From 1729f61e7cf476bd5871583fc4461f072e6a83bd Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Thu, 5 Sep 2024 15:36:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=94=AE=E5=8F=91=E9=80=81keyEvent=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 罗键铭 <541416002@qq.com> --- .../ets/plugin/editing/TextInputPlugin.ets | 37 ++++++++++--------- 1 file changed, 20 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 01a79f36f1..c41f1da13e 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 @@ -26,6 +26,7 @@ import Any from '../common/Any'; import { window } from '@kit.ArkUI'; import FlutterManager from '../../embedding/ohos/FlutterManager'; import { IntentionCode } from '@ohos.multimodalInput.intentionCode'; +import {KeyCode} from '@kit.InputKit'; /// 临时规避缺少newline对应枚举问题 const NEWLINE_KEY_TYPE: number = 8; @@ -285,22 +286,10 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { /// 暂时规避方案 /// OS机制与Android不一致,需要去监听软键盘事件才能发送KeyEvent事件 /// keyCode是从dart侧获取的,因为是使用删除按钮,此处暂时这样写死;其他地方如果需要键盘发送事件,再去找对应的keyCode - if (length == 1) { - let event: KeyEvent = { - type: KeyType.Down, - /// dart侧keyboard_maps.g.dart中LogicalKeyboardKey.backspace设置为这个参 - keyCode: 2055, - keyText: '', - keySource: KeySource.Keyboard, - deviceId: 0, - metaKey: 0, - timestamp: 0, - stopPropagation: (): void => { - throw new Error('Function not implemented.'); - }, - intentionCode: IntentionCode.INTENTION_BACK - } - this.sendKeyboardEvent(event) + if (this.mEditable.getStringCache() == "") { + /// dart侧keyboard_maps.g.dart中LogicalKeyboardKey.backspace设置为这个参 + this.sendKeyboardEvent(KeyType.Down, KeyCode.KEYCODE_DEL) + this.sendKeyboardEvent(KeyType.Up, KeyCode.KEYCODE_DEL) } this.mEditable.handleDeleteEvent(false, length); }) @@ -366,7 +355,21 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.imcFlag = true; } - sendKeyboardEvent(event: KeyEvent): void { + sendKeyboardEvent(type: KeyType, keyCode: number): void { + let event: KeyEvent = { + type: type, + /// dart侧keyboard_maps.g.dart中LogicalKeyboardKey.backspace设置为这个参 + keyCode: keyCode, + keyText: '', + keySource: KeySource.Keyboard, + deviceId: 0, + metaKey: 0, + timestamp: 0, + stopPropagation: (): void => { + throw new Error('Function not implemented.'); + }, + intentionCode: IntentionCode.INTENTION_BACK + } FlutterManager.getInstance().getFlutterViewList().forEach((value) => { value.onKeyEvent(event) }) -- Gitee From 0eb7a59e3e338311cbc3d0400bfc96538f3afbc0 Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Thu, 5 Sep 2024 15:39:21 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 罗键铭 <541416002@qq.com> --- .../flutter/src/main/ets/plugin/editing/TextInputPlugin.ets | 3 --- 1 file changed, 3 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 c41f1da13e..8bf6fcbbbf 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 @@ -285,9 +285,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.inputMethodController.on('deleteLeft', (length) => { /// 暂时规避方案 /// OS机制与Android不一致,需要去监听软键盘事件才能发送KeyEvent事件 - /// keyCode是从dart侧获取的,因为是使用删除按钮,此处暂时这样写死;其他地方如果需要键盘发送事件,再去找对应的keyCode if (this.mEditable.getStringCache() == "") { - /// dart侧keyboard_maps.g.dart中LogicalKeyboardKey.backspace设置为这个参 this.sendKeyboardEvent(KeyType.Down, KeyCode.KEYCODE_DEL) this.sendKeyboardEvent(KeyType.Up, KeyCode.KEYCODE_DEL) } @@ -358,7 +356,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { sendKeyboardEvent(type: KeyType, keyCode: number): void { let event: KeyEvent = { type: type, - /// dart侧keyboard_maps.g.dart中LogicalKeyboardKey.backspace设置为这个参 keyCode: keyCode, keyText: '', keySource: KeySource.Keyboard, -- Gitee