Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/actions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you measured a performance difference with these changes? I want to be sure we're not prematurely optimizing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried - but could not create reproduceable measurements. I understand

? [...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[] = [];

Expand Down
120 changes: 60 additions & 60 deletions src/actions/commands/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,66 @@ export class ExitInsertMode extends BaseCommand {
}
}

@RegisterAction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for moving the methods? It makes it more difficult to tell what changed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the only change that was made here was the move itself - only change of location and not of contents - This change causes the "TypeInInsertMode" action to get identified earlier (at iteration 6 instead of 11) at iteration that happens at base.ts line 267

export class BackspaceInInsertMode extends BaseCommand {
modes = [Mode.Insert];
keys = [['<BS>'], ['<C-h>']];

override runsOnceForEveryCursor() {
return false;
}

public override async exec(position: Position, vimState: VimState): Promise<void> {
vimState.recordedState.transformer.vscodeCommand('deleteLeft');
}
}

@RegisterAction
export class TypeInInsertMode extends BaseCommand {
modes = [Mode.Insert];
keys = ['<character>'];

public override async exec(position: Position, vimState: VimState): Promise<void> {
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];
Expand Down Expand Up @@ -377,20 +437,6 @@ class DecreaseIndent extends IndentCommand {
override readonly delta = -1;
}

@RegisterAction
export class BackspaceInInsertMode extends BaseCommand {
modes = [Mode.Insert];
keys = [['<BS>'], ['<C-h>']];

override runsOnceForEveryCursor() {
return false;
}

public override async exec(position: Position, vimState: VimState): Promise<void> {
vimState.recordedState.transformer.vscodeCommand('deleteLeft');
}
}

@RegisterAction
class DeleteInInsertMode extends BaseCommand {
modes = [Mode.Insert];
Expand All @@ -405,52 +451,6 @@ class DeleteInInsertMode extends BaseCommand {
}
}

@RegisterAction
export class TypeInInsertMode extends BaseCommand {
modes = [Mode.Insert];
keys = ['<character>'];

public override async exec(position: Position, vimState: VimState): Promise<void> {
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];
Expand Down
6 changes: 3 additions & 3 deletions src/configuration/langmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <register> or <macro> as literal!
const literalModes = [
const literalModes = new Set<Mode>([
Mode.Insert,
Mode.Replace,
Mode.CommandlineInProgress,
Mode.SearchInProgressMode,
];
]);

let lastLangmapString = '';

Expand Down Expand Up @@ -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<string, string>, key: string): string {
Expand Down