From a6c7e25407ffc0d26fb4bc21ff34af26e5ded5d6 Mon Sep 17 00:00:00 2001 From: xuchang Date: Fri, 14 Feb 2025 11:14:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4TextInputPlugin.ets?= =?UTF-8?q?=E4=B8=AD=E5=A4=9A=E4=BD=99=E7=9A=84delete=E7=9B=91=E5=90=AC?= =?UTF-8?q?=EF=BC=9B=E8=BF=99=E9=83=A8=E5=88=86=E5=88=A0=E9=99=A4=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BC=9A=E5=9C=A8FlutterView.ets=E7=9A=84onK?= =?UTF-8?q?eyPreIme=E5=81=9A=E5=88=A0=E9=99=A4=E5=AD=97=E7=AC=A6=E7=9A=84?= =?UTF-8?q?=E4=BC=A0=E9=80=92=EF=BC=8C=E5=9C=A8TextInputChannel.ets?= =?UTF-8?q?=E7=9A=84'TextInput.setEditingState'=E5=9B=9E=E8=B0=83=E4=B8=AD?= =?UTF-8?q?=E5=81=9A=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=9B=B4=E6=96=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuchang --- .../editing/ListenableEditingState.test.ets | 7 --- .../plugin/editing/ListenableEditingState.ets | 52 ------------------- .../ets/plugin/editing/TextInputPlugin.ets | 26 ---------- 3 files changed, 85 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/application/src/ohosTest/ets/test/plugin/editing/ListenableEditingState.test.ets b/shell/platform/ohos/flutter_embedding/application/src/ohosTest/ets/test/plugin/editing/ListenableEditingState.test.ets index 1a0c51c5b0..fa1d6a1641 100644 --- a/shell/platform/ohos/flutter_embedding/application/src/ohosTest/ets/test/plugin/editing/ListenableEditingState.test.ets +++ b/shell/platform/ohos/flutter_embedding/application/src/ohosTest/ets/test/plugin/editing/ListenableEditingState.test.ets @@ -18,13 +18,6 @@ export default function ListenableEditingStateTest() { expect(editingState.getSelectionStart()).assertEqual(5); expect(editingState.getSelectionEnd()).assertEqual(5); }) - - it('should handle delete event correctly (right)', 0, () => { - editingState.handleDeleteEvent(true, 1); - expect(editingState.getStringCache()).assertEqual('hello'); - expect(editingState.getSelectionStart()).assertEqual(5); - expect(editingState.getSelectionEnd()).assertEqual(5); - }) it('should handle newline event correctly', 0, () => { editingState.handleNewlineEvent(); expect(editingState.getStringCache()).assertEqual('hello\n'); 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 1d4e82adce..690fdff3a4 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 @@ -247,58 +247,6 @@ export class ListenableEditingState { } } - handleDeleteEvent(leftOrRight: boolean, length: number): void { - if (length === 0) { - return; - } - - let start = - this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; - let end = this.mSelectionStartCache > this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; - - if (leftOrRight == false) { - //delete left - if (start == 0 && end == 0) { - return; - } - - let unicodeStart = start; - if (start == end) { - for (let i = 0; i < length; i++) { - unicodeStart = FlutterTextUtils.getOffsetBefore(this.mStringCache, unicodeStart); - if (unicodeStart === 0) { - break; - } - } - } - this.replace(unicodeStart, end, "", 0, 0); - this.mSelectionStartCache = unicodeStart; - let tempStr: string = this.mStringCache.slice(0, unicodeStart) + this.mStringCache.slice(end); - this.mStringCache = tempStr; - this.mSelectionEndCache = this.mSelectionStartCache; - } else if (leftOrRight == true) { - //delete right - if (start == this.mStringCache.length) { - return; - } - let unicodeEnd = end; - if (start == end) { - for (let i = 0; i < length; i++) { - unicodeEnd = FlutterTextUtils.getOffsetAfter(this.mStringCache, unicodeEnd); - if (unicodeEnd === this.mStringCache.length) { - break; - } - } - } - this.replace(start, unicodeEnd, "", 0, 0); - this.mSelectionEndCache = start; - let tempStr: string = this.mStringCache.slice(0, start) + (unicodeEnd >= this.mStringCache.length ? "" : this.mStringCache.slice(unicodeEnd)); - this.mStringCache = tempStr; - this.mSelectionStartCache = this.mSelectionEndCache; - } - this.notifyListenersIfNeeded(true, true, false); - } - handleNewlineEvent(): void { // 获取光标所在位置; // 当光标移动前位置小于移动后的位置时,获取光标移动前位置;反之获取移动后位置 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 8692e4ee2a..4509d270ba 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 @@ -253,22 +253,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { return; } - try { - this.inputMethodController.on('deleteLeft', this.deleteLeftCallback) - } catch (err) { - Log.e(TextInputMethodHandlerImpl.TAG, "Failed to subscribe deleteLeft:" + JSON.stringify(err)); - this.cancelListenKeyBoardEvent(); - return; - } - - try { - this.inputMethodController.on('deleteRight', this.deleteRightCallback) - } catch (err) { - Log.e(TextInputMethodHandlerImpl.TAG, "Failed to subscribe deleteRight:" + JSON.stringify(err)); - this.cancelListenKeyBoardEvent(); - return; - } - try { this.inputMethodController.on('sendFunctionKey', this.sendFunctionKeyCallback) } catch (err) { @@ -301,14 +285,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.mEditable.handleInsertTextEvent(text); } - private deleteLeftCallback = (length: number) => { - this.mEditable.handleDeleteEvent(false, length); - } - - private deleteRightCallback = (length: number) => { - this.mEditable.handleDeleteEvent(true, length); - } - private sendFunctionKeyCallback = (functionKey: inputMethod.FunctionKey) => { /// 临时规避缺少newline对应枚举类型问题 if (functionKey.enterKeyType == NEWLINE_KEY_TYPE) { @@ -327,8 +303,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { cancelListenKeyBoardEvent(): void { this.inputMethodController?.off('insertText', this.insertTextCallback); - this.inputMethodController?.off('deleteLeft', this.deleteLeftCallback); - this.inputMethodController?.off('deleteRight', this.deleteRightCallback); this.inputMethodController?.off('sendFunctionKey', this.sendFunctionKeyCallback); this.inputMethodController?.off('sendKeyboardStatus', this.sendKeyboardStatusCallback); this.inputMethodController?.off('selectByRange', this.selectByRangeCallback); -- Gitee