diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index b7cb0349b..7da6e543e 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -2960,7 +2960,7 @@ Default: +pass:[false]+ === search.ignore_case When to find text on a page case-insensitively. -Type: <> +Type: <> Valid values: @@ -3624,6 +3624,7 @@ Lists with duplicate flags are invalid. Each item is checked against the valid v |FontFamily|A Qt font family. |FormatString|A string with placeholders. |FuzzyUrl|A URL which gets interpreted as search if needed. +|IgnoreCase|Whether to search case insensitively. |Int|Base class for an integer setting. |Key|A name of a key. |List|A list of values. diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 3b39e52d1..0625b218e 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -297,7 +297,7 @@ class AbstractSearch(QObject): self.text = None # type: typing.Optional[str] self.search_displayed = False - def _is_case_sensitive(self, ignore_case: str) -> bool: + def _is_case_sensitive(self, ignore_case: usertypes.IgnoreCase) -> bool: """Check if case-sensitivity should be used. This assumes self.text is already set properly. @@ -307,21 +307,21 @@ class AbstractSearch(QObject): """ assert self.text is not None mapping = { - 'smart': not self.text.islower(), - 'never': True, - 'always': False, + usertypes.IgnoreCase.smart: not self.text.islower(), + usertypes.IgnoreCase.never: True, + usertypes.IgnoreCase.always: False, } return mapping[ignore_case] def search(self, text: str, *, - ignore_case: str = 'never', + ignore_case: usertypes.IgnoreCase = usertypes.IgnoreCase.never, reverse: bool = False, result_cb: _Callback = None) -> None: """Find the given text on the page. Args: text: The text to search for. - ignore_case: Search case-insensitively. ('always'/'never/'smart') + ignore_case: Search case-insensitively. reverse: Reverse search direction. result_cb: Called with a bool indicating whether a match was found. """ diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 453b36974..fd380abae 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -205,8 +205,8 @@ class WebEngineSearch(browsertab.AbstractSearch): self._widget.findText(text, flags, wrapped_callback) - def search(self, text, *, ignore_case='never', reverse=False, - result_cb=None): + def search(self, text, *, ignore_case=usertypes.IgnoreCase.never, + reverse=False, result_cb=None): # Don't go to next entry on duplicate search if self.text == text and self.search_displayed: log.webview.debug("Ignoring duplicate search request" diff --git a/qutebrowser/browser/webkit/webkittab.py b/qutebrowser/browser/webkit/webkittab.py index 2c7083c25..44dc76f9d 100644 --- a/qutebrowser/browser/webkit/webkittab.py +++ b/qutebrowser/browser/webkit/webkittab.py @@ -125,8 +125,8 @@ class WebKitSearch(browsertab.AbstractSearch): self._widget.findText('') self._widget.findText('', QWebPage.HighlightAllOccurrences) - def search(self, text, *, ignore_case='never', reverse=False, - result_cb=None): + def search(self, text, *, ignore_case=usertypes.IgnoreCase.never, + reverse=False, result_cb=None): # Don't go to next entry on duplicate search if self.text == text and self.search_displayed: log.webview.debug("Ignoring duplicate search request" diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index ff43cc156..bed4d9659 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -39,12 +39,7 @@ ignore_case: renamed: search.ignore_case search.ignore_case: - type: - name: String - valid_values: - - always: Search case-insensitively. - - never: Search case-sensitively. - - smart: Search case-sensitively if there are capital characters. + type: IgnoreCase default: smart desc: When to find text on a page case-insensitively. diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 691584801..c0f3bec9f 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -62,7 +62,8 @@ from PyQt5.QtWidgets import QTabWidget, QTabBar from qutebrowser.misc import objects from qutebrowser.config import configexc, configutils -from qutebrowser.utils import standarddir, utils, qtutils, urlutils, urlmatch +from qutebrowser.utils import (standarddir, utils, qtutils, urlutils, urlmatch, + usertypes) from qutebrowser.keyinput import keyutils @@ -911,6 +912,26 @@ class ColorSystem(MappingType): } +class IgnoreCase(MappingType): + + """Whether to search case insensitively.""" + + def __init__(self, none_ok=False): + super().__init__( + none_ok, + valid_values=ValidValues( + ('always', "Search case-insensitively."), + ('never', "Search case-sensitively."), + ('smart', ("Search case-sensitively if there are capital " + "characters.")))), + + MAPPING = { + 'always': usertypes.IgnoreCase.always, + 'never': usertypes.IgnoreCase.never, + 'smart': usertypes.IgnoreCase.smart, + } + + class QtColor(BaseType): """A color value. diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index cd36db49a..5bb8d3aa9 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -253,6 +253,9 @@ JsLogLevel = enum.Enum('JsLogLevel', ['unknown', 'info', 'warning', 'error']) MessageLevel = enum.Enum('MessageLevel', ['error', 'warning', 'info']) +IgnoreCase = enum.Enum('IgnoreCase', ['smart', 'never', 'always']) + + class Question(QObject): """A question asked to the user, e.g. via the status bar.