Use an enum for IgnoreCase
This commit is contained in:
parent
2cd2c60a8b
commit
a6d3a935d3
@ -2960,7 +2960,7 @@ Default: +pass:[false]+
|
|||||||
=== search.ignore_case
|
=== search.ignore_case
|
||||||
When to find text on a page case-insensitively.
|
When to find text on a page case-insensitively.
|
||||||
|
|
||||||
Type: <<types,String>>
|
Type: <<types,IgnoreCase>>
|
||||||
|
|
||||||
Valid values:
|
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.
|
|FontFamily|A Qt font family.
|
||||||
|FormatString|A string with placeholders.
|
|FormatString|A string with placeholders.
|
||||||
|FuzzyUrl|A URL which gets interpreted as search if needed.
|
|FuzzyUrl|A URL which gets interpreted as search if needed.
|
||||||
|
|IgnoreCase|Whether to search case insensitively.
|
||||||
|Int|Base class for an integer setting.
|
|Int|Base class for an integer setting.
|
||||||
|Key|A name of a key.
|
|Key|A name of a key.
|
||||||
|List|A list of values.
|
|List|A list of values.
|
||||||
|
@ -297,7 +297,7 @@ class AbstractSearch(QObject):
|
|||||||
self.text = None # type: typing.Optional[str]
|
self.text = None # type: typing.Optional[str]
|
||||||
self.search_displayed = False
|
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.
|
"""Check if case-sensitivity should be used.
|
||||||
|
|
||||||
This assumes self.text is already set properly.
|
This assumes self.text is already set properly.
|
||||||
@ -307,21 +307,21 @@ class AbstractSearch(QObject):
|
|||||||
"""
|
"""
|
||||||
assert self.text is not None
|
assert self.text is not None
|
||||||
mapping = {
|
mapping = {
|
||||||
'smart': not self.text.islower(),
|
usertypes.IgnoreCase.smart: not self.text.islower(),
|
||||||
'never': True,
|
usertypes.IgnoreCase.never: True,
|
||||||
'always': False,
|
usertypes.IgnoreCase.always: False,
|
||||||
}
|
}
|
||||||
return mapping[ignore_case]
|
return mapping[ignore_case]
|
||||||
|
|
||||||
def search(self, text: str, *,
|
def search(self, text: str, *,
|
||||||
ignore_case: str = 'never',
|
ignore_case: usertypes.IgnoreCase = usertypes.IgnoreCase.never,
|
||||||
reverse: bool = False,
|
reverse: bool = False,
|
||||||
result_cb: _Callback = None) -> None:
|
result_cb: _Callback = None) -> None:
|
||||||
"""Find the given text on the page.
|
"""Find the given text on the page.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text: The text to search for.
|
text: The text to search for.
|
||||||
ignore_case: Search case-insensitively. ('always'/'never/'smart')
|
ignore_case: Search case-insensitively.
|
||||||
reverse: Reverse search direction.
|
reverse: Reverse search direction.
|
||||||
result_cb: Called with a bool indicating whether a match was found.
|
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)
|
self._widget.findText(text, flags, wrapped_callback)
|
||||||
|
|
||||||
def search(self, text, *, ignore_case='never', reverse=False,
|
def search(self, text, *, ignore_case=usertypes.IgnoreCase.never,
|
||||||
result_cb=None):
|
reverse=False, result_cb=None):
|
||||||
# Don't go to next entry on duplicate search
|
# Don't go to next entry on duplicate search
|
||||||
if self.text == text and self.search_displayed:
|
if self.text == text and self.search_displayed:
|
||||||
log.webview.debug("Ignoring duplicate search request"
|
log.webview.debug("Ignoring duplicate search request"
|
||||||
|
@ -125,8 +125,8 @@ class WebKitSearch(browsertab.AbstractSearch):
|
|||||||
self._widget.findText('')
|
self._widget.findText('')
|
||||||
self._widget.findText('', QWebPage.HighlightAllOccurrences)
|
self._widget.findText('', QWebPage.HighlightAllOccurrences)
|
||||||
|
|
||||||
def search(self, text, *, ignore_case='never', reverse=False,
|
def search(self, text, *, ignore_case=usertypes.IgnoreCase.never,
|
||||||
result_cb=None):
|
reverse=False, result_cb=None):
|
||||||
# Don't go to next entry on duplicate search
|
# Don't go to next entry on duplicate search
|
||||||
if self.text == text and self.search_displayed:
|
if self.text == text and self.search_displayed:
|
||||||
log.webview.debug("Ignoring duplicate search request"
|
log.webview.debug("Ignoring duplicate search request"
|
||||||
|
@ -39,12 +39,7 @@ ignore_case:
|
|||||||
renamed: search.ignore_case
|
renamed: search.ignore_case
|
||||||
|
|
||||||
search.ignore_case:
|
search.ignore_case:
|
||||||
type:
|
type: IgnoreCase
|
||||||
name: String
|
|
||||||
valid_values:
|
|
||||||
- always: Search case-insensitively.
|
|
||||||
- never: Search case-sensitively.
|
|
||||||
- smart: Search case-sensitively if there are capital characters.
|
|
||||||
default: smart
|
default: smart
|
||||||
desc: When to find text on a page case-insensitively.
|
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.misc import objects
|
||||||
from qutebrowser.config import configexc, configutils
|
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
|
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):
|
class QtColor(BaseType):
|
||||||
|
|
||||||
"""A color value.
|
"""A color value.
|
||||||
|
@ -253,6 +253,9 @@ JsLogLevel = enum.Enum('JsLogLevel', ['unknown', 'info', 'warning', 'error'])
|
|||||||
MessageLevel = enum.Enum('MessageLevel', ['error', 'warning', 'info'])
|
MessageLevel = enum.Enum('MessageLevel', ['error', 'warning', 'info'])
|
||||||
|
|
||||||
|
|
||||||
|
IgnoreCase = enum.Enum('IgnoreCase', ['smart', 'never', 'always'])
|
||||||
|
|
||||||
|
|
||||||
class Question(QObject):
|
class Question(QObject):
|
||||||
|
|
||||||
"""A question asked to the user, e.g. via the status bar.
|
"""A question asked to the user, e.g. via the status bar.
|
||||||
|
Loading…
Reference in New Issue
Block a user