-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow vscode sync viewport with neovim #919
Merged
theol0403
merged 12 commits into
vscode-neovim:master
from
windwp:feat_scroll_neovim_viewport
Jul 31, 2022
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
26ffd10
try to make scroll working
d88a3d2
fix outline move and increase viewport 2
039a913
fix gd jump and add ViewportHeightExtend optional
5850dfd
Merge remote-tracking branch 'vscode-neovim/master' into feat_scroll_…
theol0403 7260ae8
feat: move scrolling to viewport
theol0403 2cb7fc6
feat: fix range bug
theol0403 3e7d3e6
fact: clean up code
theol0403 119cd3f
feat: change extend default from 3 to 1
theol0403 f29ca16
feat: check scroll on all cursor moves
theol0403 94aebcf
Merge branch 'master' into feat_scroll_neovim_viewport
theol0403 6b4210f
feat: fix tests
theol0403 53b6ae9
feat: hardcode initial height
theol0403 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local M = {} | ||
|
||
---call from vscode to sync viewport with neovim | ||
---@param vscode_topline number the top line of vscode visible range | ||
---@param vscode_endline number the end line of vscode visible range | ||
M.scroll_viewport = function(vscode_topline, vscode_endline) | ||
local scrolloff = vim.wo.scrolloff ~= -1 and vim.wo.scrolloff or vim.o.scrolloff | ||
local current_height = vim.api.nvim_win_get_height(0) | ||
local new_height = vscode_endline - vscode_topline + scrolloff * 2 + 2 | ||
|
||
-- resize height | ||
if current_height ~= new_height then | ||
vim.api.nvim_win_set_height(0, new_height) | ||
end | ||
|
||
local top_line = vim.fn.line('w0') | ||
local diff = top_line - vscode_topline + scrolloff | ||
|
||
if diff ~= 0 and (vscode_topline - scrolloff > 0) then | ||
vim.fn.winrestview({ | ||
topline = vscode_topline - scrolloff, | ||
}) | ||
end | ||
end | ||
|
||
_G.vscode = M | ||
return M |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be expanded to also include visual mode? Why is this check needed?