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 cb723bf148428e21cd9775ce42960d15a74eb19f..829af1280ac18b9232f743879da063388a187230 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 368ae775e45ec9598579086ae76fbfca1d6f1374..ddda4c0412383b4de1fdbc2cab1ec38038bd1a54 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);