@@ -433,15 +433,7 @@ M.rebuild_discussion_tree = function()
433433 return
434434 end
435435
436- -- save current node for restoring cursor position
437- local current_node
438- if
439- vim .api .nvim_get_current_win () == M .split .winid
440- and vim .api .nvim_get_current_buf () == M .linked_bufnr
441- and M .discussion_tree ~= nil
442- then
443- current_node = M .discussion_tree :get_node ()
444- end
436+ local current_node = discussions_tree .get_node_at_cursor (M .split .winid , M .linked_bufnr , M .discussion_tree )
445437
446438 local expanded_node_ids = M .gather_expanded_node_ids (M .discussion_tree )
447439 common .switch_can_edit_bufs (true , M .linked_bufnr , M .unlinked_bufnr )
@@ -464,11 +456,7 @@ M.rebuild_discussion_tree = function()
464456 tree_utils .open_node_by_id (discussion_tree , id )
465457 end
466458 discussion_tree :render ()
467-
468- if current_node ~= nil then
469- local root_node = common .get_root_node (M .discussion_tree , current_node )
470- discussions_tree .restore_cursor_position (M .split .winid , discussion_tree , current_node , root_node )
471- end
459+ discussions_tree .restore_cursor_position (M .split .winid , discussion_tree , current_node )
472460
473461 M .set_tree_keymaps (discussion_tree , M .linked_bufnr , false )
474462 M .discussion_tree = discussion_tree
@@ -485,14 +473,7 @@ M.rebuild_unlinked_discussion_tree = function()
485473 end
486474
487475 -- save current node for restoring cursor position
488- local current_node
489- if
490- vim .api .nvim_get_current_win () == M .split .winid
491- and vim .api .nvim_get_current_buf () == M .unlinked_bufnr
492- and M .unlinked_discussion_tree ~= nil
493- then
494- current_node = M .unlinked_discussion_tree :get_node ()
495- end
476+ local current_node = discussions_tree .get_node_at_cursor (M .split .winid , M .unlinked_bufnr , M .unlinked_discussion_tree )
496477
497478 local expanded_node_ids = M .gather_expanded_node_ids (M .unlinked_discussion_tree )
498479 common .switch_can_edit_bufs (true , M .linked_bufnr , M .unlinked_bufnr )
@@ -515,11 +496,7 @@ M.rebuild_unlinked_discussion_tree = function()
515496 tree_utils .open_node_by_id (unlinked_discussion_tree , id )
516497 end
517498 unlinked_discussion_tree :render ()
518-
519- if current_node ~= nil then
520- local root_node = common .get_root_node (M .unlinked_discussion_tree , current_node )
521- discussions_tree .restore_cursor_position (M .split .winid , unlinked_discussion_tree , current_node , root_node )
522- end
499+ discussions_tree .restore_cursor_position (M .split .winid , unlinked_discussion_tree , current_node )
523500
524501 M .set_tree_keymaps (unlinked_discussion_tree , M .unlinked_bufnr , true )
525502 M .unlinked_discussion_tree = unlinked_discussion_tree
0 commit comments