From ff03e9210aaa7a024d91db05ced7cc503b08494a Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Tue, 8 Oct 2024 14:58:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E8=BE=93=E5=85=A5=E6=B3=95?= =?UTF-8?q?=E9=A2=84=E4=B8=8A=E5=B1=8F=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../src/main/ets/plugin/editing/TextInputPlugin.ets | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index 36c52b7faa..6a6b814e38 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -270,14 +270,17 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { private insertTextCallback = (text: string) => { Log.d(TextInputMethodHandlerImpl.TAG, "insertText: " + text); this.mEditable.handleInsertTextEvent(text); + this.changeSelection(); } private deleteLeftCallback = (length: number) => { this.mEditable.handleDeleteEvent(false, length); + this.changeSelection(); } private deleteRightCallback = (length: number) => { this.mEditable.handleDeleteEvent(true, length); + this.changeSelection(); } private sendFunctionKeyCallback = (functionKey: inputMethod.FunctionKey) => { @@ -301,6 +304,14 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.mEditable.handleSelectByRange(range); } + changeSelection(): void { + try { + this.inputMethodController.changeSelection(this.mEditable.getStringCache(), this.mEditable.getSelectionStart(), this.mEditable.getSelectionEnd()); + } catch (err) { + Log.e(TextInputMethodHandlerImpl.TAG, "Failed to changeSelection:" + JSON.stringify(err)); + } + } + cancelListenKeyBoardEvent(): void { this.inputMethodController.off('insertText', this.insertTextCallback); this.inputMethodController.off('deleteLeft', this.deleteLeftCallback); -- Gitee