MCPcopy
hub / github.com/wavetermdev/waveterm / parseKeyDescription

Function parseKeyDescription

frontend/util/keyutil.ts:74–128  ·  view source on GitHub ↗
(keyDescription: string)

Source from the content-addressed store, hash-verified

72}
73
74function parseKeyDescription(keyDescription: string): KeyPressDecl {
75 let rtn = { key: "", mods: {} } as KeyPressDecl;
76 let keys = keyDescription.replace(/[()]/g, "").split(":");
77 for (let key of keys) {
78 if (key == "Cmd") {
79 if (PLATFORM == PlatformMacOS) {
80 rtn.mods.Meta = true;
81 } else {
82 rtn.mods.Alt = true;
83 }
84 rtn.mods.Cmd = true;
85 } else if (key == "Shift") {
86 rtn.mods.Shift = true;
87 } else if (key == "Ctrl") {
88 rtn.mods.Ctrl = true;
89 } else if (key == "Option") {
90 if (PLATFORM == PlatformMacOS) {
91 rtn.mods.Alt = true;
92 } else {
93 rtn.mods.Meta = true;
94 }
95 rtn.mods.Option = true;
96 } else if (key == "Alt") {
97 if (PLATFORM == PlatformMacOS) {
98 rtn.mods.Option = true;
99 } else {
100 rtn.mods.Cmd = true;
101 }
102 rtn.mods.Alt = true;
103 } else if (key == "Meta") {
104 if (PLATFORM == PlatformMacOS) {
105 rtn.mods.Cmd = true;
106 } else {
107 rtn.mods.Option = true;
108 }
109 rtn.mods.Meta = true;
110 } else {
111 let { key: parsedKey, type: keyType } = parseKey(key);
112 rtn.key = parsedKey;
113 rtn.keyType = keyType;
114 if (rtn.keyType == KeyTypeKey && key.length == 1) {
115 // check for if key is upper case
116 // TODO what about unicode upper case?
117 if (/[A-Z]/.test(key.charAt(0))) {
118 // this key is an upper case A - Z - we should apply the shift key, even if it wasn't specified
119 rtn.mods.Shift = true;
120 } else if (key == " ") {
121 rtn.key = "Space";
122 // we allow " " and "Space" to be mapped to Space key
123 }
124 }
125 }
126 }
127 return rtn;
128}
129
130function notMod(keyPressMod: boolean, eventMod: boolean) {
131 return (keyPressMod && !eventMod) || (eventMod && !keyPressMod);

Callers 1

checkKeyPressedFunction · 0.70

Calls 1

parseKeyFunction · 0.70

Tested by

no test coverage detected