Add current hint target
This commit is contained in:
parent
76935291c0
commit
201739a7e6
@ -42,10 +42,10 @@ from qutebrowser.misc import guiprocess
|
|||||||
ElemTuple = collections.namedtuple('ElemTuple', ['elem', 'label'])
|
ElemTuple = collections.namedtuple('ElemTuple', ['elem', 'label'])
|
||||||
|
|
||||||
|
|
||||||
Target = usertypes.enum('Target', ['normal', 'tab', 'tab_fg', 'tab_bg',
|
Target = usertypes.enum('Target', ['normal', 'current', 'tab', 'tab_fg',
|
||||||
'window', 'yank', 'yank_primary', 'run',
|
'tab_bg', 'window', 'yank', 'yank_primary',
|
||||||
'fill', 'hover', 'download', 'userscript',
|
'run', 'fill', 'hover', 'download',
|
||||||
'spawn'])
|
'userscript', 'spawn'])
|
||||||
|
|
||||||
|
|
||||||
class WordHintingError(Exception):
|
class WordHintingError(Exception):
|
||||||
@ -71,7 +71,7 @@ class HintContext:
|
|||||||
elems: A mapping from key strings to (elem, label) namedtuples.
|
elems: A mapping from key strings to (elem, label) namedtuples.
|
||||||
baseurl: The URL of the current page.
|
baseurl: The URL of the current page.
|
||||||
target: What to do with the opened links.
|
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.
|
yank/yank_primary: Yank to clipboard/primary selection.
|
||||||
run: Run a command.
|
run: Run a command.
|
||||||
fill: Fill commandline with link.
|
fill: Fill commandline with link.
|
||||||
@ -128,6 +128,7 @@ class HintManager(QObject):
|
|||||||
|
|
||||||
HINT_TEXTS = {
|
HINT_TEXTS = {
|
||||||
Target.normal: "Follow hint",
|
Target.normal: "Follow hint",
|
||||||
|
Target.current: "Follow hint in current tab",
|
||||||
Target.tab: "Follow hint in new tab",
|
Target.tab: "Follow hint in new tab",
|
||||||
Target.tab_fg: "Follow hint in foreground tab",
|
Target.tab_fg: "Follow hint in foreground tab",
|
||||||
Target.tab_bg: "Follow hint in background tab",
|
Target.tab_bg: "Follow hint in background tab",
|
||||||
@ -429,6 +430,7 @@ class HintManager(QObject):
|
|||||||
"""
|
"""
|
||||||
target_mapping = {
|
target_mapping = {
|
||||||
Target.normal: usertypes.ClickTarget.normal,
|
Target.normal: usertypes.ClickTarget.normal,
|
||||||
|
Target.current: usertypes.ClickTarget.normal,
|
||||||
Target.tab_fg: usertypes.ClickTarget.tab,
|
Target.tab_fg: usertypes.ClickTarget.tab,
|
||||||
Target.tab_bg: usertypes.ClickTarget.tab_bg,
|
Target.tab_bg: usertypes.ClickTarget.tab_bg,
|
||||||
Target.window: usertypes.ClickTarget.window,
|
Target.window: usertypes.ClickTarget.window,
|
||||||
@ -463,6 +465,7 @@ class HintManager(QObject):
|
|||||||
QMouseEvent(QEvent.MouseButtonRelease, pos, Qt.LeftButton,
|
QMouseEvent(QEvent.MouseButtonRelease, pos, Qt.LeftButton,
|
||||||
Qt.NoButton, modifiers),
|
Qt.NoButton, modifiers),
|
||||||
]
|
]
|
||||||
|
if context.target == Target.current:
|
||||||
elem.remove_target()
|
elem.remove_target()
|
||||||
for evt in events:
|
for evt in events:
|
||||||
self.mouse_event.emit(evt)
|
self.mouse_event.emit(evt)
|
||||||
@ -742,7 +745,8 @@ class HintManager(QObject):
|
|||||||
|
|
||||||
target: What to do with the selected element.
|
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
|
- `tab`: Open the link in a new tab (honoring the
|
||||||
background-tabs setting).
|
background-tabs setting).
|
||||||
- `tab-fg`: Open the link in a new foreground tab.
|
- `tab-fg`: Open the link in a new foreground tab.
|
||||||
@ -892,6 +896,7 @@ class HintManager(QObject):
|
|||||||
# Handlers which take a QWebElement
|
# Handlers which take a QWebElement
|
||||||
elem_handlers = {
|
elem_handlers = {
|
||||||
Target.normal: self._click,
|
Target.normal: self._click,
|
||||||
|
Target.current: self._click,
|
||||||
Target.tab: self._click,
|
Target.tab: self._click,
|
||||||
Target.tab_fg: self._click,
|
Target.tab_fg: self._click,
|
||||||
Target.tab_bg: self._click,
|
Target.tab_bg: self._click,
|
||||||
|
@ -286,7 +286,7 @@ class WebElementWrapper(collections.abc.MutableMapping):
|
|||||||
return self.get('role', None) in roles or tag in ('input', 'textarea')
|
return self.get('role', None) in roles or tag in ('input', 'textarea')
|
||||||
|
|
||||||
def remove_target(self):
|
def remove_target(self):
|
||||||
"""Remove target from link"""
|
"""Remove target from link."""
|
||||||
if self._elem.tagName().lower() == 'a':
|
if self._elem.tagName().lower() == 'a':
|
||||||
self._elem.removeAttribute('target')
|
self._elem.removeAttribute('target')
|
||||||
elif self.parent().tagName().lower() == 'a':
|
elif self.parent().tagName().lower() == 'a':
|
||||||
|
Loading…
Reference in New Issue
Block a user