Update incremental_search PR with changes from review
This commit is contained in:
parent
77054cc063
commit
bb2fcddcd4
@ -45,7 +45,7 @@ ignore_case:
|
||||
|
||||
incremental_search:
|
||||
type: Bool
|
||||
default: False
|
||||
default: True
|
||||
desc: Find text on a page incrementally, renewing the search for each typing character.
|
||||
|
||||
new_instance_open_target:
|
||||
|
@ -46,7 +46,6 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
||||
update_completion: Emitted when the completion should be shown/updated.
|
||||
show_cmd: Emitted when command input should be shown.
|
||||
hide_cmd: Emitted when command input can be hidden.
|
||||
update_search: Emitted when search term could be updated.
|
||||
"""
|
||||
|
||||
got_cmd = pyqtSignal([str], [str, int])
|
||||
@ -55,7 +54,6 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
||||
update_completion = pyqtSignal()
|
||||
show_cmd = pyqtSignal()
|
||||
hide_cmd = pyqtSignal()
|
||||
update_search = pyqtSignal()
|
||||
|
||||
def __init__(self, *, win_id, private, parent=None):
|
||||
misc.CommandLineEdit.__init__(self, parent=parent)
|
||||
@ -69,8 +67,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
||||
self.cursorPositionChanged.connect(self.update_completion)
|
||||
self.textChanged.connect(self.update_completion)
|
||||
self.textChanged.connect(self.updateGeometry)
|
||||
self.textChanged.connect(self.update_search)
|
||||
self.update_search.connect(self.incrementSearch)
|
||||
self.textChanged.connect(self._incremental_search)
|
||||
|
||||
def prefix(self):
|
||||
"""Get the currently entered command prefix."""
|
||||
@ -244,12 +241,14 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
||||
width = self.fontMetrics().width(text)
|
||||
return QSize(width, height)
|
||||
|
||||
def incrementSearch(self):
|
||||
if config.val.incremental_search == True:
|
||||
@pyqtSlot(str)
|
||||
def _incremental_search(self, text):
|
||||
if config.val.incremental_search:
|
||||
search_prefixes = {
|
||||
'/': 'search -- ',
|
||||
'?': 'search -r -- ',
|
||||
}
|
||||
if self.prefix() == '/' or self.prefix() == '?':
|
||||
text = self.text()
|
||||
|
||||
# len(text) check is for when user presses <Esc>
|
||||
if self.prefix() in '/?' and len(text) != 0:
|
||||
self.got_cmd[str].emit(search_prefixes[text[0]] + text[1:])
|
||||
|
Loading…
Reference in New Issue
Block a user