Repository: qutebrowser/qutebrowser

Issue:
Open tabs directly after current tab
Currently I have both `tabs.new_position.unrelated` and `tabs.new_position.related` set to `next`. With this configuration, new tabs open after the last tab opened from the current tab, but I'd like to have all tabs open directly after the current tab. Is there currently some way to achieve this, or could this be added as an option?



Discussion:
I don't think there's a way to do this currently.

The fix for this is pretty easy, I think (just comment this line):

https://github.com/qutebrowser/qutebrowser/blob/master/qutebrowser/mainwindow/tabbedbrowser.py#L537

However, I'm not sure what an ideal interface for this would be. We could add
a new setting (maybe something about stacking related tabs), or we could make
new options for tabs.new_position.related.

Fox Kiester writes:

> Currently I have both tabs.new_position.unrelated and tabs.new_position.related set to next. With this configuration, new tabs open after the last tab opened from the current tab, but I'd like to have all tabs open directly after the current tab. Is there
> currently some way to achieve this, or could this be added as an option?
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub, or mute the thread.

I think the description for `next` is misleading since it doesn't always open tabs after the current. I think a new option for `tabs.new_position.related` for the current behavior would make sense, but it would break backwards compatibility. I think adding a new setting that determines how `next` behaves and then mentioning it in `tabs.new_position.related` probably makes the most sense.

Resolving patch:
diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py
--- a/qutebrowser/mainwindow/tabbedbrowser.py
+++ b/qutebrowser/mainwindow/tabbedbrowser.py
@@ -526,14 +526,20 @@ def _get_new_tab_idx(self, related):
         else:
             pos = config.val.tabs.new_position.unrelated
         if pos == 'prev':
-            idx = self._tab_insert_idx_left
-            # On first sight, we'd think we have to decrement
-            # self._tab_insert_idx_left here, as we want the next tab to be
-            # *before* the one we just opened. However, since we opened a tab
-            # *before* the currently focused tab, indices will shift by
-            # 1 automatically.
+            if config.val.tabs.new_position.stacking:
+                idx = self._tab_insert_idx_left
+                # On first sight, we'd think we have to decrement
+                # self._tab_insert_idx_left here, as we want the next tab to be
+                # *before* the one we just opened. However, since we opened a
+                # tab *before* the currently focused tab, indices will shift by
+                # 1 automatically.
+            else:
+                idx = self.widget.currentIndex()
         elif pos == 'next':
-            idx = self._tab_insert_idx_right
+            if config.val.tabs.new_position.stacking:
+                idx = self._tab_insert_idx_right
+            else:
+                idx = self.widget.currentIndex() + 1
             self._tab_insert_idx_right += 1
         elif pos == 'first':
             idx = 0


Test patch:
diff --git a/tests/end2end/features/tabs.feature b/tests/end2end/features/tabs.feature
--- a/tests/end2end/features/tabs.feature
+++ b/tests/end2end/features/tabs.feature
@@ -894,6 +894,71 @@ Feature: Tab management
             - about:blank
             - data/hello.txt (active)
 
+    # stacking tabs
+    Scenario: stacking tabs opening tab with tabs.new_position.related next
+        When I set tabs.new_position.related to next
+        And I set tabs.new_position.stacking to true
+        And I set tabs.background to true
+        And I open about:blank
+        And I open data/navigate/index.html in a new tab
+        And I hint with args "all tab-bg" and follow a
+        And I hint with args "all tab-bg" and follow s
+        And I wait until data/navigate/prev.html is loaded
+        And I wait until data/navigate/next.html is loaded
+        Then the following tabs should be open:
+            - about:blank
+            - data/navigate/index.html (active)
+            - data/navigate/prev.html
+            - data/navigate/next.html
+
+    Scenario: stacking tabs opening tab with tabs.new_position.related prev
+        When I set tabs.new_position.related to prev
+        And I set tabs.new_position.stacking to true
+        And I set tabs.background to true
+        And I open about:blank
+        And I open data/navigate/index.html in a new tab
+        And I hint with args "all tab-bg" and follow a
+        And I hint with args "all tab-bg" and follow s
+        And I wait until data/navigate/prev.html is loaded
+        And I wait until data/navigate/next.html is loaded
+        Then the following tabs should be open:
+            - about:blank
+            - data/navigate/next.html
+            - data/navigate/prev.html
+            - data/navigate/index.html (active)
+
+    Scenario: no stacking tabs opening tab with tabs.new_position.related next
+        When I set tabs.new_position.related to next
+        And I set tabs.new_position.stacking to false
+        And I set tabs.background to true
+        And I open about:blank
+        And I open data/navigate/index.html in a new tab
+        And I hint with args "all tab-bg" and follow a
+        And I hint with args "all tab-bg" and follow s
+        And I wait until data/navigate/prev.html is loaded
+        And I wait until data/navigate/next.html is loaded
+        Then the following tabs should be open:
+            - about:blank
+            - data/navigate/index.html (active)
+            - data/navigate/next.html
+            - data/navigate/prev.html
+
+    Scenario: no stacking tabs opening tab with tabs.new_position.related prev
+        When I set tabs.new_position.related to prev
+        And I set tabs.new_position.stacking to false
+        And I set tabs.background to true
+        And I open about:blank
+        And I open data/navigate/index.html in a new tab
+        And I hint with args "all tab-bg" and follow a
+        And I hint with args "all tab-bg" and follow s
+        And I wait until data/navigate/prev.html is loaded
+        And I wait until data/navigate/next.html is loaded
+        Then the following tabs should be open:
+            - about:blank
+            - data/navigate/prev.html
+            - data/navigate/next.html
+            - data/navigate/index.html (active)
+
     # :buffer
 
     Scenario: :buffer without args or count