From 2515e466a532ca280c8800d00e786de96cc0b1d9 Mon Sep 17 00:00:00 2001 From: wongxy Date: Sun, 8 Oct 2023 23:49:38 +0800 Subject: [PATCH] feat: add options to disable or change selection debounce time (#1504) --- package.json | 25 +++++++++++++++++++++++++ src/config.ts | 10 ++++++++++ src/cursor_manager.ts | 8 +++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index fbb855f97..47b8834d0 100644 --- a/package.json +++ b/package.json @@ -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" } } }, diff --git a/src/config.ts b/src/config.ts index 849703881..6740acfee 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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(); diff --git a/src/cursor_manager.ts b/src/cursor_manager.ts index 8963d1a2d..f0b0991ee 100644 --- a/src/cursor_manager.ts +++ b/src/cursor_manager.ts @@ -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"); @@ -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; @@ -369,7 +370,8 @@ export class CursorManager implements Disposable, NeovimRedrawProcessable, Neovi await this.client.input(""); 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;