From c21ae0b65155123d5d1cbae78ef588cbe10c505d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 22 Apr 2015 07:13:56 +0200 Subject: [PATCH] Add a :debug-webaction command. --- doc/help/commands.asciidoc | 15 +++++++++++++++ qutebrowser/browser/commands.py | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index d6340b35a..491e9ac10 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -947,6 +947,7 @@ These commands are mainly intended for debugging. They are hidden if qutebrowser |<>|Crash for debugging purposes. |<>|Evaluate a python string and display the results as a web page. |<>|Trace executed code via hunter. +|<>|Execute a webaction. |============== [[debug-all-objects]] === debug-all-objects @@ -995,3 +996,17 @@ Trace executed code via hunter. * This command does not split arguments after the last argument and handles quotes literally. * With this command, +;;+ is interpreted literally instead of splitting off a second command. +[[debug-webaction]] +=== debug-webaction +Syntax: +:debug-webaction 'action'+ + +Execute a webaction. + +See http://doc.qt.io/qt-5/qwebpage.html#WebAction-enum for the available actions. + +==== positional arguments +* +'action'+: The action to execute, e.g. MoveToNextChar. + +==== count +How many times to repeat the action. + diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 04408cdcf..2cc30e668 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1150,3 +1150,23 @@ class CommandDispatcher: flags |= QWebPage.FindBackward for _ in range(count): view.search(view.search_text, flags) + + @cmdutils.register(instance='command-dispatcher', scope='window', + count='count', debug=True) + def debug_webaction(self, action, count=1): + """Execute a webaction. + + See http://doc.qt.io/qt-5/qwebpage.html#WebAction-enum for the + available actions. + + Args: + action: The action to execute, e.g. MoveToNextChar. + count: How many times to repeat the action. + """ + member = getattr(QWebPage, action, None) + if not isinstance(member, QWebPage.WebAction): + raise cmdexc.CommandError("{} is not a valid web action!".format( + acction)) + view = self._current_widget() + for _ in range(count): + view.triggerPageAction(member)