diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 4bc9941a8..0c99387b5 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,7 @@ 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 +128,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 +430,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,7 +465,8 @@ class HintManager(QObject): QMouseEvent(QEvent.MouseButtonRelease, pos, Qt.LeftButton, Qt.NoButton, modifiers), ] - elem.remove_target() + if context.target == Target.current: + elem.remove_target() for evt in events: self.mouse_event.emit(evt) if elem.is_text_input() and elem.is_editable(): @@ -742,7 +745,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. @@ -892,6 +896,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 f18bea65a..0f6ae633d 100644 --- a/qutebrowser/browser/webelem.py +++ b/qutebrowser/browser/webelem.py @@ -286,7 +286,7 @@ class WebElementWrapper(collections.abc.MutableMapping): return self.get('role', None) in roles or tag in ('input', 'textarea') def remove_target(self): - """Remove target from link""" + """Remove target from link.""" if self._elem.tagName().lower() == 'a': self._elem.removeAttribute('target') elif self.parent().tagName().lower() == 'a':