Use an enum for IgnoreCase
This commit is contained in:
parent
2cd2c60a8b
commit
a6d3a935d3
@ -2960,7 +2960,7 @@ Default: +pass:[false]+
|
||||
=== search.ignore_case
|
||||
When to find text on a page case-insensitively.
|
||||
|
||||
Type: <<types,String>>
|
||||
Type: <<types,IgnoreCase>>
|
||||
|
||||
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.
|
||||
|
@ -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.
|
||||
"""
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user