Skip to content

Commit

Permalink
fix(incsearch): viewport is not updating during searching (#1575)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed Oct 29, 2023
1 parent 85057b8 commit b8696a3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/highlight_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export class HighlightManager implements Disposable {
this.disposables.push(eventBus.on("redraw", this.handleRedraw, this));
}

private handleRedraw(data: EventBusData<"redraw">): void {
private async handleRedraw(data: EventBusData<"redraw">): Promise<void> {
await this.main.viewportManager.isSyncDone;

const gridHLUpdates: Set<number> = new Set();

for (const { name, args } of data) {
Expand Down
7 changes: 7 additions & 0 deletions src/mode_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export class Mode {
public get isNormal(): boolean {
return this.name === "normal";
}
public get isCmdline(): boolean {
return this.name === "cmdline";
}
}
export class ModeManager implements Disposable {
private disposables: Disposable[] = [];
Expand Down Expand Up @@ -87,6 +90,10 @@ export class ModeManager implements Disposable {
return this.mode.isNormal;
}

public get isCmdlineMode(): boolean {
return this.mode.isCmdline;
}

public get isRecordingInInsertMode(): boolean {
return this.isRecording;
}
Expand Down
31 changes: 29 additions & 2 deletions src/viewport_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { config } from "./config";
import { EventBusData, eventBus } from "./eventBus";
import { createLogger } from "./logger";
import { MainController } from "./main_controller";
import { disposeAll } from "./utils";
import { ManualPromise, disposeAll } from "./utils";

const logger = createLogger("ViewportManager");

Expand All @@ -27,6 +27,8 @@ export class ViewportManager implements Disposable {
*/
private gridViewport: Map<number, Viewport> = new Map();

private syncViewportPromise?: ManualPromise;

private get client() {
return this.main.client;
}
Expand All @@ -48,6 +50,10 @@ export class ViewportManager implements Disposable {
);
}

public get isSyncDone(): Promise<void> {
return Promise.resolve(this.syncViewportPromise?.promise);
}

/**
* Get viewport data
* @param gridId: grid id
Expand Down Expand Up @@ -76,7 +82,7 @@ export class ViewportManager implements Disposable {
return new Position(view.topline, view.leftcol);
}

private handleRedraw(data: EventBusData<"redraw">) {
private async handleRedraw(data: EventBusData<"redraw">) {
for (const { name, args } of data) {
switch (name) {
case "win_viewport": {
Expand All @@ -87,6 +93,27 @@ export class ViewportManager implements Disposable {
view.line = curline;
view.col = curcol;
}
// #1555
if (this.main.modeManager.isCmdlineMode && !this.syncViewportPromise) {
this.syncViewportPromise = new ManualPromise();
try {
const [currWin, currView] = (await this.client.lua(
"return {vim.api.nvim_get_current_win(), vim.fn.winsaveview()}",
)) as [number, any];
const grid = this.main.bufferManager.getGridIdForWinId(currWin);
if (grid) {
const view = this.getViewport(grid);
view.line = currView.lnum - 1;
view.col = currView.col;
view.topline = currView.topline - 1;
view.leftcol = currView.leftcol;
view.skipcol = currView.skipcol;
}
} finally {
this.syncViewportPromise.resolve();
this.syncViewportPromise = undefined;
}
}
break;
}
case "grid_destroy": {
Expand Down

0 comments on commit b8696a3

Please sign in to comment.