mirror of
https://github.com/neovim/neovim.git
synced 2025-10-12 12:56:04 +00:00
fix(undotree): sync scroll pos with undo #36117
Problem: when undo in buffer, undotree window is not updated to position of correct node Solution: schedule nvim_win_set_cursor
This commit is contained in:
@@ -264,9 +264,11 @@ local function draw(inbuf, outbuf)
|
|||||||
local curseq_line = buf_apply_graph_lines(tree, graph_lines, outbuf, meta, curseq)
|
local curseq_line = buf_apply_graph_lines(tree, graph_lines, outbuf, meta, curseq)
|
||||||
vim.bo[outbuf].modifiable = false
|
vim.bo[outbuf].modifiable = false
|
||||||
|
|
||||||
if vim.api.nvim_win_is_valid(vim.b[outbuf].nvim_is_undotree) then
|
vim.schedule(function()
|
||||||
vim.api.nvim_win_set_cursor(vim.b[outbuf].nvim_is_undotree, { curseq_line, 0 })
|
if vim.api.nvim_win_is_valid(vim.b[outbuf].nvim_is_undotree) then
|
||||||
end
|
vim.api.nvim_win_set_cursor(vim.b[outbuf].nvim_is_undotree, { curseq_line, 0 })
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
return meta
|
return meta
|
||||||
end
|
end
|
||||||
|
@@ -6,6 +6,7 @@ local eq = t.eq
|
|||||||
local exec = n.exec
|
local exec = n.exec
|
||||||
local api = n.api
|
local api = n.api
|
||||||
local dedent = t.dedent
|
local dedent = t.dedent
|
||||||
|
local Screen = require('test.functional.ui.screen')
|
||||||
|
|
||||||
---@param reverse_tree {[integer]:integer}
|
---@param reverse_tree {[integer]:integer}
|
||||||
local function generate_undo_tree_from_rev(reverse_tree)
|
local function generate_undo_tree_from_rev(reverse_tree)
|
||||||
@@ -80,6 +81,28 @@ describe(':Undotree', function()
|
|||||||
eq('foo', api.nvim_get_current_line())
|
eq('foo', api.nvim_get_current_line())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('sync scroll pos when undo', function()
|
||||||
|
local screen = Screen.new(30, 10)
|
||||||
|
for _ = 1, n.api.nvim_get_option_value('lines', {}) do
|
||||||
|
api.nvim_set_current_line('foo')
|
||||||
|
end
|
||||||
|
exec 'Undotree'
|
||||||
|
exec 'wincmd w'
|
||||||
|
exec 'silent undo'
|
||||||
|
screen:expect([[
|
||||||
|
* 3 │^foo |
|
||||||
|
* 4 │{1:~ }|
|
||||||
|
* 5 │{1:~ }|
|
||||||
|
* 6 │{1:~ }|
|
||||||
|
* 7 │{1:~ }|
|
||||||
|
* 8 │{1:~ }|
|
||||||
|
{21:* 9 }│{1:~ }|
|
||||||
|
* 10 │{1:~ }|
|
||||||
|
{2:<or [-] }{3:[No Name] [+] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
describe('branch+remove is correctly graphed', function()
|
describe('branch+remove is correctly graphed', function()
|
||||||
it('when branching left', function()
|
it('when branching left', function()
|
||||||
generate_undo_tree_from_rev({ 0, 1, 2, 3, 1, 3, 4, 3, 2, 0 })
|
generate_undo_tree_from_rev({ 0, 1, 2, 3, 1, 3, 4, 3, 2, 0 })
|
||||||
|
Reference in New Issue
Block a user