Match-id-97c5022a44570f5599dd0a72dadfd05f95e09617
This commit is contained in:
commit
7b603282aa
|
@ -12,8 +12,7 @@ import { getListeners as getCompositionListeners } from './simulatedEvtHandler/C
|
||||||
import { getListeners as getChangeListeners } from './simulatedEvtHandler/ChangeEventHandler';
|
import { getListeners as getChangeListeners } from './simulatedEvtHandler/ChangeEventHandler';
|
||||||
import { getListeners as getSelectionListeners } from './simulatedEvtHandler/SelectionEventHandler';
|
import { getListeners as getSelectionListeners } from './simulatedEvtHandler/SelectionEventHandler';
|
||||||
import {
|
import {
|
||||||
getCustomEventNameWithOn,
|
addOnPrefix,
|
||||||
uniqueCharCode,
|
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { createCustomEvent } from './customEvents/EventFactory';
|
import { createCustomEvent } from './customEvents/EventFactory';
|
||||||
import { getListenersFromTree } from './ListenerGetter';
|
import { getListenersFromTree } from './ListenerGetter';
|
||||||
|
@ -30,16 +29,11 @@ function getCommonListeners(
|
||||||
target: null | EventTarget,
|
target: null | EventTarget,
|
||||||
isCapture: boolean,
|
isCapture: boolean,
|
||||||
): ListenerUnitList {
|
): ListenerUnitList {
|
||||||
const horizonEvtName = getCustomEventNameWithOn(CommonEventToHorizonMap[nativeEvtName]);
|
const horizonEvtName = addOnPrefix(CommonEventToHorizonMap[nativeEvtName]);
|
||||||
if (!horizonEvtName) {
|
if (!horizonEvtName) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 火狐浏览器兼容。火狐浏览器下功能键将触发keypress事件 火狐下keypress的charCode有值,keyCode为0
|
|
||||||
if (nativeEvtName === 'keypress' && uniqueCharCode(nativeEvent) === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 鼠标点击右键
|
// 鼠标点击右键
|
||||||
if (nativeEvent instanceof MouseEvent && nativeEvtName === 'click' && nativeEvent.button === 2) {
|
if (nativeEvent instanceof MouseEvent && nativeEvtName === 'click' && nativeEvent.button === 2) {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {VNode} from '../../renderer/Types';
|
import type {VNode} from '../../renderer/Types';
|
||||||
import {uniqueCharCode} from '../utils';
|
|
||||||
import {CustomBaseEvent} from './CustomBaseEvent';
|
import {CustomBaseEvent} from './CustomBaseEvent';
|
||||||
import {CHAR_CODE_ENTER} from '../const';
|
import {CHAR_CODE_ENTER} from '../const';
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ function getKey(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type === 'keypress') {
|
if (event.type === 'keypress') {
|
||||||
const charCode = uniqueCharCode(event);
|
const charCode = event.charCode;
|
||||||
return charCode === CHAR_CODE_ENTER ? 'Enter' : String.fromCharCode(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);
|
super(customEvtName, nativeEvtName, nativeEvt, vNode, target);
|
||||||
this.key = getKey(nativeEvt);
|
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.keyCode = (nativeEvtName === 'keydown' || nativeEvtName === 'keyup') ? nativeEvt.keyCode : 0;
|
||||||
this.which = this.charCode || this.keyCode;
|
this.which = this.charCode || this.keyCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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',
|
const supportedInputTypes = ['color', 'date', 'datetime', 'datetime-local', 'email', 'month',
|
||||||
|
@ -36,7 +14,7 @@ export function isTextInputElement(dom?: HTMLElement): boolean {
|
||||||
|
|
||||||
|
|
||||||
// 例:dragEnd -> onDragEnd
|
// 例:dragEnd -> onDragEnd
|
||||||
export function getCustomEventNameWithOn(name) {
|
export function addOnPrefix(name) {
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue