Improve clipboard exceptions, migrate bindings
This commit is contained in:
parent
96146c55af
commit
38508274e0
@ -818,7 +818,10 @@ class CommandDispatcher:
|
|||||||
force_search = False
|
force_search = False
|
||||||
if not utils.supports_selection():
|
if not utils.supports_selection():
|
||||||
sel = False
|
sel = False
|
||||||
text = utils.get_clipboard(selection=sel)
|
try:
|
||||||
|
text = utils.get_clipboard(selection=sel)
|
||||||
|
except utils.ClipboardEmptyError as e:
|
||||||
|
raise cmdexc.CommandError(e)
|
||||||
text_urls = [u for u in text.split('\n') if u.strip()]
|
text_urls = [u for u in text.split('\n') if u.strip()]
|
||||||
if (len(text_urls) > 1 and not urlutils.is_url(text_urls[0]) and
|
if (len(text_urls) > 1 and not urlutils.is_url(text_urls[0]) and
|
||||||
urlutils.get_path_if_valid(
|
urlutils.get_path_if_valid(
|
||||||
@ -1462,9 +1465,12 @@ class CommandDispatcher:
|
|||||||
raise cmdexc.CommandError("Focused element is not editable!")
|
raise cmdexc.CommandError("Focused element is not editable!")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sel = utils.get_clipboard(selection=True)
|
try:
|
||||||
except utils.SelectionUnsupportedError:
|
sel = utils.get_clipboard(selection=True)
|
||||||
sel = utils.get_clipboard()
|
except utils.SelectionUnsupportedError:
|
||||||
|
sel = utils.get_clipboard()
|
||||||
|
except utils.ClipboardEmptyError:
|
||||||
|
return
|
||||||
|
|
||||||
log.misc.debug("Pasting primary selection into element {}".format(
|
log.misc.debug("Pasting primary selection into element {}".format(
|
||||||
elem.debug_text()))
|
elem.debug_text()))
|
||||||
|
@ -57,10 +57,13 @@ def replace_variables(win_id, arglist):
|
|||||||
QUrl.RemovePassword)
|
QUrl.RemovePassword)
|
||||||
if '{url:pretty}' in arglist:
|
if '{url:pretty}' in arglist:
|
||||||
pretty_url = _current_url(tabbed_browser).toString(QUrl.RemovePassword)
|
pretty_url = _current_url(tabbed_browser).toString(QUrl.RemovePassword)
|
||||||
if '{clipboard}' in arglist:
|
try:
|
||||||
clipboard = utils.get_clipboard()
|
if '{clipboard}' in arglist:
|
||||||
if '{primary}' in arglist:
|
clipboard = utils.get_clipboard()
|
||||||
primary = utils.get_clipboard(selection=True)
|
if '{primary}' in arglist:
|
||||||
|
primary = utils.get_clipboard(selection=True)
|
||||||
|
except utils.ClipboardEmptyError as e:
|
||||||
|
raise cmdexc.CommandError(e)
|
||||||
for arg in arglist:
|
for arg in arglist:
|
||||||
if arg == '{url}':
|
if arg == '{url}':
|
||||||
args.append(url)
|
args.append(url)
|
||||||
|
@ -1677,4 +1677,9 @@ CHANGED_KEY_COMMANDS = [
|
|||||||
(re.compile(r'^download-remove --all$'), r'download-clear'),
|
(re.compile(r'^download-remove --all$'), r'download-clear'),
|
||||||
|
|
||||||
(re.compile(r'^hint links fill "([^"]*)"$'), r'hint links fill \1'),
|
(re.compile(r'^hint links fill "([^"]*)"$'), r'hint links fill \1'),
|
||||||
|
|
||||||
|
(re.compile(r'^paste$'), r'open {clipboard}'),
|
||||||
|
(re.compile(r'^paste -([twb])$'), r'open -\1 {clipboard}'),
|
||||||
|
(re.compile(r'^paste -([twb])s$'), r'open -\1 {primary}'),
|
||||||
|
(re.compile(r'^paste -s([twb])$'), r'open -\1 {primary}'),
|
||||||
]
|
]
|
||||||
|
@ -47,7 +47,8 @@ class MinimalLineEditMixin:
|
|||||||
if e.key() == Qt.Key_Insert and e.modifiers() == Qt.ShiftModifier:
|
if e.key() == Qt.Key_Insert and e.modifiers() == Qt.ShiftModifier:
|
||||||
try:
|
try:
|
||||||
text = utils.get_clipboard(selection=True)
|
text = utils.get_clipboard(selection=True)
|
||||||
except utils.SelectionUnsupportedError:
|
except (utils.SelectionUnsupportedError,
|
||||||
|
utils.ClipboardEmptyError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
e.accept()
|
e.accept()
|
||||||
|
@ -37,7 +37,6 @@ import pkg_resources
|
|||||||
|
|
||||||
import qutebrowser
|
import qutebrowser
|
||||||
from qutebrowser.utils import qtutils, log
|
from qutebrowser.utils import qtutils, log
|
||||||
from qutebrowser.commands import cmdexc
|
|
||||||
|
|
||||||
|
|
||||||
fake_clipboard = None
|
fake_clipboard = None
|
||||||
@ -49,6 +48,11 @@ class SelectionUnsupportedError(Exception):
|
|||||||
"""Raised if [gs]et_clipboard is used and selection=True is unsupported."""
|
"""Raised if [gs]et_clipboard is used and selection=True is unsupported."""
|
||||||
|
|
||||||
|
|
||||||
|
class ClipboardEmptyError(Exception):
|
||||||
|
|
||||||
|
"""Raised if get_clipboard is used and the clipboard is empty."""
|
||||||
|
|
||||||
|
|
||||||
def elide(text, length):
|
def elide(text, length):
|
||||||
"""Elide text so it uses a maximum of length chars."""
|
"""Elide text so it uses a maximum of length chars."""
|
||||||
if length < 1:
|
if length < 1:
|
||||||
@ -813,7 +817,7 @@ def get_clipboard(selection=False):
|
|||||||
|
|
||||||
target = "Primary selection" if selection else "Clipboard"
|
target = "Primary selection" if selection else "Clipboard"
|
||||||
if not data.strip():
|
if not data.strip():
|
||||||
raise cmdexc.CommandError("{} is empty.".format(target))
|
raise ClipboardEmptyError("{} is empty.".format(target))
|
||||||
log.misc.debug("{} contained: {!r}".format(target, data))
|
log.misc.debug("{} contained: {!r}".format(target, data))
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -286,6 +286,10 @@ class TestKeyConfigParser:
|
|||||||
'hint links fill :open {hint-url}'),
|
'hint links fill :open {hint-url}'),
|
||||||
('hint links fill ":open -t {hint-url}"',
|
('hint links fill ":open -t {hint-url}"',
|
||||||
'hint links fill :open -t {hint-url}'),
|
'hint links fill :open -t {hint-url}'),
|
||||||
|
|
||||||
|
('paste', 'open {clipboard}'),
|
||||||
|
('paste -t', 'open -t {clipboard}'),
|
||||||
|
('paste -ws', 'open -w {primary}'),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_migrations(self, old, new_expected):
|
def test_migrations(self, old, new_expected):
|
||||||
|
Loading…
Reference in New Issue
Block a user