Skip to content

feat: horizontal mouse-wheel scrolling for the bufferline#1053

Open
tusharmurali wants to merge 1 commit into
akinsho:mainfrom
tusharmurali:feat/mouse-scroll
Open

feat: horizontal mouse-wheel scrolling for the bufferline#1053
tusharmurali wants to merge 1 commit into
akinsho:mainfrom
tusharmurali:feat/mouse-scroll

Conversation

@tusharmurali

Copy link
Copy Markdown

What

Adds opt-in horizontal mouse-wheel scrolling of the bufferline. When more buffers/tabs are open than fit on screen, scrolling the wheel while hovering over the bufferline shifts the visible window left/right to reveal off-screen buffers — without changing the active buffer (view-only scroll, like scrolling a horizontal list).

Enable it via:

require("bufferline").setup({
  options = {
    mouse_scroll = { enabled = true, step = 1 },
  },
})

Disabled by default, mirroring the existing hover option.

How it works

  • A new lua/bufferline/scroll.lua registers <ScrollWheelUp/Down/Left/Right> expr-keymaps, mirroring hover.lua's <MouseMove> pattern. Each acts only when the mouse is over the tabline (screenrow == 1) and otherwise returns the original key, so scrolling over normal windows is unaffected. Both vertical and horizontal wheels drive horizontal movement (up/left = towards the start).
  • The scroll position is persisted in state (scroll_offset) and honored by a parallel windowing path in the renderer (max_scroll_pivot + scroll_window in ui.lua). This leaves the existing, well-tested centring truncate logic untouched — it's only bypassed while actively scrolled.
  • The view snaps back to auto-centring when the active buffer changes (a keyboard switch) or the buffer list grows/shrinks, so you're never stranded on a stale scroll position. When everything fits on screen, scrolling is a no-op.
  • step controls how many buffers each wheel tick moves the view by.

Notes

  • Works in both buffers and tabs mode.
  • Requires mouse to be enabled. Delivery of <ScrollWheel*> events over the tabline row depends on the terminal/multiplexer (the same assumption the existing hover feature makes for <MouseMove>).

Tests

Adds unit tests in tests/ui_spec.lua covering the scroll-pivot clamping, window building/marker counts, and the handler's offset capture + clamping. Full suite passes and stylua is clean.

Scrolling the mouse wheel over the bufferline now shifts the visible
window of buffers/tabs to reveal off-screen ones, without changing the
active buffer. Opt-in via `mouse_scroll = { enabled = true, step = 1 }`,
mirroring the existing `hover` option.

The scroll position is persisted in state and honored by a parallel
windowing path in the renderer, leaving the centring `truncate` logic
untouched. The view snaps back to auto-centring when the active buffer
or the buffer list changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant