Skip to content

Commit

Permalink
fix(viewport): reduce cursor jitter (temporary solution) (#1459)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed Sep 17, 2023
1 parent 7089bb5 commit 237e795
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/viewport_manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NeovimClient } from "neovim";
import { Disposable, TextEditor, window, TextEditorVisibleRangesChangeEvent, Position } from "vscode";
import { Disposable, TextEditor, window, TextEditorVisibleRangesChangeEvent, Position, workspace } from "vscode";
import { DebouncedFunc, debounce } from "lodash-es";

import { Logger } from "./logger";
import { MainController } from "./main_controller";
Expand Down Expand Up @@ -129,9 +130,36 @@ export class ViewportManager implements Disposable, NeovimRedrawProcessable, Neo
}
}

// #region
// FIXME: This is a temporary solution to reduce cursor jitter when scrolling.
private debouncedScrollNeovim!: DebouncedFunc<ViewportManager["scrollNeovim"]>;
private debounceTime = 20;
private refreshDebounceTime(): boolean {
const smoothScrolling = workspace.getConfiguration("editor").get("smoothScrolling", false);
const debounceTime = smoothScrolling ? 100 : 20; // vscode's scrolling duration is 125ms.
const updated = this.debounceTime !== debounceTime;
this.debounceTime = debounceTime;
return updated;
}
private refreshDebounceScroll() {

Check warning on line 144 in src/viewport_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (macos-latest)

Missing return type on function

Check warning on line 144 in src/viewport_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

Missing return type on function

Check warning on line 144 in src/viewport_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

Missing return type on function

Check warning on line 144 in src/viewport_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (macos-latest)

Missing return type on function

Check warning on line 144 in src/viewport_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

Missing return type on function

Check warning on line 144 in src/viewport_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

Missing return type on function
this.debouncedScrollNeovim = debounce(this.scrollNeovim.bind(this), this.debounceTime, {
leading: false,
trailing: true,
});
}
private onDidChangeVisibleRange = async (e: TextEditorVisibleRangesChangeEvent): Promise<void> => {
this.scrollNeovim(e.textEditor);
if (!this.debouncedScrollNeovim) {
this.refreshDebounceTime();
this.refreshDebounceScroll();
workspace.onDidChangeConfiguration(
(e) => e.affectsConfiguration("editor") && this.refreshDebounceTime() && this.refreshDebounceScroll(),
null,
this.disposables,
);
}
this.debouncedScrollNeovim(e.textEditor);
};
// #endregion

public scrollNeovim(editor: TextEditor | null): void {
if (editor == null || this.main.modeManager.isInsertMode) {
Expand Down

0 comments on commit 237e795

Please sign in to comment.