From 320b9cac3fd97ab0a99549003993713ce5176e5e Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Thu, 30 Jun 2016 02:22:02 +0200 Subject: [PATCH] Move repeat-command, make it work with multiple modes, improve tests --- qutebrowser/browser/commands.py | 14 -------- qutebrowser/commands/runners.py | 11 +++--- qutebrowser/misc/utilcmds.py | 16 +++++++++ tests/end2end/features/misc.feature | 23 +++++++++++++ tests/end2end/features/repeatcommand.feature | 34 ------------------- tests/end2end/features/test_misc_bdd.py | 1 + .../features/test_repeatcommand_bbd.py | 21 ------------ 7 files changed, 47 insertions(+), 73 deletions(-) delete mode 100644 tests/end2end/features/repeatcommand.feature delete mode 100644 tests/end2end/features/test_repeatcommand_bbd.py diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index f3d1f2a85..eb2f31575 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1972,17 +1972,3 @@ class CommandDispatcher: key: mark identifier; capital indicates a global mark """ self._tabbed_browser.jump_mark(key) - - @cmdutils.register(instance='command-dispatcher', scope='window') - @cmdutils.argument('count', count=True) - def repeat_command(self, count=None): - """Repeat the last executed command, like '.' in vi. - - Args: - count: Which numeric argument to give the command. - """ - if runners.last_command is None: - raise cmdexc.CommandError("You didn't do anything yet.") - runners.CommandRunner(self._win_id).run( - runners.last_command[0], - count if count is not None else runners.last_command[1]) diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index 4fc80f630..b9ab0b6c4 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -32,7 +32,7 @@ from qutebrowser.misc import split ParseResult = collections.namedtuple('ParseResult', ['cmd', 'args', 'cmdline', 'count']) -last_command = None +last_command = {} def _current_url(tabbed_browser): @@ -286,11 +286,14 @@ class CommandRunner(QObject): else: result.cmd.run(self._win_id, args) + mode_manager = objreg.get('mode-manager', scope='window', + window=self._win_id) if (result.cmdline[0] != 'repeat-command' and - result.cmd.mode_allowed(usertypes.KeyMode.normal)): + result.cmd.mode_allowed(mode_manager.mode)): global last_command - last_command = (self._parse_count(text)[1], - count if count is not None else result.count) + last_command[mode_manager.mode] = ( + self._parse_count(text)[1], + count if count is not None else result.count) @pyqtSlot(str, int) @pyqtSlot(str) diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index 1de004c90..9996913e5 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -217,3 +217,19 @@ def debug_set_fake_clipboard(s=None): utils.log_clipboard = True else: utils.fake_clipboard = s + +@cmdutils.register() +@cmdutils.argument('win_id', win_id=True) +@cmdutils.argument('count', count=True) +def repeat_command(win_id, count=None): + """Repeat the last executed command, like '.' in vi. + Args: + count: Which numeric argument to give the command. + """ + mode_manager = objreg.get('mode-manager', scope='window', + window=win_id) + if mode_manager.mode not in runners.last_command: + raise cmdexc.CommandError("You didn't do anything yet.") + cmd = runners.last_command[mode_manager.mode] + commandrunner = runners.CommandRunner(win_id) + commandrunner.run(cmd[0], count if count is not None else cmd[1]) diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index bd54960bd..e11d87121 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -464,3 +464,26 @@ Feature: Various utility commands. And I wait until cookies is loaded And I open cookies in a new tab Then the cookie qute-test should be set to 42 + + Scenario: :repeat-command + Given I open data/scroll.html + When I run :scroll down + And I run :repeat-command + And I run :scroll up + Then the page should be scrolled vertically + + Scenario: :repeat-command with count + Given I open data/scroll.html + When I run :scroll down with count 3 + And I run :scroll up + And I run :repeat-command with count 2 + Then the page should not be scrolled + + Scenario: :repeat-command with not-normal command inbetween + Given I open data/scroll.html + When I run :scroll down with count 3 + And I run :scroll up + And I run :prompt-accept + And I run :repeat-command with count 2 + Then the page should not be scrolled + And the error "prompt-accept: This command is only allowed in prompt/yesno mode." should be shown diff --git a/tests/end2end/features/repeatcommand.feature b/tests/end2end/features/repeatcommand.feature deleted file mode 100644 index 1e8cc83ff..000000000 --- a/tests/end2end/features/repeatcommand.feature +++ /dev/null @@ -1,34 +0,0 @@ -Feature: Repeating - Test the repeat-command command. - - Background: - Given I run :tab-only - - Scenario: :repeat-command - When I open data/numbers/1.txt - And I open data/numbers/2.txt in a new tab - And I open data/numbers/3.txt in a new tab - And I run :tab-close with count 1 - And I run :repeat-command - Then the following tabs should be open: - - data/numbers/3.txt (active) - - Scenario: :repeat-command with count - When I open data/numbers/1.txt - And I open data/numbers/2.txt in a new tab - And I open data/numbers/3.txt in a new tab - And I run :tab-close with count 1 - And I run :repeat-command with count 2 - Then the following tabs should be open: - - data/numbers/2.txt (active) - - Scenario: :repeat-command with not-normal command inbetween - When I open data/numbers/1.txt - And I open data/numbers/2.txt in a new tab - And I open data/numbers/3.txt in a new tab - And I run :tab-close with count 1 - And I run :prompt-accept - And I run :repeat-command - Then the following tabs should be open: - - data/numbers/3.txt (active) - And the error "prompt-accept: This command is only allowed in prompt/yesno mode." should be shown diff --git a/tests/end2end/features/test_misc_bdd.py b/tests/end2end/features/test_misc_bdd.py index 443583166..03c1f0ff1 100644 --- a/tests/end2end/features/test_misc_bdd.py +++ b/tests/end2end/features/test_misc_bdd.py @@ -29,6 +29,7 @@ import qutebrowser from qutebrowser.utils import docutils from qutebrowser.browser import pdfjs +from end2end.features.test_scroll_bdd import check_scrolled, check_not_scrolled bdd.scenarios('misc.feature') diff --git a/tests/end2end/features/test_repeatcommand_bbd.py b/tests/end2end/features/test_repeatcommand_bbd.py deleted file mode 100644 index d6c063ade..000000000 --- a/tests/end2end/features/test_repeatcommand_bbd.py +++ /dev/null @@ -1,21 +0,0 @@ -# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: - -# Copyright 2016 Jan Verbeek (blyxxyz) -# -# This file is part of qutebrowser. -# -# qutebrowser is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# qutebrowser is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with qutebrowser. If not, see . - -import pytest_bdd as bdd -bdd.scenarios('repeatcommand.feature')