diff --git a/libs/horizon/src/event/HorizonEventMain.ts b/libs/horizon/src/event/HorizonEventMain.ts index e8913a18..9a9e2719 100644 --- a/libs/horizon/src/event/HorizonEventMain.ts +++ b/libs/horizon/src/event/HorizonEventMain.ts @@ -12,8 +12,7 @@ import { getListeners as getCompositionListeners } from './simulatedEvtHandler/C import { getListeners as getChangeListeners } from './simulatedEvtHandler/ChangeEventHandler'; import { getListeners as getSelectionListeners } from './simulatedEvtHandler/SelectionEventHandler'; import { - getCustomEventNameWithOn, - uniqueCharCode, + addOnPrefix, } from './utils'; import { createCustomEvent } from './customEvents/EventFactory'; import { getListenersFromTree } from './ListenerGetter'; @@ -30,16 +29,11 @@ function getCommonListeners( target: null | EventTarget, isCapture: boolean, ): ListenerUnitList { - const horizonEvtName = getCustomEventNameWithOn(CommonEventToHorizonMap[nativeEvtName]); + const horizonEvtName = addOnPrefix(CommonEventToHorizonMap[nativeEvtName]); if (!horizonEvtName) { return []; } - // 火狐浏览器兼容。火狐浏览器下功能键将触发keypress事件 火狐下keypress的charCode有值,keyCode为0 - if (nativeEvtName === 'keypress' && uniqueCharCode(nativeEvent) === 0) { - return []; - } - // 鼠标点击右键 if (nativeEvent instanceof MouseEvent && nativeEvtName === 'click' && nativeEvent.button === 2) { return []; diff --git a/libs/horizon/src/event/customEvents/CustomKeyboardEvent.ts b/libs/horizon/src/event/customEvents/CustomKeyboardEvent.ts index 33c6d13c..1ca6ab58 100644 --- a/libs/horizon/src/event/customEvents/CustomKeyboardEvent.ts +++ b/libs/horizon/src/event/customEvents/CustomKeyboardEvent.ts @@ -3,7 +3,6 @@ */ import type {VNode} from '../../renderer/Types'; -import {uniqueCharCode} from '../utils'; import {CustomBaseEvent} from './CustomBaseEvent'; import {CHAR_CODE_ENTER} from '../const'; @@ -44,7 +43,7 @@ function getKey(event) { } if (event.type === 'keypress') { - const charCode = uniqueCharCode(event); + const charCode = event.charCode; return charCode === CHAR_CODE_ENTER ? 'Enter' : String.fromCharCode(charCode); } @@ -71,7 +70,7 @@ export class CustomKeyboardEvent extends CustomBaseEvent { ) { super(customEvtName, nativeEvtName, nativeEvt, vNode, target); this.key = getKey(nativeEvt); - this.charCode = nativeEvtName === 'keypress' ? uniqueCharCode(nativeEvt) : 0; + this.charCode = nativeEvtName === 'keypress' ? nativeEvt.charCode : 0; this.keyCode = (nativeEvtName === 'keydown' || nativeEvtName === 'keyup') ? nativeEvt.keyCode : 0; this.which = this.charCode || this.keyCode; } diff --git a/libs/horizon/src/event/utils.ts b/libs/horizon/src/event/utils.ts index 12a6735e..51f022f1 100644 --- a/libs/horizon/src/event/utils.ts +++ b/libs/horizon/src/event/utils.ts @@ -1,25 +1,3 @@ -import { CHAR_CODE_ENTER, CHAR_CODE_SPACE } from './const'; - -export function uniqueCharCode(nativeEvent): number { - let charCode = nativeEvent.charCode; - - // 火狐浏览器没有设置enter键的charCode,用keyCode - if (charCode === 0 && nativeEvent.keyCode === CHAR_CODE_ENTER) { - charCode = CHAR_CODE_ENTER; - } - - // 当ctrl按下时10表示enter键按下 - if (charCode === 10) { - charCode = CHAR_CODE_ENTER; - } - - // 忽略非打印的Enter键 - if (charCode >= CHAR_CODE_SPACE || charCode === CHAR_CODE_ENTER) { - return charCode; - } - - return 0; -} // 支持的输入框类型 const supportedInputTypes = ['color', 'date', 'datetime', 'datetime-local', 'email', 'month', @@ -36,7 +14,7 @@ export function isTextInputElement(dom?: HTMLElement): boolean { // 例:dragEnd -> onDragEnd -export function getCustomEventNameWithOn(name) { +export function addOnPrefix(name) { if (!name) { return ''; }