* Tokenize a string like `"abc d "` into `["a", "b", "c", " ", "d", " "]`
(sequence: string)
| 155 | * Tokenize a string like `"abc<Esc>d<C-c>"` into `["a", "b", "c", "<Esc>", "d", "<C-c>"]` |
| 156 | */ |
| 157 | function 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 | |
| 205 | async function applyDocState(editor: vscode.TextEditor, docState: DocState): Promise<void> { |
| 206 | assert.ok( |
no test coverage detected