Add viewport info to JSON UI draw message#5471
Open
Yus314 wants to merge 2 commits intomawww:masterfrom
Open
Conversation
Append first_buffer_line, last_buffer_line, and buffer_line_count parameters to the draw JSON-RPC method. This enables alternative frontends to implement scroll bars, minimap indicators, and other viewport-aware UI elements without reverse-engineering buffer position from display content. The values are sourced from: - first_buffer_line: window.last_display_setup().first_line (post-ensure_cursor_visible, accounts for scrolloff) - last_buffer_line: display_buffer.lines().back().range().begin.line (reflects actual last visible line after highlighter transforms) - buffer_line_count: context.buffer().line_count() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix two issues in the test update: 1. Python regex replacement produced }\' instead of }' at end of draw message lines (72 files, 80 occurrences) 2. Inferred viewport values were wrong for 7 tests involving replace-ranges, word-wrap, scrolling, and multi-line buffers All 656 tests now pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Append
first_buffer_line,last_buffer_line, andbuffer_line_countparameters to thedrawJSON-RPC method, enabling alternative frontends to implement scroll bars, minimap indicators, and other viewport-aware UI elements.This is the viewport information subset extracted from the scroll bar PR (#5304), proposed as an independent protocol extension that benefits all JSON UI consumers regardless of whether a built-in scroll bar is added.
Motivation
Alternative frontends (e.g. Kasane) currently cannot determine the buffer position corresponding to the displayed viewport. The information needed — which buffer lines are visible and how many total lines exist — is available inside Kakoune but not exposed through the JSON-RPC protocol. Without these values, features like scroll bars, minimap position indicators, and viewport-relative overlays require fragile heuristics that break with word-wrap, replace-ranges, and folding.
Implementation
New parameters (appended to existing
drawpositional params):first_buffer_lineint(0-based)window.last_display_setup().first_linelast_buffer_lineint(0-based)display_buffer.lines().back().range().begin.linebuffer_line_countintcontext.buffer().line_count()Data source rationale:
first_buffer_lineuseslast_display_setup().first_linerather thandisplay_buffer.range().begin.linebecause the latter is computed before highlighter passes and becomes stale after wrap/trim/erase operations.last_buffer_lineuses the last display line's range begin, which is updated bycompute_range()duringtrim_fromand reflects the actual last visible buffer line after all highlighter transforms.Files changed:
src/user_interface.hh— Added 3LineCountparams todraw()virtual interfacesrc/client.cc— Extract and pass viewport values from correct sourcessrc/json_ui.cc/hh— Addedto_json(LineCount)overload; updated draw signature andrpc_callsrc/terminal_ui.cc/hh— Updated signature (values unused, unnamed params)src/remote.cc— Updated signature;send_message/template dispatch handles serialization automaticallysrc/main.cc— DummyUI draw override updateddoc/json_ui.asciidoc— Protocol documentation updatedBackward compatibility: Existing JSON UI consumers that don't parse trailing positional parameters are unaffected. This follows the same "append to end" pattern established by
widget_columns(#5455) anddraw_statusstyle (#5458).Test plan
makebuilds with zero new warningsdrawmessages updated with correct viewport valuesmake testpasses (656 tests, 0 failures)kak -ui jsonemits correct viewport values with word-wrap, replace-ranges, and large buffersDiscussed in #5304 (comment)