Skip to content

Commit

Permalink
feat: add options to disable or change selection debounce time (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed Oct 8, 2023
1 parent 888e6e3 commit 2515e46
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,31 @@
"backgroundColor": "theme.editor.selectionBackground"
}
}
},
"vscode-neovim.normalSelectionDebounceTime": {
"type": "integer",
"minimum": 20,
"maximum": 100,
"default": 50,
"description": "Debounce time used to synchronize selection from VSCode to Nvim, typically referring to cursor movement"
},
"vscode-neovim.mouseSelectionDebounceTime": {
"default": 100,
"enum": [
0,
50,
100,
150,
200
],
"enumDescriptions": [
"Disable mouse selection sync",
"50ms",
"100ms",
"150ms",
"200ms"
],
"description": "Debounce time for synchronizing mouse selection. Set to 0 to disable synchronization"
}
}
},
Expand Down
10 changes: 10 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ export class Config implements Disposable {
get outputToConsole() {
return this.cfg.get("logOutputToConsole", false);
}

get normalSelectionDebounceTime() {
return this.cfg.get("normalSelectionDebounceTime", 50);
}
get mouseSelectionDebounceTime() {
return this.cfg.get("mouseSelectionDebounceTime", 100);
}
get disableMouseSelection() {
return this.mouseSelectionDebounceTime === 0;
}
}

export const config = new Config();
8 changes: 5 additions & 3 deletions src/cursor_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { MainController } from "./main_controller";
import { Mode } from "./mode_manager";
import { NeovimExtensionRequestProcessable, NeovimRedrawProcessable } from "./neovim_events_processable";
import { convertEditorPositionToVimPosition, convertVimPositionToEditorPosition, ManualPromise } from "./utils";
import { config } from "./config";

const logger = createLogger("CursorManager");

Expand Down Expand Up @@ -323,9 +324,9 @@ export class CursorManager implements Disposable, NeovimRedrawProcessable, Neovi
if (this.previousApplyDebounceTime !== undefined) {
debounceTime = this.previousApplyDebounceTime;
} else if (kind === TextEditorSelectionChangeKind.Mouse) {
debounceTime = 100;
debounceTime = config.mouseSelectionDebounceTime;
} else {
debounceTime = 50;
debounceTime = config.normalSelectionDebounceTime;
}
this.previousApplyDebounceTime = debounceTime;

Expand Down Expand Up @@ -369,7 +370,8 @@ export class CursorManager implements Disposable, NeovimRedrawProcessable, Neovi
await this.client.input("<Esc>");
await this.updateNeovimCursorPosition(editor, selection.active);
} else {
await this.updateNeovimVisualSelection(editor, selection);
if (kind != TextEditorSelectionChangeKind.Mouse || !config.disableMouseSelection)
await this.updateNeovimVisualSelection(editor, selection);
}
}
this.previousApplyDebounceTime = undefined;
Expand Down

0 comments on commit 2515e46

Please sign in to comment.