From 86d14a6e5369fd20c23904b9778c830e6ef6f7c5 Mon Sep 17 00:00:00 2001 From: wongxy Date: Fri, 17 May 2024 21:43:26 +0800 Subject: [PATCH] fix(incsearch): win cursor not properly revealed --- src/cursor_manager.ts | 1 + src/viewport_manager.ts | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/cursor_manager.ts b/src/cursor_manager.ts index 635c9eac7..aadacdaf5 100644 --- a/src/cursor_manager.ts +++ b/src/cursor_manager.ts @@ -111,6 +111,7 @@ export class CursorManager implements Disposable { window.visibleTextEditors.forEach((e) => (e.options.cursorStyle = style)); }, }, + main.viewportManager.onCursorChanged((grid) => this.gridCursorUpdates.addForceUpdate(grid)), ); } diff --git a/src/viewport_manager.ts b/src/viewport_manager.ts index b9a61db2c..f70aa128d 100644 --- a/src/viewport_manager.ts +++ b/src/viewport_manager.ts @@ -1,5 +1,13 @@ import { DebouncedFunc, debounce } from "lodash-es"; -import { Disposable, Position, TextEditor, TextEditorVisibleRangesChangeEvent, window, workspace } from "vscode"; +import { + Disposable, + EventEmitter, + Position, + TextEditor, + TextEditorVisibleRangesChangeEvent, + window, + workspace, +} from "vscode"; import actions from "./actions"; import { config } from "./config"; @@ -30,12 +38,18 @@ export class ViewportManager implements Disposable { private syncViewportPromise?: ManualPromise; + // TODO: Temporary solution. Need to refactor cursor manager and viewport manager. + // Related issue: https://github.com/neovim/neovim/issues/28800 + private cursorChanged = new EventEmitter(); + public onCursorChanged = this.cursorChanged.event; + private get client() { return this.main.client; } public constructor(private main: MainController) { this.disposables.push( + this.cursorChanged, window.onDidChangeTextEditorVisibleRanges(this.onDidChangeVisibleRange), eventBus.on("redraw", this.handleRedraw, this), eventBus.on("window-scroll", ([winId, saveView]) => { @@ -88,10 +102,14 @@ export class ViewportManager implements Disposable { case "win_viewport": { for (const [grid, , topline, botline, curline, curcol] of args) { const view = this.getViewport(grid); + const { line, col } = view; view.topline = topline; view.botline = botline; view.line = curline; view.col = curcol; + if (line !== curline || col !== curcol) { + this.cursorChanged.fire(grid); + } } // HACK: See #1575 // Don't await, as it may result in processing different events in the wrong order. @@ -103,11 +121,15 @@ export class ViewportManager implements Disposable { const grid = this.main.bufferManager.getGridIdForWinId(currWin); if (!grid) return; const view = this.getViewport(grid); + const { line, col } = view; view.line = currView.lnum - 1; view.col = currView.col; view.topline = currView.topline - 1; view.leftcol = currView.leftcol; view.skipcol = currView.skipcol; + if (line !== view.line || col !== view.col) { + this.cursorChanged.fire(grid); + } }) .finally(() => { this.syncViewportPromise?.resolve();