diff --git a/src/actions/base.ts b/src/actions/base.ts index af812636edf..73f9e694b42 100644 --- a/src/actions/base.ts +++ b/src/actions/base.ts @@ -202,12 +202,15 @@ export abstract class BaseCommand extends BaseAction { return; } - const cursorsToIterateOver = [...vimState.cursors].sort((a, b) => - a.start.line > b.start.line || - (a.start.line === b.start.line && a.start.character > b.start.character) - ? 1 - : -1, - ); + const cursorsToIterateOver = + vimState.cursors.length > 1 + ? [...vimState.cursors].sort((a, b) => + a.start.line > b.start.line || + (a.start.line === b.start.line && a.start.character > b.start.character) + ? 1 + : -1, + ) + : vimState.cursors; const resultingCursors: Cursor[] = []; diff --git a/src/actions/commands/insert.ts b/src/actions/commands/insert.ts index 739eede9da2..9d59cea9b0c 100644 --- a/src/actions/commands/insert.ts +++ b/src/actions/commands/insert.ts @@ -292,6 +292,66 @@ export class ExitInsertMode extends BaseCommand { } } +@RegisterAction +export class BackspaceInInsertMode extends BaseCommand { + modes = [Mode.Insert]; + keys = [[''], ['']]; + + override runsOnceForEveryCursor() { + return false; + } + + public override async exec(position: Position, vimState: VimState): Promise { + vimState.recordedState.transformer.vscodeCommand('deleteLeft'); + } +} + +@RegisterAction +export class TypeInInsertMode extends BaseCommand { + modes = [Mode.Insert]; + keys = ['']; + + public override async exec(position: Position, vimState: VimState): Promise { + const char = this.keysPressed.at(-1)!; + + let text = char; + + if (char.length === 1) { + const prevHighSurrogate = + vimState.modeData.mode === Mode.Insert ? vimState.modeData.highSurrogate : undefined; + + if (isHighSurrogate(char.charCodeAt(0))) { + await vimState.setModeData({ + mode: Mode.Insert, + highSurrogate: char, + }); + + if (prevHighSurrogate === undefined) return; + text = prevHighSurrogate; + } else { + if (isLowSurrogate(char.charCodeAt(0)) && prevHighSurrogate !== undefined) { + text = prevHighSurrogate + char; + } + + await vimState.setModeData({ + mode: Mode.Insert, + highSurrogate: undefined, + }); + } + } + + vimState.recordedState.transformer.addTransformation({ + type: 'insertTextVSCode', + text, + isMultiCursor: vimState.isMultiCursor, + }); + } + + public override toString(): string { + return this.keysPressed.at(-1)!; + } +} + @RegisterAction export class InsertPreviousText extends BaseCommand { modes = [Mode.Insert]; @@ -377,20 +437,6 @@ class DecreaseIndent extends IndentCommand { override readonly delta = -1; } -@RegisterAction -export class BackspaceInInsertMode extends BaseCommand { - modes = [Mode.Insert]; - keys = [[''], ['']]; - - override runsOnceForEveryCursor() { - return false; - } - - public override async exec(position: Position, vimState: VimState): Promise { - vimState.recordedState.transformer.vscodeCommand('deleteLeft'); - } -} - @RegisterAction class DeleteInInsertMode extends BaseCommand { modes = [Mode.Insert]; @@ -405,52 +451,6 @@ class DeleteInInsertMode extends BaseCommand { } } -@RegisterAction -export class TypeInInsertMode extends BaseCommand { - modes = [Mode.Insert]; - keys = ['']; - - public override async exec(position: Position, vimState: VimState): Promise { - const char = this.keysPressed.at(-1)!; - - let text = char; - - if (char.length === 1) { - const prevHighSurrogate = - vimState.modeData.mode === Mode.Insert ? vimState.modeData.highSurrogate : undefined; - - if (isHighSurrogate(char.charCodeAt(0))) { - await vimState.setModeData({ - mode: Mode.Insert, - highSurrogate: char, - }); - - if (prevHighSurrogate === undefined) return; - text = prevHighSurrogate; - } else { - if (isLowSurrogate(char.charCodeAt(0)) && prevHighSurrogate !== undefined) { - text = prevHighSurrogate + char; - } - - await vimState.setModeData({ - mode: Mode.Insert, - highSurrogate: undefined, - }); - } - } - - vimState.recordedState.transformer.addTransformation({ - type: 'insertTextVSCode', - text, - isMultiCursor: vimState.isMultiCursor, - }); - } - - public override toString(): string { - return this.keysPressed.at(-1)!; - } -} - @RegisterAction class InsertDigraph extends BaseCommand { modes = [Mode.Insert]; diff --git a/src/configuration/langmap.ts b/src/configuration/langmap.ts index e29d22aba46..07b0bbdad79 100644 --- a/src/configuration/langmap.ts +++ b/src/configuration/langmap.ts @@ -4,12 +4,12 @@ import { configuration } from './configuration'; const nonMatchable = /<(any|leader|number|alpha|character|register|macro)>/; const literalKeys = /<(any|number|alpha|character)>/; // do not treat or as literal! -const literalModes = [ +const literalModes = new Set([ Mode.Insert, Mode.Replace, Mode.CommandlineInProgress, Mode.SearchInProgressMode, -]; +]); let lastLangmapString = ''; @@ -77,7 +77,7 @@ function parseLangmap(langmapString: string): { } export function isLiteralMode(mode: Mode): boolean { - return literalModes.includes(mode); + return literalModes.has(mode); } function map(langmap: Map, key: string): string {