From d467f82995a580dcd8dfec15415f9fff17c6cbb1 Mon Sep 17 00:00:00 2001 From: Jack Nam <30609178+thienlnam@users.noreply.github.com> Date: Thu, 4 Apr 2024 10:09:13 -0700 Subject: [PATCH] Merge pull request #39621 from software-mansion-labs/@BartoszGrajdek/cursor-position-when-typing-fast [Fix] One character jumps "after" cursor when typing fast (cherry picked from commit 90ac4ef1a7cf638d1328f2bf178f1e1d40a39bc5) --- ios/Podfile.lock | 4 ++-- package-lock.json | 8 ++++---- package.json | 2 +- src/components/Composer/index.tsx | 5 ++++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 333842e5b36a..f38e181a1310 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1363,7 +1363,7 @@ PODS: - RNGoogleSignin (10.0.1): - GoogleSignIn (~> 7.0) - React-Core - - RNLiveMarkdown (0.1.36): + - RNLiveMarkdown (0.1.38): - glog - RCT-Folly (= 2022.05.16.00) - React-Core @@ -1904,7 +1904,7 @@ SPEC CHECKSUMS: RNFS: 4ac0f0ea233904cb798630b3c077808c06931688 RNGestureHandler: 25b969a1ffc806b9f9ad2e170d4a3b049c6af85e RNGoogleSignin: ccaa4a81582cf713eea562c5dd9dc1961a715fd0 - RNLiveMarkdown: e6312e556c522dd178728b28e132b16354789cb8 + RNLiveMarkdown: 0f7819903c63a786bbb80fd620baba10d43dfe18 RNLocalize: d4b8af4e442d4bcca54e68fc687a2129b4d71a81 rnmapbox-maps: fcf7f1cbdc8bd7569c267d07284e8a5c7bee06ed RNPermissions: 9b086c8f05b2e2faa587fdc31f4c5ab4509728aa diff --git a/package-lock.json b/package-lock.json index 76c51db76785..9e1a96e31b89 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "@dotlottie/react-player": "^1.6.3", - "@expensify/react-native-live-markdown": "0.1.36", + "@expensify/react-native-live-markdown": "0.1.38", "@expo/metro-runtime": "~3.1.1", "@formatjs/intl-datetimeformat": "^6.10.0", "@formatjs/intl-listformat": "^7.2.2", @@ -3097,9 +3097,9 @@ } }, "node_modules/@expensify/react-native-live-markdown": { - "version": "0.1.36", - "resolved": "https://registry.npmjs.org/@expensify/react-native-live-markdown/-/react-native-live-markdown-0.1.36.tgz", - "integrity": "sha512-dJ8V873DW7wP+OFU50XEIgR/cavfmVKXIUI4bN/oI3SbGiGVXrOVcBbg6THx0HrclupVxg/qsHxaDAXsYLV/iA==", + "version": "0.1.38", + "resolved": "https://registry.npmjs.org/@expensify/react-native-live-markdown/-/react-native-live-markdown-0.1.38.tgz", + "integrity": "sha512-0EcXvK/eqeJdesX8DBibJ+V2KX9n5Gbmg0fWTk93mGOUA70h3W6lO68nuch40X+RgQdOgIf50BMfzbBzzVdJwA==", "engines": { "node": ">= 18.0.0" }, diff --git a/package.json b/package.json index 12d354a7ae83..b603503ef004 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ }, "dependencies": { "@dotlottie/react-player": "^1.6.3", - "@expensify/react-native-live-markdown": "0.1.36", + "@expensify/react-native-live-markdown": "0.1.38", "@expo/metro-runtime": "~3.1.1", "@formatjs/intl-datetimeformat": "^6.10.0", "@formatjs/intl-listformat": "^7.2.2", diff --git a/src/components/Composer/index.tsx b/src/components/Composer/index.tsx index 82f67382c44b..5d01b05bb51f 100755 --- a/src/components/Composer/index.tsx +++ b/src/components/Composer/index.tsx @@ -126,9 +126,12 @@ function Composer( * Adds the cursor position to the selection change event. */ const addCursorPositionToSelectionChange = (event: NativeSyntheticEvent) => { + if (!isRendered) { + return; + } const webEvent = event as BaseSyntheticEvent; - if (shouldCalculateCaretPosition && isRendered) { + if (shouldCalculateCaretPosition) { // we do flushSync to make sure that the valueBeforeCaret is updated before we calculate the caret position to receive a proper position otherwise we will calculate position for the previous state flushSync(() => { setValueBeforeCaret(webEvent.target.value.slice(0, webEvent.nativeEvent.selection.start));