From 9faafbe05350fa3c3f4a8019c7149afb3adc2ed8 Mon Sep 17 00:00:00 2001 From: Alison Winters Date: Sun, 13 Nov 2022 17:26:18 +0800 Subject: [PATCH 1/2] remove unnecessarily async functions --- src/Actions/MoveCursor.ts | 8 +++----- src/Modes/Insert.ts | 14 +++++--------- src/Modes/Mode.ts | 10 +++------- src/Modes/Normal.ts | 6 ++---- src/Modes/Visual.ts | 4 +--- src/Modes/VisualLine.ts | 4 +--- 6 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/Actions/MoveCursor.ts b/src/Actions/MoveCursor.ts index 00d77d0..1f600d8 100644 --- a/src/Actions/MoveCursor.ts +++ b/src/Actions/MoveCursor.ts @@ -24,22 +24,20 @@ export class ActionMoveCursor { }, 100); } - static updatePreferredColumn(): Thenable { + static updatePreferredColumn(): void { if (ActionMoveCursor.isUpdatePreferredColumnBlocked) { - return Promise.resolve(false); + return; } const activeTextEditor = window.activeTextEditor; if (!activeTextEditor) { - return Promise.resolve(false); + return; } ActionMoveCursor.preferredColumnBySelectionIndex = activeTextEditor.selections.map( (selection) => UtilPosition.getColumn(activeTextEditor, selection.active), ); - - return Promise.resolve(true); } static async byMotions(args: { diff --git a/src/Modes/Insert.ts b/src/Modes/Insert.ts index ed300da..9ac7314 100644 --- a/src/Modes/Insert.ts +++ b/src/Modes/Insert.ts @@ -269,9 +269,9 @@ export class ModeInsert extends Mode { this.processRecord(); } - protected onWillCommandMapMakesChanges(map: CommandMap): Promise { + protected onWillCommandMapMakesChanges(map: CommandMap): void { if (!this.isRecording) { - return Promise.resolve(false); + return; } if (map.keys === '\n') { @@ -285,18 +285,16 @@ export class ModeInsert extends Mode { isRepeating: true, }); } - - return Promise.resolve(true); } - protected onDidCommandMapMakesChanges(map: CommandMap): Promise { + protected onDidCommandMapMakesChanges(map: CommandMap): void { if (!this.isRecording) { - return Promise.resolve(false); + return; } if (map.keys === '\n') { if (!this.textEditor) { - return Promise.resolve(false); + return; } this.recordStartPosition = this.textEditor.selection.active; @@ -304,8 +302,6 @@ export class ModeInsert extends Mode { this.recordStartPosition.line, ).text; } - - return Promise.resolve(true); } onDidChangeTextEditorSelection(): void { diff --git a/src/Modes/Mode.ts b/src/Modes/Mode.ts index 11c31c4..de42b83 100644 --- a/src/Modes/Mode.ts +++ b/src/Modes/Mode.ts @@ -96,16 +96,12 @@ export abstract class Mode { /** * Override this to do something before command map makes changes. */ - protected onWillCommandMapMakesChanges(map: CommandMap): Promise { - return Promise.resolve(true); - } + protected onWillCommandMapMakesChanges(map: CommandMap): void {} /** * Override this to do something after command map made changes. */ - protected onDidCommandMapMakesChanges(map: CommandMap): Promise { - return Promise.resolve(true); - } + protected onDidCommandMapMakesChanges(map: CommandMap): void {} /** * Override this to do something after selection changes. @@ -132,7 +128,7 @@ export abstract class Mode { return; } - let promise: Promise = Promise.resolve(true); + let promise: Promise = Promise.resolve(true); const isAnyActionIsChange = map.actions.some((action) => { return StaticReflect.getMetadata(SymbolMetadata.Action.isChange, action); diff --git a/src/Modes/Normal.ts b/src/Modes/Normal.ts index fd13df0..5bc5042 100644 --- a/src/Modes/Normal.ts +++ b/src/Modes/Normal.ts @@ -367,9 +367,9 @@ export class ModeNormal extends Mode { return this._recordedCommandMaps; } - protected onWillCommandMapMakesChanges(map: CommandMap): Promise { + protected onWillCommandMapMakesChanges(map: CommandMap): void { if (map.isRepeating) { - return Promise.resolve(false); + return; } const actions = map.actions.filter((action) => { @@ -386,8 +386,6 @@ export class ModeNormal extends Mode { isRepeating: true, }, ]; - - return Promise.resolve(true); } onDidRecordFinish(recordedCommandMaps: CommandMap[], lastModeID: ModeID): void { diff --git a/src/Modes/Visual.ts b/src/Modes/Visual.ts index 2808fc4..9953753 100644 --- a/src/Modes/Visual.ts +++ b/src/Modes/Visual.ts @@ -219,7 +219,7 @@ export class ModeVisual extends Mode { return this._recordedCommandMaps; } - protected onWillCommandMapMakesChanges(map: CommandMap): Promise { + protected onWillCommandMapMakesChanges(map: CommandMap): void { const actions = map.actions.filter((action) => { return ( StaticReflect.getMetadata(SymbolMetadata.Action.shouldSkipOnRepeat, action) !== true @@ -243,7 +243,5 @@ export class ModeVisual extends Mode { isRepeating: true, }, ]; - - return Promise.resolve(true); } } diff --git a/src/Modes/VisualLine.ts b/src/Modes/VisualLine.ts index ccd4db2..cb09df1 100644 --- a/src/Modes/VisualLine.ts +++ b/src/Modes/VisualLine.ts @@ -216,7 +216,7 @@ export class ModeVisualLine extends Mode { return this._recordedCommandMaps; } - protected onWillCommandMapMakesChanges(map: CommandMap): Promise { + protected onWillCommandMapMakesChanges(map: CommandMap): void { const actions = map.actions.filter((action) => { return ( StaticReflect.getMetadata(SymbolMetadata.Action.shouldSkipOnRepeat, action) !== true @@ -240,7 +240,5 @@ export class ModeVisualLine extends Mode { isRepeating: true, }, ]; - - return Promise.resolve(true); } } From ac2ced20e0881fbe2a68e6ba453baff360136d9a Mon Sep 17 00:00:00 2001 From: Alison Winters Date: Sun, 13 Nov 2022 18:05:46 +0800 Subject: [PATCH 2/2] await mode changes triggered by window events --- src/Dispatcher.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Dispatcher.ts b/src/Dispatcher.ts index b12e96c..d58f62c 100644 --- a/src/Dispatcher.ts +++ b/src/Dispatcher.ts @@ -68,18 +68,18 @@ export class Dispatcher { this.disposables.push( window.onDidChangeTextEditorSelection(() => { // Ensure this is executed after all pending commands. - setTimeout(() => { - ActionMode.switchByActiveSelections(this._currentMode.id); + setTimeout(async () => { + await ActionMode.switchByActiveSelections(this._currentMode.id); ActionMoveCursor.updatePreferredColumn(); this._currentMode.onDidChangeTextEditorSelection(); }, 0); }), - window.onDidChangeActiveTextEditor(() => { + window.onDidChangeActiveTextEditor(async () => { if (Configuration.defaultModeID === ModeID.INSERT) { - ActionMode.toInsert(); + await ActionMode.toInsert(); } else { // Passing `null` to `currentMode` to force mode switch. - ActionMode.switchByActiveSelections(null); + await ActionMode.switchByActiveSelections(null); } ActionMoveCursor.updatePreferredColumn(); }),