From ddcdf7bfcc9b03562c38f2cc0af8c2c0789e93df Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Thu, 10 Oct 2024 19:09:22 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?=E9=A2=84=E4=B8=8A=E5=B1=8F=E5=80=99=E9=80=89=E6=A0=8F=E6=95=88?= =?UTF-8?q?=E6=9E=9C=20=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../ets/plugin/editing/TextInputPlugin.ets | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) 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 6a6b814e38..54703f364a 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 @@ -78,7 +78,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { mEditable: ListenableEditingState; private mRestartInputPending: boolean = false; private plugin: EditingStateWatcher | Any; - private imcFlag: boolean = false; private inputTypeNone: string = 'NONE' private keyboardStatus: inputMethod.KeyboardStatus = inputMethod.KeyboardStatus.HIDE; private inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 } @@ -144,22 +143,11 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { return; } await this.attach(true); - if (!this.imcFlag) { - this.listenKeyBoardEvent(); - } - this.inputMethodController.showTextInput().then(() => { - Log.d(TextInputMethodHandlerImpl.TAG, "Succeeded in showing softKeyboard"); - }).catch((err: Any) => { - Log.e(TextInputMethodHandlerImpl.TAG, "Failed to show softKeyboard:" + JSON.stringify(err)); - }); + this.listenKeyBoardEvent(); } private async hideTextInput(): Promise { - this.inputMethodController.hideTextInput().then(() => { - Log.d(TextInputMethodHandlerImpl.TAG, "Succeeded in hide softKeyboard"); - }).catch((err: Any) => { - Log.e(TextInputMethodHandlerImpl.TAG, "Failed to hide softKeyboard:" + JSON.stringify(err)); - }) + this.inputMethodController.detach(); } async attach(showKeyboard: boolean): Promise { @@ -264,7 +252,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { return; } Log.d(TextInputMethodHandlerImpl.TAG, "listenKeyBoardEvent success"); - this.imcFlag = true; } private insertTextCallback = (text: string) => { @@ -287,6 +274,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { /// 临时规避缺少newline对应枚举类型问题 if (functionKey.enterKeyType == NEWLINE_KEY_TYPE) { this.mEditable.handleNewlineEvent(); + this.changeSelection(); } this.mEditable.handleFunctionKey(functionKey); } @@ -319,8 +307,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.inputMethodController.off('sendFunctionKey', this.sendFunctionKeyCallback); this.inputMethodController.off('sendKeyboardStatus', this.sendKeyboardStatusCallback); this.inputMethodController.off('selectByRange', this.selectByRangeCallback); - this.imcFlag = false; - this.inputMethodController.detach() } public clearTextInputClient(): void { -- Gitee From 4a49671c404afbbf5fbf8c02859a9218c29ef644 Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Thu, 10 Oct 2024 19:23:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E5=90=8E=E8=8B=B1=E6=96=87=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E5=80=99=E9=80=89=E6=A1=86=E9=A2=84=E8=A7=88=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> --- .../flutter/src/main/ets/plugin/editing/TextInputPlugin.ets | 1 + 1 file changed, 1 insertion(+) 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 54703f364a..126f4dce84 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 @@ -132,6 +132,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { + editingState.selectionEnd + " composingStart:" + editingState.composingStart + " composingEnd" + editingState.composingEnd); this.mEditable.updateTextInputState(editingState); + this.changeSelection(); } clearClient(): void { -- Gitee From 40349bd3ca02dfa28de2324e0c38fa675461a224 Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Fri, 11 Oct 2024 10:41:23 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8A=E5=B1=8F=E6=8F=92=E5=85=A5=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E9=81=BF=E5=85=8D=E6=95=88=E6=9E=9C=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../plugin/editing/ListenableEditingState.ets | 41 +++++++++++++++++++ .../ets/plugin/editing/TextInputPlugin.ets | 7 +++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets index 837253925b..21d2e3f103 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets @@ -171,6 +171,47 @@ export class ListenableEditingState { this.notifyListenersIfNeeded(true, true, false); } + handleInsertEnglishTextEvent(text: string): void { + let start = this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + let end = this.mSelectionStartCache > this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + const length = text.length; + this.replace(start, end, text, 0, length); + let englishReg = new RegExp("[A-Za-z^']"); + + if (start == 0 || !this.mStringCache.substring(start - 1, start).match(englishReg)) { + let tempStr: string = this.mStringCache.substring(0, start) + text + this.mStringCache.substring(end); + this.mStringCache = tempStr; + this.setSelectionStart(this.mStringCache.length); + this.setSelectionEnd(this.mStringCache.length); + } else { + for (let i = start; i <= start; i--) { + if (this.mStringCache.substring(i - 1, i).match(englishReg)) { + start = i; + } else { + break; + } + } + for (let i = end; i >= start; i++) { + if (this.mStringCache.substring(i, i + 1).match(englishReg)) { + end = i; + } else { + break; + } + } + let tempStr: string = this.mStringCache.substring(0, start - 1) + text + this.mStringCache.substring(end + 1); + let selectionLength: number = start - 1 + text.length; + this.mStringCache = tempStr; + this.setSelectionStart(selectionLength); + this.setSelectionEnd(selectionLength); + } + + if (this.mListeners == null) { + Log.e(TAG, "mListeners is null"); + return; + } + this.notifyListenersIfNeeded(true, true, false); + } + updateTextInputState(state: TextEditState): void { this.beginBatchEdit(); this.setStringCache(state.text); 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 126f4dce84..d859c72a05 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 @@ -257,7 +257,12 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { private insertTextCallback = (text: string) => { Log.d(TextInputMethodHandlerImpl.TAG, "insertText: " + text); - this.mEditable.handleInsertTextEvent(text); + if (text.length > 1 && text.substring(text.length - 1, text.length == " ") { + this.mEditable.handleInsertEnglishTextEvent(text); + } else { + this.mEditable.handleInsertTextEvent(text); + } + this.changeSelection(); } -- Gitee