@@ -433,7 +433,7 @@ M.rebuild_discussion_tree = function()
433433 return
434434 end
435435
436- local current_node = discussions_tree .get_node_at_cursor (M .split . winid , M .linked_bufnr , M . discussion_tree )
436+ local current_node = discussions_tree .get_node_at_cursor (M .discussion_tree , M .last_node_at_cursor )
437437
438438 local expanded_node_ids = M .gather_expanded_node_ids (M .discussion_tree )
439439 common .switch_can_edit_bufs (true , M .linked_bufnr , M .unlinked_bufnr )
@@ -472,8 +472,7 @@ M.rebuild_unlinked_discussion_tree = function()
472472 return
473473 end
474474
475- -- save current node for restoring cursor position
476- local current_node = discussions_tree .get_node_at_cursor (M .split .winid , M .unlinked_bufnr , M .unlinked_discussion_tree )
475+ local current_node = discussions_tree .get_node_at_cursor (M .unlinked_discussion_tree , M .last_node_at_cursor )
477476
478477 local expanded_node_ids = M .gather_expanded_node_ids (M .unlinked_discussion_tree )
479478 common .switch_can_edit_bufs (true , M .linked_bufnr , M .unlinked_bufnr )
@@ -545,6 +544,14 @@ M.create_split_and_bufs = function()
545544 buffer = linked_bufnr ,
546545 callback = function ()
547546 M .last_row , M .last_column = unpack (vim .api .nvim_win_get_cursor (0 ))
547+ M .last_node_at_cursor = M .discussion_tree and M .discussion_tree :get_node () or nil
548+ end ,
549+ })
550+
551+ vim .api .nvim_create_autocmd (" WinLeave" , {
552+ buffer = unlinked_bufnr ,
553+ callback = function ()
554+ M .last_node_at_cursor = M .unlinked_discussion_tree and M .unlinked_discussion_tree :get_node () or nil
548555 end ,
549556 })
550557
0 commit comments