Skip to content

Commit

Permalink
fix(viewport): Avoid awaiting the hack to refresh viewport
Browse files Browse the repository at this point in the history
Possible ordering issue with handling multiple win_viewport events
  • Loading branch information
xiyaowong committed Nov 17, 2023
1 parent ed4e988 commit d5cb701
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/viewport_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,26 @@ export class ViewportManager implements Disposable {
view.line = curline;
view.col = curcol;
}
// #1555
// HACK: See #1575
// Don't await, as it may result in processing different events in the wrong order.
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 _lua = "return {vim.api.nvim_get_current_win(), vim.fn.winsaveview()}";
(this.client.lua(_lua) as Promise<[number, any]>)
.then(([currWin, currView]) => {
const grid = this.main.bufferManager.getGridIdForWinId(currWin);
if (!grid) return;
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;
}
})
.finally(() => {
this.syncViewportPromise?.resolve();
this.syncViewportPromise = undefined;
});
}
break;
}
Expand Down

0 comments on commit d5cb701

Please sign in to comment.