mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
detect single keypresses
This commit is contained in:
parent
56a930c1dc
commit
bfab5e4223
@ -1,6 +1,8 @@
|
||||
// Copyright 2024, Command Line Inc.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import * as util from "./util";
|
||||
|
||||
const KeyTypeCodeRegex = /c{(.*)}/;
|
||||
const KeyTypeKey = "key";
|
||||
const KeyTypeCode = "code";
|
||||
@ -76,6 +78,13 @@ function notMod(keyPressMod: boolean, eventMod: boolean) {
|
||||
return (keyPressMod && !eventMod) || (eventMod && !keyPressMod);
|
||||
}
|
||||
|
||||
function isCharacterKeyEvent(event: WaveKeyboardEvent): boolean {
|
||||
if (event.alt || event.meta || event.control) {
|
||||
return false;
|
||||
}
|
||||
return util.countGraphemes(event.key) == 1;
|
||||
}
|
||||
|
||||
function checkKeyPressed(event: WaveKeyboardEvent, keyDescription: string): boolean {
|
||||
let keyPress = parseKeyDescription(keyDescription);
|
||||
if (!keyPress.mods.Alt && notMod(keyPress.mods.Option, event.option)) {
|
||||
@ -155,6 +164,7 @@ export {
|
||||
adaptFromElectronKeyEvent,
|
||||
adaptFromReactOrNativeKeyEvent,
|
||||
checkKeyPressed,
|
||||
isCharacterKeyEvent,
|
||||
keydownWrapper,
|
||||
parseKeyDescription,
|
||||
setKeyUtilPlatform,
|
||||
|
Loading…
Reference in New Issue
Block a user