From d5c8e73b147ac8443ae2eb0a42c5f4be45d59bf1 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 16 Jul 2014 06:58:01 +0200 Subject: [PATCH] Use same focus code for insertmode/editor --- qutebrowser/browser/commands.py | 6 ++++-- qutebrowser/test/stubs.py | 4 ++++ qutebrowser/utils/webelem.py | 15 ++++----------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 3332ecf09..b00c80716 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -712,9 +712,11 @@ class CommandDispatcher: """ frame = self._tabs.currentWidget().page().currentFrame() elem = frame.findFirstElement(webelem.SELECTORS[ - webelem.Group.editable_focused]) + webelem.Group.focus]) if elem.isNull(): - raise CommandError("No editable element focused!") + raise CommandError("No element focused!") + if not webelem.is_editable(elem): + raise CommandError("Focused element is not editable!") text = elem.evaluateJavaScript('this.value') self._editor = ExternalEditor(self._tabs) self._editor.editing_finished.connect( diff --git a/qutebrowser/test/stubs.py b/qutebrowser/test/stubs.py index 869351916..668b7aa27 100644 --- a/qutebrowser/test/stubs.py +++ b/qutebrowser/test/stubs.py @@ -107,6 +107,10 @@ class FakeWebElement: self._attributes = attributes self._classes = classes + def toOuterXml(self): + """Imitate toOuterXml.""" + return '' + def styleProperty(self, name, strategy): """Return the CSS style property named name. diff --git a/qutebrowser/utils/webelem.py b/qutebrowser/utils/webelem.py index 6e27c24ce..7a2381c2f 100644 --- a/qutebrowser/utils/webelem.py +++ b/qutebrowser/utils/webelem.py @@ -36,7 +36,7 @@ import qutebrowser.config.config as config Group = enum('all', 'links', 'images', 'editable', 'url', 'prevnext_rel', - 'prevnext', 'editable_focused') + 'prevnext', 'focus') SELECTORS = { @@ -45,19 +45,10 @@ SELECTORS = { '[role=option], [role=button], img'), Group.links: 'a, area, link', Group.images: 'img', - # This doesn't contain all the groups where we should switch to insert mode - # - it is just used when opening the external editor. - Group.editable_focused: ('input[type=text]:focus, ' - 'input[type=email]:focus, ' - 'input[type=url]:focus, ' - 'input[type=tel]:focus, ' - 'input[type=number]:focus, ' - 'input[type=password]:focus, ' - 'input[type=search]:focus, ' - 'textarea:focus'), Group.url: '[src], [href]', Group.prevnext_rel: 'a, area, link, [role=link]', Group.prevnext: 'a, area, button, [role=button]', + Group.focus: '*:focus', } FILTERS = { @@ -208,6 +199,8 @@ def is_editable(elem): True if we should switch to insert mode, False otherwise. """ # Beginnings of div-classes which are actually some kind of editor. + log.misc.debug("Checking if element is editable: {}".format( + elem.toOuterXml())) div_classes = ['CodeMirror', # Javascript editor over a textarea 'kix-'] # Google Docs editor tag = elem.tagName().lower()