MCPcopy
hub / github.com/VSCodeVim/Vim / tokenizeKeySequence

Function tokenizeKeySequence

test/testSimplifier.ts:157–203  ·  view source on GitHub ↗

* Tokenize a string like `"abc d "` into `["a", "b", "c", " ", "d", " "]`

(sequence: string)

Source from the content-addressed store, hash-verified

155 * Tokenize a string like `"abc<Esc>d<C-c>"` into `["a", "b", "c", "<Esc>", "d", "<C-c>"]`
156 */
157function tokenizeKeySequence(sequence: string): string[] {
158 let isBracketedKey = false;
159 let key = '';
160 const result: string[] = [];
161
162 // no close bracket, probably trying to do a left shift, take literal
163 // char sequence
164 const rawTokenize = (characters: string): void => {
165 for (const c of characters) {
166 result.push(c);
167 }
168 };
169
170 // don't use a for of here, since the iterator doesn't split surrogate pairs
171 // eslint-disable-next-line @typescript-eslint/prefer-for-of
172 for (let i = 0; i < sequence.length; i++) {
173 const char = sequence[i];
174
175 key += char;
176
177 if (char === '<') {
178 if (isBracketedKey) {
179 rawTokenize(key.slice(0, key.length - 1));
180 key = '<';
181 } else {
182 isBracketedKey = true;
183 }
184 }
185
186 if (char === '>') {
187 isBracketedKey = false;
188 }
189
190 if (isBracketedKey) {
191 continue;
192 }
193
194 result.push(key);
195 key = '';
196 }
197
198 if (isBracketedKey) {
199 rawTokenize(key);
200 }
201
202 return result;
203}
204
205async function applyDocState(editor: vscode.TextEditor, docState: DocState): Promise<void> {
206 assert.ok(

Callers 2

testItFunction · 0.85
testItWithRemapsFunction · 0.85

Calls 1

rawTokenizeFunction · 0.85

Tested by

no test coverage detected