Skip to content

fix(ui): restore output views without normal commands#452

Merged
sudo-tee merged 4 commits into
sudo-tee:mainfrom
jensenojs:fix/suppress-modechanged-during-output-scroll
Jul 9, 2026
Merged

fix(ui): restore output views without normal commands#452
sudo-tee merged 4 commits into
sudo-tee:mainfrom
jensenojs:fix/suppress-modechanged-during-output-scroll

Conversation

@jensenojs

@jensenojs jensenojs commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Remove Normal-mode view commands from automatic output view maintenance.

The previous fix in #427 tried to protect the IME-sensitive output auto-scroll path by suppressing focus-related window/buffer events around normal! zb. With the view restore moved to winsaveview() / winrestview(), that wrapper no longer has a job.

This patch removes the source instead:

  • output auto-scroll no longer uses normal! zb;
  • lazy-render top-anchor restore no longer uses normal! zt;
  • the fix: keep input focused during output auto-scroll #427 eventignore wrapper is removed;
  • the behavior is covered directly: input focus stays put, and auto-scroll does not emit WinEnter, WinLeave, BufEnter, or ModeChanged.

Other normal! call sites are left unchanged because they are user navigation / picker / selection paths, not automatic output view maintenance.

Tests

  • ./run_tests.sh

@phanen

phanen commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Here's another way to avoid emit ModeChanged

local function scroll_view(target)
  local view = vim.fn.winsaveview()
  view.topline = view.lnum - target + 1
  vim.fn.winrestview(view)
end

vim.keymap.set('n', '<leader>zb', function()
  scroll_view(vim.api.nvim_win_get_height(0))
end)
vim.keymap.set('n', '<leader>zz', function()
  scroll_view(math.ceil(vim.api.nvim_win_get_height(0) / 2))
end)

vim.keymap.set('n', '<leader>zt', function()
  scroll_view(1)
end)

@phanen

phanen commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

All of this if-else branch should be included if we want to suppressed ModeChanged.

if windows and vim.api.nvim_get_current_win() == windows.input_win then
with_window_event_autocmds_ignored(function()
vim.api.nvim_win_call(win, function()
vim.cmd('normal! zb')
end)
end)
else
vim.api.nvim_win_call(win, function()
vim.cmd('normal! zb')
end)
end

Also there're many other call site not sure if all of them related.
image

@jensenojs jensenojs changed the title fix(renderer): suppress mode changes during output scroll fix(ui): restore output views without normal commands Jul 8, 2026
@jensenojs jensenojs marked this pull request as draft July 8, 2026 06:10
@jensenojs jensenojs force-pushed the fix/suppress-modechanged-during-output-scroll branch from 17aad80 to f1526ca Compare July 8, 2026 06:15
@jensenojs

Copy link
Copy Markdown
Collaborator Author

Thanks, your suggestion is the right direction. I revised the PR to use winsaveview() / winrestview() for output view restore instead of suppressing ModeChanged.

This removes the normal! zb / normal! zt calls from automatic output maintenance, and also removes the old eventignore wrapper.

Could you give the updated branch a try? @phanen

@phanen

phanen commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

yeah, I'm using this branch now.

Comment thread lua/opencode/ui/output_window.lua Outdated
@jensenojs jensenojs marked this pull request as ready for review July 9, 2026 01:47
@jensenojs jensenojs requested a review from phanen July 9, 2026 01:47
Comment thread tests/unit/cursor_tracking_spec.lua Outdated
@phanen

phanen commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Other thing lgtm, I've been on this branch a day and didn't reproduce input switch issue.

@sudo-tee

sudo-tee commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR.

I've tested and it seems pretty stable for me to.

@sudo-tee sudo-tee merged commit 7962b68 into sudo-tee:main Jul 9, 2026
5 checks passed
@jensenojs jensenojs deleted the fix/suppress-modechanged-during-output-scroll branch July 9, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants