summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2022-08-22 11:43:49 +0200
committerFlorian Bruhin <me@the-compiler.org>2022-08-22 11:44:31 +0200
commit3f875e3b275eea07404b08f405121b087e6c0575 (patch)
tree59e82484cc7b85c31f9ce4ba35df9daa92c56ad7
parentb8cc8588f534cd9ee4e19f233ea8753bb01e2596 (diff)
downloadqutebrowser-3f875e3b275eea07404b08f405121b087e6c0575.tar.gz
qutebrowser-3f875e3b275eea07404b08f405121b087e6c0575.zip
Add --quiet for :back and :forward
-rw-r--r--doc/changelog.asciidoc2
-rw-r--r--qutebrowser/browser/commands.py53
-rw-r--r--tests/end2end/features/backforward.feature10
3 files changed, 56 insertions, 9 deletions
diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc
index 911c8508c..a30f85dc8 100644
--- a/doc/changelog.asciidoc
+++ b/doc/changelog.asciidoc
@@ -35,6 +35,8 @@ Added
- New `content.javascript.log_message.excludes` setting, which allows to exclude
certain messages from the `content.javascript.log_message.levels` setting
described above.
+- New `--quiet` switch for `:back` and `:forward`, to suppress the error message
+ about already being at beginning/end of history.
- New `qute-1pass` userscript using the 1password commandline to fill
passwords.
- New features in userscripts:
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py
index e6d2af822..b537b05f4 100644
--- a/qutebrowser/browser/commands.py
+++ b/qutebrowser/browser/commands.py
@@ -22,7 +22,7 @@
import os.path
import shlex
import functools
-from typing import cast, Callable, Dict, Union
+from typing import cast, Callable, Dict, Union, Optional
from PyQt5.QtWidgets import QApplication, QTabBar
from PyQt5.QtCore import Qt, QUrl, QEvent, QUrlQuery
@@ -503,14 +503,31 @@ class CommandDispatcher:
add_undo=False,
transfer=True)
- def _back_forward(self, tab, bg, window, count, forward, index=None):
+ def _back_forward(
+ self, *,
+ tab: bool,
+ bg: bool,
+ window: bool,
+ count: Optional[int],
+ forward: bool,
+ quiet: bool,
+ index: Optional[int],
+ ) -> None:
"""Helper function for :back/:forward."""
history = self._current_widget().history
- # Catch common cases before e.g. cloning tab
+ # Catch common cases before e.g. cloning tab, and handle --quiet
if not forward and not history.can_go_back():
- raise cmdutils.CommandError("At beginning of history.")
+ text = "At beginning of history."
+ if quiet:
+ log.webview.debug(text)
+ return
+ raise cmdutils.CommandError(text)
if forward and not history.can_go_forward():
- raise cmdutils.CommandError("At end of history.")
+ text = "At end of history."
+ if quiet:
+ log.webview.debug(text)
+ return
+ raise cmdutils.CommandError(text)
if tab or bg or window:
widget = self.tab_clone(bg, window)
@@ -536,7 +553,7 @@ class CommandDispatcher:
@cmdutils.argument('index', completion=miscmodels.back)
def back(self, tab: bool = False, bg: bool = False,
window: bool = False, count: int = None,
- index: int = None) -> None:
+ index: int = None, quiet: bool = False) -> None:
"""Go back in the history of the current tab.
Args:
@@ -545,15 +562,24 @@ class CommandDispatcher:
window: Go back in a new window.
count: How many pages to go back.
index: Which page to go back to, count takes precedence.
+ quiet: Don't show an error if already at the beginning of history.
"""
- self._back_forward(tab, bg, window, count, forward=False, index=index)
+ self._back_forward(
+ tab=tab,
+ bg=bg,
+ window=window,
+ count=count,
+ forward=False,
+ index=index,
+ quiet=quiet,
+ )
@cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('count', value=cmdutils.Value.count)
@cmdutils.argument('index', completion=miscmodels.forward)
def forward(self, tab: bool = False, bg: bool = False,
window: bool = False, count: int = None,
- index: int = None) -> None:
+ index: int = None, quiet: bool = False) -> None:
"""Go forward in the history of the current tab.
Args:
@@ -562,8 +588,17 @@ class CommandDispatcher:
window: Go forward in a new window.
count: How many pages to go forward.
index: Which page to go forward to, count takes precedence.
+ quiet: Don't show an error if already at the end of history.
"""
- self._back_forward(tab, bg, window, count, forward=True, index=index)
+ self._back_forward(
+ tab=tab,
+ bg=bg,
+ window=window,
+ count=count,
+ forward=True,
+ index=index,
+ quiet=quiet,
+ )
@cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('where', choices=['prev', 'next', 'up', 'increment',
diff --git a/tests/end2end/features/backforward.feature b/tests/end2end/features/backforward.feature
index 4de785517..673910412 100644
--- a/tests/end2end/features/backforward.feature
+++ b/tests/end2end/features/backforward.feature
@@ -137,11 +137,21 @@ Feature: Going back and forward.
When I run :back
Then the error "At beginning of history." should be shown
+ Scenario: Going back without history and --quiet
+ Given I open data/backforward/1.txt
+ When I run :back --quiet
+ Then "At beginning of history." should be logged
+
Scenario: Going forward without history
Given I open data/backforward/1.txt
When I run :forward
Then the error "At end of history." should be shown
+ Scenario: Going forward without history and --quiet
+ Given I open data/backforward/1.txt
+ When I run :forward --quiet
+ Then "At end of history." should be logged
+
@qtwebengine_skip: Getting 'at beginning of history' when going back
Scenario: Going forward too much with count.
Given I open data/backforward/1.txt