summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2023-12-27 08:56:16 +1300
committertoofar <toofar@spalge.com>2024-01-06 21:02:33 +1300
commitc2bc549605a3c0bbb67187bbc197bc38f4a3085a (patch)
treedce702ec7627220a0a3fa29f9476dd35848371db
parent96a37b0a61174c09f1c4e7bbccb8da151481316b (diff)
downloadqutebrowser-c2bc549605a3c0bbb67187bbc197bc38f4a3085a.tar.gz
qutebrowser-c2bc549605a3c0bbb67187bbc197bc38f4a3085a.zip
Fix tab-give -r when moving a subtree
Two issues here: 1. transplanted trees could get rendered upside down depending on the value of the tab.new_position.tree.new_child setting, I think. The parent and child attributes of the nodes looked correct but it was being rendered upside down in the tab bar, weird. Anyway, we are adding new tabs at the top level and them setting their parents based on the mapping. We shouldn't be opening them as related to the currently focused tab 2. moving a subtree was crashing because the parent of the top node wasn't in the mapping. Which is fine because that's not being moved over. I changed it to not explicitly change the parent of such nodes (so they remain under the tree root). Two other tidy ups: * the initialization of "uid_map" as it didn't seem to need the 1:1 in there. * remove tabs explicitly in reverse order rather than repeatedly removing the current tab. This avoids re-work in the tree because it does a bunch of stuff to re-parent children if you delete the parent. Also I have debug logging in notree currently warning of children being "orphaned" that was going off TODO items around tab moving: * collapsed state is lost * moved tab isn't focused in destination window (I think that's a thing that happens normally? Could be wrong) * this method might be a bit simpler and consistent with other methods (like undo) if it did more stuff in one go using traverse order to keep things consistent, instead of the map. It seems to work fine as is but not re-using patterns makes it harder to see opportunities for refactoring The structure I was testing with was: 1. one 2. two 3. three 4. four 5. five 1. six Then focusing "three" and `:tab-give -r 1`.
-rw-r--r--qutebrowser/browser/commands.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
index d1a1cf6be..aa720a747 100644
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -498,29 +498,32 @@ class CommandDispatcher:
def _tree_tab_give(self, tabbed_browser, keep):
"""Helper function to simplify tab-give."""
- uid_map = {1: 1}
+ # first pass: open tabs and save the uids of the new nodes
+ uid_map = {} # old_uid -> new_uid
traversed = list(self._current_widget().node.traverse())
- # first pass: open tabs
for node in traversed:
- tab = tabbed_browser.tabopen(node.value.url())
-
+ tab = tabbed_browser.tabopen(
+ node.value.url(),
+ related=False,
+ )
uid_map[node.uid] = tab.node.uid
# second pass: copy tree structure over
newroot = tabbed_browser.widget.tree_root
oldroot = self._tabbed_browser.widget.tree_root
for node in traversed:
- if node.parent is not oldroot:
+ if node.parent.uid in uid_map:
uid = uid_map[node.uid]
new_node = newroot.get_descendent_by_uid(uid)
parent_uid = uid_map[node.parent.uid]
new_parent = newroot.get_descendent_by_uid(parent_uid)
new_node.parent = new_parent
- # third pass: remove tabs from old window
+ # third pass: remove tabs from old window, children first this time to
+ # avoid having to re-parent things when traversing.
if not keep:
- for _node in traversed:
- self._tabbed_browser.close_tab(self._current_widget(),
+ for node in reversed(traversed):
+ self._tabbed_browser.close_tab(node.value,
add_undo=False,
transfer=True)