Add support for following tab selected elements to :follow-selected
This commit is contained in:
parent
12e0edbcd0
commit
c33a887b2d
@ -364,7 +364,7 @@ class WebEngineCaret(browsertab.AbstractCaret):
|
||||
|
||||
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))
|
||||
|
||||
|
@ -377,8 +377,14 @@ class WebKitCaret(browsertab.AbstractCaret):
|
||||
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:
|
||||
|
@ -243,6 +243,7 @@ window._qutebrowser.webelem = (function() {
|
||||
};
|
||||
|
||||
// Runs a function in a frame until the result is not null, then return
|
||||
// If no frame succeds, return null
|
||||
function run_frames(func) {
|
||||
for (let i = 0; i < window.frames.length; ++i) {
|
||||
const frame = window.frames[i];
|
||||
@ -329,7 +330,8 @@ window._qutebrowser.webelem = (function() {
|
||||
};
|
||||
|
||||
// Function for returning a selection to python (so we can click it)
|
||||
funcs.find_selected_link = () => {
|
||||
// If there is no selection, get the currently focused element.
|
||||
funcs.find_selected_focused_link = () => {
|
||||
const elem = window.getSelection().baseNode;
|
||||
if (elem) {
|
||||
return serialize_elem(elem.parentNode);
|
||||
@ -342,7 +344,12 @@ window._qutebrowser.webelem = (function() {
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return serialized_frame_elem;
|
||||
|
||||
if (serialized_frame_elem) {
|
||||
return serialized_frame_elem;
|
||||
}
|
||||
// No selected element, return focused element
|
||||
return funcs.find_focused();
|
||||
};
|
||||
|
||||
funcs.set_value = (id, value) => {
|
||||
|
@ -321,6 +321,32 @@ Feature: Caret mode
|
||||
- data/caret.html
|
||||
- data/hello.txt (active)
|
||||
|
||||
@qtwebkit_skip: getting focused element not possible without js
|
||||
Scenario: :follow-selected with link tabbing (without JS)
|
||||
When I set content.javascript.enabled to false
|
||||
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 :fake-key <tab>
|
||||
And I run :follow-selected
|
||||
Then data/hello.txt should be loaded
|
||||
|
||||
@qtwebkit_skip: getting focused element not possible without js
|
||||
Scenario: :follow-selected with link tabbing in a tab (without JS)
|
||||
When I set content.javascript.enabled to false
|
||||
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 :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
|
||||
|
Loading…
Reference in New Issue
Block a user