diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 385f42e97..4ee5b8d26 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -34,6 +34,8 @@ Added for hints instead of single characters. - New `--all` argument for `:download-cancel` to cancel all running downloads. - New `password_fill` userscript to fill passwords using the `pass` executable. +- New `current` hinting mode which forces opening hints in the current tab + (even with `target="_blank"`) Changed ~~~~~~~ diff --git a/README.asciidoc b/README.asciidoc index 6cb17e248..11c0783b9 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -165,6 +165,7 @@ Contributors, sorted by the number of commits in descending order: * Thorsten Wißmann * Philipp Hansch * Austin Anderson +* Kevin Velghe * Alexey "Averrin" Nabrodov * avk * ZDarian @@ -216,7 +217,6 @@ Contributors, sorted by the number of commits in descending order: * Samuel Loury * Matthias Lisin * Marcel Schilling -* Kevin Velghe * Jean-Christophe Petkovich * Helen Sherwood-Taylor * HalosGhost diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index ae7b597d3..d3819741e 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -290,7 +290,8 @@ Start hinting. * +'target'+: What to do with the selected element. - - `normal`: Open the link in the current tab. + - `normal`: Open the link. + - `current`: Open the link in the current tab. - `tab`: Open the link in a new tab (honoring the background-tabs setting). - `tab-fg`: Open the link in a new foreground tab. diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 26fd02fbc..3b71c0266 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -42,10 +42,10 @@ from qutebrowser.misc import guiprocess ElemTuple = collections.namedtuple('ElemTuple', ['elem', 'label']) -Target = usertypes.enum('Target', ['normal', 'tab', 'tab_fg', 'tab_bg', - 'window', 'yank', 'yank_primary', 'run', - 'fill', 'hover', 'download', 'userscript', - 'spawn']) +Target = usertypes.enum('Target', ['normal', 'current', 'tab', 'tab_fg', + 'tab_bg', 'window', 'yank', 'yank_primary', + 'run', 'fill', 'hover', 'download', + 'userscript', 'spawn']) class WordHintingError(Exception): @@ -71,7 +71,8 @@ class HintContext: elems: A mapping from key strings to (elem, label) namedtuples. baseurl: The URL of the current page. target: What to do with the opened links. - normal/tab/tab_fg/tab_bg/window: Get passed to BrowserTab. + normal/current/tab/tab_fg/tab_bg/window: Get passed to + BrowserTab. yank/yank_primary: Yank to clipboard/primary selection. run: Run a command. fill: Fill commandline with link. @@ -128,6 +129,7 @@ class HintManager(QObject): HINT_TEXTS = { Target.normal: "Follow hint", + Target.current: "Follow hint in current tab", Target.tab: "Follow hint in new tab", Target.tab_fg: "Follow hint in foreground tab", Target.tab_bg: "Follow hint in background tab", @@ -429,6 +431,7 @@ class HintManager(QObject): """ target_mapping = { Target.normal: usertypes.ClickTarget.normal, + Target.current: usertypes.ClickTarget.normal, Target.tab_fg: usertypes.ClickTarget.tab, Target.tab_bg: usertypes.ClickTarget.tab_bg, Target.window: usertypes.ClickTarget.window, @@ -463,6 +466,8 @@ class HintManager(QObject): QMouseEvent(QEvent.MouseButtonRelease, pos, Qt.LeftButton, Qt.NoButton, modifiers), ] + if context.target == Target.current: + elem.remove_blank_target() for evt in events: self.mouse_event.emit(evt) if elem.is_text_input() and elem.is_editable(): @@ -741,7 +746,8 @@ class HintManager(QObject): target: What to do with the selected element. - - `normal`: Open the link in the current tab. + - `normal`: Open the link. + - `current`: Open the link in the current tab. - `tab`: Open the link in a new tab (honoring the background-tabs setting). - `tab-fg`: Open the link in a new foreground tab. @@ -891,6 +897,7 @@ class HintManager(QObject): # Handlers which take a QWebElement elem_handlers = { Target.normal: self._click, + Target.current: self._click, Target.tab: self._click, Target.tab_fg: self._click, Target.tab_bg: self._click, diff --git a/qutebrowser/browser/webelem.py b/qutebrowser/browser/webelem.py index 49f4bfc27..df481b98c 100644 --- a/qutebrowser/browser/webelem.py +++ b/qutebrowser/browser/webelem.py @@ -285,6 +285,19 @@ class WebElementWrapper(collections.abc.MutableMapping): tag = self._elem.tagName().lower() return self.get('role', None) in roles or tag in ('input', 'textarea') + def remove_blank_target(self): + """Remove target from link.""" + elem = self._elem + for _ in range(5): + if elem is None: + break + tag = elem.tagName().lower() + if tag == 'a' or tag == 'area': + if elem.attribute('target') == '_blank': + elem.setAttribute('target', '_top') + break + elem = elem.parent() + def debug_text(self): """Get a text based on an element suitable for debug output.""" self._check_vanished() diff --git a/tests/integration/data/hints/link_blank.html b/tests/integration/data/hints/link_blank.html new file mode 100644 index 000000000..f738e61dc --- /dev/null +++ b/tests/integration/data/hints/link_blank.html @@ -0,0 +1,10 @@ + + +
+ +