refactor: replace win_execute string injection in _adjust_scroll - #1
Open
leolaurindo wants to merge 1 commit into
Open
refactor: replace win_execute string injection in _adjust_scroll#1leolaurindo wants to merge 1 commit into
leolaurindo wants to merge 1 commit into
Conversation
…_adjust_scroll
The top-fill and bottom-scroll adjustments previously built Vimscript/Lua
strings at runtime and evaluated them via win_execute, e.g.
'win_execute(winid, "lua vim.fn.winrestview({topfill=...})")'. This is
eval-style and fragile to internal changes.
Replace both with direct vim.api.nvim_win_call calls:
- winrestview({ topfill = count }) for the top case
- vim.cmd.normal(needed .. "\5") for the bottom case
The N<C-e> scroll itself is retained: winrestview topline clamps to the
last buffer line and cannot reveal past-EOF virt_lines, so CTRL-E remains
the only stable mechanism. No behavior change.
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
This is a behavior-preserving refactor of the internal
_adjust_scrollimplementation._adjust_scrollhandles deleted virtual lines at the edges of a buffer:virt_lines_aboveand requiretopfill.The current implementation performs these operations through dynamically constructed Ex-command strings passed to
win_execute.What changed
Before, the top-of-file case built and evaluated Lua source code:
It is now a direct window-scoped function call:
It now uses the documented window-call API:
Why
The previous code constructed executable Lua/Vimscript as strings. That makes the operation:
nvim_win_call()directly expresses the intended operation: execute this function with a specific window as the current window.The CTRL-E bottom scroll is intentionally retained.
winrestview({ topline = ... })clamps at the final buffer line and cannot reveal virtual lines positioned past EOF. The normal-mode scroll remains necessary for that case.User-visible behavior
None intended. This is an internal refactor only.
The existing scroll tests pass unchanged:
Success: 23
Failed: 0
Errors: 0
The combined demo branch containing this and the other proposed changes is available at:
https://github.com/leolaurindo/inline-diff.nvim/tree/dev/all