Repository: qutebrowser/qutebrowser

Issue:
Add setting to allow navigation in pinned tabs
I should be able to open any url in a pinned tab as long as it's on the same domain.


Discussion:
I actually prefer the current behaviour.
Or maybe introduce a different type of pin: pin url vs pin a tab.
In one you are explicitly saying "i want this tab to stay on this url", in the other you just want to pin a tab regardless of its current url.

Benoit Giannangeli writes:

> Or maybe introduce a different type of pin: pin url vs pin a tab.
> In one you are explicitly saying "i want this tab to stay on this url", in the other you just want to pin a tab regardless of its current url.

Would a global "pinned.tab.frozen" setting defaulting to true work for you? I
think that would be the simplest way to implement this. Having two commands
would be a lot of work for (I'm assuming) not a lot of people's benefit, and
can lead to confusion.

Ie: you want pinned tabs for their shrinking alone right?

Yes a flag like that would be great.
The code for this is in browser/commands.py:openurl, and I think it should be
fairly trivial (maybe even with a third setting for allowing only same domain,
but simpler is better). If no one takes it, I'll do it at some point.

>                 curtab = self._cntwidget(count)
>                 if curtab is None:
>                     if count is None:
>                         # We want to open a URL in the current tab, but none
>                         # exists yet.
>                         self._tabbed_browser.tabopen(cur_url)
>                     else:
>                         # Explicit count with a tab that doesn't exist.
>                         return
>                 elif curtab.data.pinned:
>                     message.info("Tab is pinned!")
>                 else:
>                     curtab.openurl(cur_url)

I'd be interested in taking this on. I haven't contributed to qutebrowser before, but I'm interested in doing so.

Adam Ibrahim writes:

> I'd be interested in taking this on. I haven't contributed to qutebrowser before, but I'm interested in doing so.

This is definitely a good starter task (especially without a third per-url
flag).

The code to block navigation on :open in pinned tabs is here, and should be
pretty trivial to modify once you have a config value:

https://github.com/qutebrowser/qutebrowser/blob/060489f1bc5b5a6529bd8e78d80449a4b06dd568/qutebrowser/browser/commands.py#L320

Here's an example of a setting, you should be able to add another one by using
the same formula. If you want to tackle a same-domain setting, you'll need to
make it a string instead of a bool though.

https://github.com/qutebrowser/qutebrowser/blob/060489f1bc5b5a6529bd8e78d80449a4b06dd568/qutebrowser/config/configdata.yml#L1766

Lastly, there are a couple other places where navigation is blocked due to
pinned status. Maybe we can take this opportunity to make some sort of
'navigation_blocked' method so if we want to keep adding new features we only
need to change one place.

https://github.com/qutebrowser/qutebrowser/blob/cbb6ae860c156f061beb4fa597db895983eab440/qutebrowser/components/misccommands.py#L122

Feel free to ask on freenode if you have any questions :)

So prompt and helpful! Thank you for that.

Resolving patch:
diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py
--- a/qutebrowser/browser/browsertab.py
+++ b/qutebrowser/browser/browsertab.py
@@ -943,6 +943,10 @@ def send_event(self, evt: QEvent) -> None:
         evt.posted = True
         QApplication.postEvent(recipient, evt)
 
+    def navigation_blocked(self) -> bool:
+        """Test if navigation is allowed on the current tab."""
+        return self.data.pinned and config.val.tabs.pinned.frozen
+
     @pyqtSlot(QUrl)
     def _on_before_load_started(self, url: QUrl) -> None:
         """Adjust the title if we are going to visit a URL soon."""
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -316,7 +316,7 @@ def openurl(self, url=None, related=False,
                     else:
                         # Explicit count with a tab that doesn't exist.
                         return
-                elif curtab.data.pinned:
+                elif curtab.navigation_blocked():
                     message.info("Tab is pinned!")
                 else:
                     curtab.load_url(cur_url)
diff --git a/qutebrowser/components/misccommands.py b/qutebrowser/components/misccommands.py
--- a/qutebrowser/components/misccommands.py
+++ b/qutebrowser/components/misccommands.py
@@ -118,7 +118,7 @@ def printpage(tab: apitypes.Tab,
 @cmdutils.argument('tab', value=cmdutils.Value.cur_tab)
 def home(tab: apitypes.Tab) -> None:
     """Open main startpage in current tab."""
-    if tab.data.pinned:
+    if tab.navigation_blocked():
         message.info("Tab is pinned!")
     else:
         tab.load_url(config.val.url.start_pages[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
@@ -1289,6 +1289,14 @@ Feature: Tab management
         And the following tabs should be open:
             - data/numbers/1.txt (active) (pinned)
 
+    Scenario: :tab-pin open url with tabs.pinned.frozen = false
+        When I set tabs.pinned.frozen to false
+        And I open data/numbers/1.txt
+        And I run :tab-pin
+        And I open data/numbers/2.txt
+        Then the following tabs should be open:
+            - data/numbers/2.txt (active) (pinned)
+
     Scenario: :home on a pinned tab
         When I open data/numbers/1.txt
         And I run :tab-pin
@@ -1297,6 +1305,16 @@ Feature: Tab management
         And the following tabs should be open:
             - data/numbers/1.txt (active) (pinned)
 
+    Scenario: :home on a pinned tab with tabs.pinned.frozen = false
+        When I set url.start_pages to ["http://localhost:(port)/data/numbers/2.txt"]
+        And I set tabs.pinned.frozen to false
+        And I open data/numbers/1.txt
+        And I run :tab-pin
+        And I run :home
+        Then data/numbers/2.txt should be loaded
+        And the following tabs should be open:
+            - data/numbers/2.txt (active) (pinned)
+
     Scenario: Cloning a pinned tab
         When I open data/numbers/1.txt
         And I run :tab-pin