From 0f93d532104affcab22f6915bcf47ef8b3455fdc Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Thu, 16 Nov 2017 07:38:03 -0500 Subject: [PATCH] Implement :edit-command. :edit-command opens the current command line in an editor, and updates the command line if the editor exits successfully. If --run is passed, the command is executed when the editor exits sucessfully. Resolves #2453. --- qutebrowser/mainwindow/statusbar/command.py | 19 ++++++++++++++++++- tests/end2end/features/editor.feature | 8 ++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index 9ca870605..2d45ccb22 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -24,7 +24,7 @@ from PyQt5.QtWidgets import QSizePolicy from qutebrowser.keyinput import modeman, modeparsers from qutebrowser.commands import cmdexc, cmdutils -from qutebrowser.misc import cmdhistory +from qutebrowser.misc import cmdhistory, editor from qutebrowser.misc import miscwidgets as misc from qutebrowser.utils import usertypes, log, objreg @@ -166,6 +166,23 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): modeman.leave(self._win_id, usertypes.KeyMode.command, 'cmd accept') self.got_cmd[str].emit(prefixes[text[0]] + text[1:]) + @cmdutils.register(instance='status-command', scope='window', maxsplit=0) + def edit_command(self, run=False): + """Open an editor to modify the current command. + + Args: + run: Run the command if the editor exits successfully. + """ + ed = editor.ExternalEditor(parent=self) + + def callback(text): + self.set_cmd_text(text) + if run: + self.got_cmd[str].emit(text) + + ed.editing_finished.connect(callback) + ed.edit(self.text()) + @pyqtSlot(usertypes.KeyMode) def on_mode_left(self, mode): """Clear up when command mode was left. diff --git a/tests/end2end/features/editor.feature b/tests/end2end/features/editor.feature index d3c634b0d..21df30b4d 100644 --- a/tests/end2end/features/editor.feature +++ b/tests/end2end/features/editor.feature @@ -141,3 +141,11 @@ Feature: Opening external editors And I wait for "Read back: bar" in the log And I run :click-element id qute-button Then the javascript message "text: bar" should be logged + + ## :edit-command + + Scenario: Edit a command and run it + When I run :set-cmd-text :message-info foo + And I set up a fake editor replacing "foo" by "bar" + And I run :edit-command --run + Then the message "bar" should be shown