Repository: qutebrowser/qutebrowser

Issue:
support follow-selected with <tab> selection
Version info http://paste.the-compiler.org/view/0a29b429

follow-selected doesn't work for me in normal mode.

I don't know if you recall us talking in IRC months ago about this, but my Return key had never worked on selected links/buttons etc. so I ended up unbinding it to get it to work for that.

Well it looks like the problem is that follow-selected doesn't work for me. If I select a link via Tab and then type :follow-selected nothing happens at all.

Log attached containing the output after using :follow-selected. If you need more let me know.
[debug-2018-05-21.log](https://github.com/qutebrowser/qutebrowser/files/2021039/debug-2018-05-21.log)



Discussion:
If you select the text with "blue selection" (ie the mosue or caret mode), and then run `:follow-selected`, does it work then?
Actually, from the debug log, it looks like you are selecting the text with blue selection (is that correct)?

Does it work with the "orange selection" (the selection created when searching)?
I'm selecting just by hitting Tab in normal mode until a link is highlighted. I tried in caret mode, but that's a different bug - I can't see the cursor in caret mode :)

Using search to highlight text works though.
How can I change my subscription email address? I want to first 
unsubscribe and then subscribe using another email address. Thanks!


On 21/05/2018 11:34, Slackhead wrote:
>
> I'm selecting just by hitting Tab in normal mode until a link is 
> highlighted. I tried in caret mode, but that's a different bug - I 
> can't see the cursor in caret mode :)
>
> Using search to highlight text works though.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub 
> <https://github.com/qutebrowser/qutebrowser/issues/3935#issuecomment-390544340>, 
> or mute the thread 
> <https://github.com/notifications/unsubscribe-auth/Ac1K7QP7WCXPiShDyN07InjhBNZqgHrJks5t0jXHgaJpZM4UGWwr>.
>


Why are you asking this in my issue thread???

Click on your profile icon and use the help link at the top.
ah, that makes a lot more sense, `:follow-selected` dosen't support that method of "selection" currently, it only considers it when a search is being performed. You can use `:fake-key <enter>` as a substitute in the meantime, but I think it may be possible to add this feature so `:follow-selected` works more reliably. 

I'm guessing it could be a hierarchy, the easiest to implement would be:

1. If searching, click on search result
2. If blue selection exists, click on blue selection
3. If a focused element exists, click on it

@gong-yuan, you can find more information on tweaking notification emails here:

https://help.github.com/articles/choosing-the-delivery-method-for-your-notifications/

Resolving patch:
diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py
--- a/qutebrowser/browser/webengine/webenginetab.py
+++ b/qutebrowser/browser/webengine/webenginetab.py
@@ -335,6 +335,13 @@ def _follow_selected_cb(self, js_elem, tab=False):
         """
         if js_elem is None:
             return
+        if js_elem == "focused":
+            # we had a focused element, not a selected one. Just send <enter>
+            if tab:
+                self._tab.key_press(Qt.Key_Enter, modifier=Qt.ControlModifier)
+            else:
+                self._tab.key_press(Qt.Key_Enter)
+
         assert isinstance(js_elem, dict), js_elem
         elem = webengineelem.WebEngineElement(js_elem, tab=self._tab)
         if tab:
@@ -364,7 +371,8 @@ def follow_selected(self, *, tab=False):
 
         else:
             # click an existing blue selection
-            js_code = javascript.assemble('webelem', 'find_selected_link')
+            js_code = javascript.assemble('webelem',
+                                          'find_selected_focused_link')
             self._tab.run_js_async(js_code, lambda jsret:
                                    self._follow_selected_cb(jsret, tab))
 
diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py
--- a/qutebrowser/browser/webkit/webkittab.py
+++ b/qutebrowser/browser/webkit/webkittab.py
@@ -377,11 +377,26 @@ def follow_selected(self, *, tab=False):
                 QWebSettings.JavascriptEnabled):
             if tab:
                 self._tab.data.override_target = usertypes.ClickTarget.tab
-            self._tab.run_js_async(
-                'window.getSelection().anchorNode.parentNode.click()')
+            self._tab.run_js_async("""
+                const aElm = document.activeElement;
+                if (window.getSelection().anchorNode) {
+                    window.getSelection().anchorNode.parentNode.click();
+                } else if (aElm && aElm !== document.body) {
+                    aElm.click();
+                }
+            """)
         else:
             selection = self._widget.selectedHtml()
             if not selection:
+                # Getting here may mean we crashed, but we can't do anything
+                # about that until this commit is released:
+                # https://github.com/annulen/webkit/commit/0e75f3272d149bc64899c161f150eb341a2417af
+                # TODO find a way to check if something is focused
+                if tab:
+                    self._tab.key_press(Qt.Key_Enter,
+                                        modifier=Qt.ControlModifier)
+                else:
+                    self._tab.key_press(Qt.Key_Enter)
                 return
             try:
                 selected_element = xml.etree.ElementTree.fromstring(


Test patch:
diff --git a/tests/end2end/features/caret.feature b/tests/end2end/features/caret.feature
--- a/tests/end2end/features/caret.feature
+++ b/tests/end2end/features/caret.feature
@@ -321,6 +321,38 @@ Feature: Caret mode
             - data/caret.html
             - data/hello.txt (active)
 
+    Scenario: :follow-selected with link tabbing (without JS)
+        When I set content.javascript.enabled to false
+        And I run :leave-mode
+        And I run :jseval document.activeElement.blur();
+        And I run :fake-key <tab>
+        And I run :follow-selected
+        Then data/hello.txt should be loaded
+
+    Scenario: :follow-selected with link tabbing (with JS)
+        When I set content.javascript.enabled to true
+        And I run :leave-mode
+        And I run :jseval document.activeElement.blur();
+        And I run :fake-key <tab>
+        And I run :follow-selected
+        Then data/hello.txt should be loaded
+
+    Scenario: :follow-selected with link tabbing in a tab (without JS)
+        When I set content.javascript.enabled to false
+        And I run :leave-mode
+        And I run :jseval document.activeElement.blur();
+        And I run :fake-key <tab>
+        And I run :follow-selected --tab
+        Then data/hello.txt should be loaded
+
+    Scenario: :follow-selected with link tabbing in a tab (with JS)
+        When I set content.javascript.enabled to true
+        And I run :leave-mode
+        And I run :jseval document.activeElement.blur();
+        And I run :fake-key <tab>
+        And I run :follow-selected --tab
+        Then data/hello.txt should be loaded
+
     # Search + caret mode
 
     # https://bugreports.qt.io/browse/QTBUG-60673