Skip to content

add stable keyboard scrolling to vim floating preview popups - #5114

Open
coriocactus wants to merge 1 commit into
dense-analysis:masterfrom
coriocactus:add-floating-preview-keyboard-scrolling
Open

coriocactus wants to merge 1 commit into
dense-analysis:masterfrom
coriocactus:add-floating-preview-keyboard-scrolling

Conversation

@coriocactus

@coriocactus coriocactus commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

Vim floating previews for hover and ALEDetail can't be scrolled from the keyboard. When the text is longer than the popup, the only way to read the rest is the mouse, and moved: 'any' closes the popup on any cursor motion.

This adds a popup filter, used in Normal mode only:

  • When a preview has more text than fits, Vim's own scroll keys scroll the preview instead of the buffer: CTRL-E/CTRL-Y by a line, CTRL-D/CTRL-U by half a page, CTRL-F/CTRL-B by a page.
  • <Esc> closes the preview.
  • Other keys pass through. If all the text already fits, the scroll keys pass through too, so short popups behave as they do now.

How it works:

  • Each key runs as a counted CTRL-D or CTRL-U inside the popup with win_execute(). Vim stops these at the start and end of the text, wrapped or not, so the popup never scrolls into blank space and its height never changes. ALE doesn't do any scroll math of its own. The filter redraws after each scroll: without that, Vim 8.2.4843 scrolls wrapped text one line too far when keys arrive faster than redraws (found by the Vim 8.2 Windows CI job).
  • The mouse wheel is left alone. Vim already scrolls a popup with the wheel when the pointer is over it.
  • Before patch 9.2.0419, Vim works out a popup's width from the lines currently in view, so the width jumps around while scrolling. On those versions ALE sets minwidth to the widest line, unless the user has set minwidth or maxwidth. The check is gated on has('patch-9.2.0419'), so it can be deleted when ALE's minimum Vim version passes that patch.
  • The filter is script-local, so this adds no new public API. Setting filter in g:ale_floating_preview_popup_opts still replaces it.

Neovim floating windows are unchanged.

Tests cover line, half-page and full-page scrolling with stops at both ends, reaching the end of wrapped text, keys passing through when nothing needs scrolling, other keys passing through, <Esc>, the width fix, and user width options being kept. One test sends keys through feedkeys() to check that Vim really delivers them to the filter in Normal mode. They pass on Vim 8.2 and 9.2. On Neovim they are skipped, because it has no popupwin.

@coriocactus
coriocactus force-pushed the add-floating-preview-keyboard-scrolling branch from 80f3c87 to dd89b90 Compare April 4, 2026 07:25
@coriocactus
coriocactus marked this pull request as draft April 4, 2026 08:11
@coriocactus
coriocactus force-pushed the add-floating-preview-keyboard-scrolling branch from dd89b90 to 3d67758 Compare April 4, 2026 08:36
@coriocactus
coriocactus marked this pull request as ready for review April 4, 2026 08:41
@coriocactus coriocactus changed the title add keyboard scrolling and dismiss to floating preview popups add stable keyboard scrolling to vim floating preview popups Apr 4, 2026
@hsanson
hsanson requested a review from Copilot April 10, 2026 14:15
@hsanson
hsanson requested a review from w0rp April 10, 2026 14:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds keyboard (and mouse wheel) scrolling support for Vim popupwin-based floating preview windows in ALE, plus sizing stabilization to prevent resize jitter while scrolling. NeoVim floating previews are unchanged.

Changes:

  • Introduces a Vim popup filter (normal-mode filtermode) to handle <C-n>/<C-p>, <C-d>/<C-u>, mouse wheel, and <Esc> for floating preview popups.
  • Adds “managed” width/height locking for Vim popups when users haven’t provided explicit size limits.
  • Adds a new Vader test suite covering scrolling behavior, boundary clamping, closing on escape, passthrough keys, and size locking; updates docs accordingly.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
autoload/ale/floating_preview.vim Implements popup filter, scroll/clamp logic, and managed size locking/reset for Vim popup previews.
doc/ale.txt Documents the new scrolling keys and sizing behavior for Vim popup previews and how to override the filter.
test/test_floating_preview_popupwin.vader Adds coverage for popup filter behavior, scroll boundaries, escape close, and size stability during scrolling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread doc/ale.txt Outdated
@w0rp

w0rp commented May 12, 2026

Copy link
Copy Markdown
Member

I'll paste this in every open PR: We finally managed to migrate CI checks for Windows from AppVeyor to GitHub Actions, and we've updated the minimum supported Vim version to 8.2. (Thought Vim 8.0 might happen to work for some.) In order to get checks to run again for a PR you'll need to rebase or merge.

@coriocactus
coriocactus force-pushed the add-floating-preview-keyboard-scrolling branch from e514c40 to 3ad02af Compare May 13, 2026 04:48
@coriocactus
coriocactus force-pushed the add-floating-preview-keyboard-scrolling branch from 3ad02af to 39ff78d Compare October 8, 2026 18:39
@coriocactus
coriocactus force-pushed the add-floating-preview-keyboard-scrolling branch from 39ff78d to df9465f Compare October 8, 2026 18:50
@rymdbar

rymdbar commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

How to try out this pull-request:

  1. Ensure vim, ale (doh!), cargo and rust-analyzer are installed.
  2. Configure .vimrc to contain let g:ale_floating_preview = 1 and let g:ale_linters.rust = [ 'rustc' ].
  3. Create a rust project.
mkdir pr5114
cd pr5114/
cargo init
  1. Update src/main.rs to contain:
fn main() {
    let x = 42;
    let y: String = x;
}
  1. Resize vim to be only 5-6 lines tall. Run :ALEDetail and observe the problem as described.

  2. Checkout pull-request branch.

  3. Observe how the issue is solved.

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.

4 participants