-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Insertmode performance improvement #9872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ac3976f
b8dbcb4
ba87a9a
7736b03
0dcb4f2
3b276e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,6 +292,66 @@ export class ExitInsertMode extends BaseCommand { | |
| } | ||
| } | ||
|
|
||
| @RegisterAction | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||
|
|
@@ -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]; | ||
|
|
@@ -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]; | ||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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