From 99a638114ee32f2b4a5289de108f504073ea7c4c Mon Sep 17 00:00:00 2001 From: zhoukc42 <1540623907@qq.com> Date: Mon, 17 Feb 2025 20:28:54 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9ATextInput=E7=9A=84onEndEditing?= =?UTF-8?q?=E5=92=8ConSubmitEditing=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoukc42 <1540623907@qq.com> --- .../TextInputComponentInstance.cpp | 20 ++++++------------- .../TextInputComponentInstance.h | 1 - 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/tester/harmony/react_native_openharmony/src/main/cpp/RNOHCorePackage/ComponentInstances/TextInputComponentInstance.cpp b/tester/harmony/react_native_openharmony/src/main/cpp/RNOHCorePackage/ComponentInstances/TextInputComponentInstance.cpp index cb723bf1..829af128 100644 --- a/tester/harmony/react_native_openharmony/src/main/cpp/RNOHCorePackage/ComponentInstances/TextInputComponentInstance.cpp +++ b/tester/harmony/react_native_openharmony/src/main/cpp/RNOHCorePackage/ComponentInstances/TextInputComponentInstance.cpp @@ -463,18 +463,6 @@ void TextInputComponentInstance::setTextContentAndSelection(std::string const &c m_textAreaNode.setTextSelection(selectionStart, selectionEnd); } -void TextInputComponentInstance::setTextContent(std::string const& content) { - // NOTE: if selection isn't set explicitly by JS side, we want it to stay - // roughly in the same place, rather than have it move to the end of the - // input (which is the ArkUI default behaviour) - //auto selectionFromEnd = m_content.size() - m_selectionLocation; - - int32_t selectionFromEnd = getTextSize(m_content) - m_selectionLocation; - int32_t selectionStart = getTextSize(content) - selectionFromEnd; - int32_t selectionEnd = selectionStart + m_selectionLength; - setTextContentAndSelection(content, selectionStart, selectionEnd); -} - void TextInputComponentInstance::onCommandReceived( std::string const& commandName, folly::dynamic const& args) { @@ -497,7 +485,9 @@ void TextInputComponentInstance::onCommandReceived( m_selectionStart = args[2].asInt(); m_selectionEnd = args[3].asInt(); if (m_selectionStart < 0) { - setTextContent(textContent); + m_content = textContent; + int32_t selectionPosition = getTextSize(textContent); + setTextContentAndSelection(textContent, selectionPosition, selectionPosition); } else { setTextContentAndSelection(textContent, m_selectionStart, m_selectionEnd); } @@ -512,7 +502,9 @@ void TextInputComponentInstance::onStateChanged( } auto content = getTextContentFromState(state); - setTextContent(content); + int32_t selectionStart = getTextSize(content) - getTextSize(m_content) + m_selectionLocation; + int32_t selectionEnd = selectionStart + m_selectionLength; + setTextContentAndSelection(content, selectionStart, selectionEnd); } ArkUINode& TextInputComponentInstance::getLocalRootArkUINode() { diff --git a/tester/harmony/react_native_openharmony/src/main/cpp/RNOHCorePackage/ComponentInstances/TextInputComponentInstance.h b/tester/harmony/react_native_openharmony/src/main/cpp/RNOHCorePackage/ComponentInstances/TextInputComponentInstance.h index 368ae775..ddda4c04 100644 --- a/tester/harmony/react_native_openharmony/src/main/cpp/RNOHCorePackage/ComponentInstances/TextInputComponentInstance.h +++ b/tester/harmony/react_native_openharmony/src/main/cpp/RNOHCorePackage/ComponentInstances/TextInputComponentInstance.h @@ -64,7 +64,6 @@ class TextInputComponentInstance std::string const& content, size_t selectionStart, size_t selectionEnd); - void setTextContent(std::string const& content); public: TextInputComponentInstance(Context context); -- Gitee