feat: allow switching into hover window via ctrl+w w for long translasion#7
feat: allow switching into hover window via ctrl+w w for long translasion#7code-dom wants to merge 3 commits intonoir4y:mainfrom
Conversation
…tions
1. Replace BufLeave/WinLeave with WinEnter to trigger hover cleanup.
2. Remove BufWipeout autocmd as closing hover on unrelated buffer deletion is wrong — hover should persist when cursor has not moved.
3. Bind q/<Esc> to close the hover window on creation.
There was a problem hiding this comment.
@code-dom
Thanks for working on this — the overall direction makes sense, especially the change to avoid immediately closing when focus enters the hover window, and the addition of q / <Esc> to close it.
That said, I think there is still a timer cleanup issue here.
Previously, cleanup_timer(args.buf) ran on BufLeave / WinLeave, so the timer attached to the source buffer was cleaned up when leaving that buffer. After this change, cleanup runs on WinEnter using the current buffer, which means a timer from the previous buffer can remain alive and fire later.
Since the timer callback calls parser.get_text_at_cursor() without an explicit bufnr, that stale timer may end up reading from the current window/buffer instead of the original source buffer.
I think the safer approach would be to:
- keep the
CursorMovedguard for the hover buffer - keep
BufLeave/WinLeavefor timer cleanup only - use
WinEnteronly for hover close behavior
There also don’t seem to be regression tests covering this timer/cleanup behavior, so I don’t think this is safe to merge as-is.
|
Thanks for the review — I’ve addressed the cleanup issue in the latest commits.
I also added regression tests for stale timer cleanup and hover-window switching behavior, and the autocmd tests pass locally. |
noir4y
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. I still see two hover lifecycle regressions in the current PR head that should be fixed before merge:
- Closing hover only on
WinEntermisses same-window buffer changes such as:bnext/:edit. Those fire buffer events but notWinEnter, so the existing hover can remain visible over the next buffer. - Auto-hover is still active while focused in the hover buffer.
CursorHoldcan create a timer for the hover buffer, andCursorMovedreturns before cleaning that timer, so it can survive during interactive use and fire unexpectedly later.
Concretely, this needs:
- a buffer-based close path for non-hover buffers, not just
WinEnter - preventing
CursorHoldfrom creating timers for the hover buffer, or cleaning those timers before the hover-bufferCursorMovedguard returns
Both cases should have regression tests before merge.
Title:
feat: allow switching into hover window via ctrl+w w
Body:
Problem
The hover window was closed immediately when entering it via
ctrl+w w,making it impossible to scroll or read long translations.
Changes
BufLeave/WinLeaveautocmds withWinEnterto fix premature hover closureq/<Esc>to close the hover window when focusedBufWipeoutautocmd whose logic incorrectly closed hover when an unrelated buffer was deleted