From 5404e93d11a5201cda9dbe39e5f11d91bf207c0c Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Fri, 26 Apr 2024 16:40:15 +0200 Subject: [PATCH] Fix selection getting lost on Android on the new arch (#335) --- android/src/main/new_arch/MarkdownCommitHook.cpp | 9 +++++++++ android/src/main/new_arch/MarkdownCommitHook.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/android/src/main/new_arch/MarkdownCommitHook.cpp b/android/src/main/new_arch/MarkdownCommitHook.cpp index 9375bb48..bbaef301 100644 --- a/android/src/main/new_arch/MarkdownCommitHook.cpp +++ b/android/src/main/new_arch/MarkdownCommitHook.cpp @@ -112,6 +112,15 @@ RootShadowNode::Unshared MarkdownCommitHook::shadowTreeWillCommit( // force measurement of a map buffer newStateData->cachedAttributedStringId = 0; + // setting -1 as the event counter makes sure that the update will be ignored by the java + // part of the code, which is what we want as we don't change the attributed string here + if (previousEventCount_.contains(nodes.textInput->getTag()) && + previousEventCount_[nodes.textInput->getTag()] == stateData.mostRecentEventCount) { + newStateData->mostRecentEventCount = -1; + } else { + previousEventCount_[nodes.textInput->getTag()] = stateData.mostRecentEventCount; + } + // clone the text input with the new state auto newNode = node.clone({ .state = diff --git a/android/src/main/new_arch/MarkdownCommitHook.h b/android/src/main/new_arch/MarkdownCommitHook.h index 6e736d7c..f14e789c 100644 --- a/android/src/main/new_arch/MarkdownCommitHook.h +++ b/android/src/main/new_arch/MarkdownCommitHook.h @@ -47,6 +47,8 @@ class MarkdownCommitHook : public UIManagerCommitHook { textLayoutManagers_; std::unordered_map previousDecoratorProps_; + std::unordered_map + previousEventCount_; }; } // namespace livemarkdown