diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/KeyEventHandler.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/KeyEventHandler.ets index 5fd76b3d62429eebe9345305e7b59f95f8abb0ec..58133fd461d8669580f47c2358ae33739957c70d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/KeyEventHandler.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/KeyEventHandler.ets @@ -21,20 +21,11 @@ import { KeyCode } from "@kit.InputKit"; const TAG = "KeyEventHandler"; -// 组合键 -const COMBINATION_KEYS = [ - KeyCode.KEYCODE_CTRL_LEFT, KeyCode.KEYCODE_CTRL_RIGHT, - KeyCode.KEYCODE_ALT_LEFT, KeyCode.KEYCODE_ALT_RIGHT -]; - export class KeyEventHandler { private textInputPlugin?: TextInputPlugin; private charMap : HashMap = new HashMap(); private shiftMap : HashMap = new HashMap(); private isShiftMode: boolean = false; - private isCombinationKey: boolean = false; - // 记录输入的keyCode,确保有down和up事件才输入字符 - private inputMap: HashMap = new HashMap(); constructor(textInputPlugin?: TextInputPlugin) { this.textInputPlugin = textInputPlugin; @@ -156,30 +147,18 @@ export class KeyEventHandler { handleKeyEvent(event: KeyEvent) { Log.i(TAG, JSON.stringify({ "name": "handleKeyEvent", - "event": event, + "event": event })); - let text = this.getCharByEvent(event); - if (event.type == KeyType.Down) { - if (!this.isCombinationKey) { - this.isCombinationKey = COMBINATION_KEYS.findIndex((it) => it == event.keyCode) >= 0; - } - this.inputMap.set(event.keyCode, text); - } else if (event.type == KeyType.Up) { - if (COMBINATION_KEYS.findIndex((it) => it == event.keyCode) >= 0) { - // Ctrl/Alt 键抬起,重置状态 - this.isCombinationKey = false; - return; - } else if (this.isCombinationKey) { - // Ctrl/Alt 键按下的状态,不输入字符(字母/数字/符号) - return; - } + if (event.type == KeyType.Up) { // 处理字符按键相关逻辑 - if (this.inputMap.hasKey(event.keyCode) && this.charMap.hasKey(event.keyCode)) { - this.inputMap.remove(event.keyCode) - this.textInputPlugin?.getEditingState().handleInsertTextEvent(text) + if (this.charMap.hasKey(event.keyCode)) { + this.textInputPlugin?.getEditingState().handleInsertTextEvent(this.getCharByEvent(event)) + } + // 处理非字符按键 + if (event.keyCode == KeyCode.KEYCODE_DEL) { + this.textInputPlugin?.getEditingState().handleDeleteEvent(false, 0) } } this.isShiftMode = event.keyCode == KeyCode.KEYCODE_SHIFT_LEFT - || event.keyCode == KeyCode.KEYCODE_SHIFT_RIGHT } } 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 42f1cec3c5bab24dc157117d50b849caf42138ef..351277019b2ba94b0b7cd759d33574c48b0b3198 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 @@ -253,12 +253,7 @@ export class ListenableEditingState { } handleDeleteEvent(leftOrRight: boolean, length: number): void { - if (length === 0) { - return; - } - - let start = - this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + let start = this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; let end = this.mSelectionStartCache > this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; if (leftOrRight == false) { @@ -266,15 +261,9 @@ export class ListenableEditingState { 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; - } - } + unicodeStart = FlutterTextUtils.getOffsetBefore(this.mStringCache, start); } this.replace(unicodeStart, end, "", 0, 0); this.mSelectionStartCache = unicodeStart; @@ -288,12 +277,7 @@ export class ListenableEditingState { } 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; - } - } + unicodeEnd = FlutterTextUtils.getOffsetAfter(this.mStringCache, start); } this.replace(start, unicodeEnd, "", 0, 0); this.mSelectionEndCache = start; 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 0b7fd575a4c3bd683662649d44289fdbb340a6b1..50be54c4b0ad32053498917760e5b350a72c2bf7 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 @@ -307,14 +307,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } private deleteLeftCallback = (length: number) => { - /// 暂时规避方案 - /// OS机制与Android不一致,需要去监听软键盘事件才能发送KeyEvent事件 - if (this.mEditable.getStringCache() == "") { - for (let i = 0; i < length; i++) { - this.sendKeyboardEvent(KeyType.Down, KeyCode.KEYCODE_DEL) - this.sendKeyboardEvent(KeyType.Up, KeyCode.KEYCODE_DEL) - } - } this.mEditable.handleDeleteEvent(false, length); } diff --git a/shell/platform/ohos/ohos_touch_processor.cpp b/shell/platform/ohos/ohos_touch_processor.cpp index 17b715b32823346890122a73f119a4593a207b00..32d2ed1ef8d0f420c4c0af25ca01194e299d1923 100644 --- a/shell/platform/ohos/ohos_touch_processor.cpp +++ b/shell/platform/ohos/ohos_touch_processor.cpp @@ -179,9 +179,11 @@ void OhosTouchProcessor::HandleTouchEvent( OH_NativeXComponent_TouchPointToolType toolType; OH_NativeXComponent_GetTouchPointToolType(component, 0, &toolType); pointerData.kind = getPointerDeviceTypeForToolType(toolType); - if (pointerData.change == PointerData::Change::kDown || - pointerData.change == PointerData::Change::kMove) { - pointerData.buttons = kPointerButtonTouchContact; + if (pointerData.kind == PointerData::DeviceKind::kTouch) { + if (pointerData.change == PointerData::Change::kDown || + pointerData.change == PointerData::Change::kMove) { + pointerData.buttons = kPointerButtonTouchContact; + } } pointerData.pan_x = 0.0; pointerData.pan_y = 0.0; @@ -259,7 +261,7 @@ void OhosTouchProcessor::HandleMouseEvent( pointerData.pressure = 0.0; pointerData.pressure_max = 1.0; pointerData.pressure_min = 0.0; - pointerData.kind = PointerData::DeviceKind::kMouse; // kMouse支持鼠标框选文字 + pointerData.kind = PointerData::DeviceKind::kTouch; pointerData.buttons = getPointerButtonFromMouse(mouseEvent.button); // hover support if (mouseEvent.button == OH_NATIVEXCOMPONENT_NONE_BUTTON && pointerData.change == PointerData::Change::kMove) { diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 6067b74b5d5d224e0b7a80ea4b0797325e1c2f7e..0d1f9360237e1adff77bf0880e2abe7519af5bca 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -528,8 +528,7 @@ void XComponentBase::OnDispatchMouseWheelEvent(mouseWheelEvent event) } if (event.eventType == "actionUpdate") { OH_NativeXComponent_MouseEvent mouseEvent; - // 调整鼠标滚轮滚动时,列表滑动的方向。和Windows保持一致。 - double scrollY = g_scrollDistance - event.offsetY; + double scrollY = event.offsetY - g_scrollDistance; g_scrollDistance = event.offsetY; // fix resize ratio mouseEvent.x = event.globalX / g_resizeRate;