Call search command directly instead of using arguments

This commit is contained in:
Jay Kamat 2018-04-16 23:15:56 -04:00
parent 76dbfa7305
commit 646e92707a
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5
2 changed files with 17 additions and 17 deletions

View File

@ -1778,16 +1778,14 @@ class CommandDispatcher:
replace=True)
@cmdutils.register(instance='command-dispatcher', scope='window',
maxsplit=0, star_args_optional=True, no_cmd_split=True)
def search(self, *text, reverse=False):
maxsplit=0)
def search(self, text="", reverse=False):
"""Search for a text on the current page. With no text, clear results.
Args:
text: The text to search for.
reverse: Reverse search direction.
"""
text = ' '.join(text)
self.set_mark("'")
tab = self._current_widget()

View File

@ -69,6 +69,13 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
self.textChanged.connect(self.updateGeometry)
self.textChanged.connect(self._incremental_search)
search_fn = cmdutils.cmd_dict['search'].run
self.search_prefixes = {
'/': lambda search: search_fn(self._win_id, ["--", search]),
'?': lambda search: search_fn(self._win_id, ["-r", "--", search]),
}
def prefix(self):
"""Get the currently entered command prefix."""
text = self.text()
@ -162,17 +169,17 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
Args:
rapid: Run the command without closing or clearing the command bar.
"""
prefixes = {
':': '',
'/': 'search -- ',
'?': 'search -r -- ',
}
text = self.text()
self.history.append(text)
if not rapid:
modeman.leave(self._win_id, usertypes.KeyMode.command,
'cmd accept')
self.got_cmd[str].emit(prefixes[text[0]] + text[1:])
prefix = text[0]
if prefix in self.search_prefixes:
self.search_prefixes[prefix](text[1:])
else:
self.got_cmd[str].emit(text[1:])
@cmdutils.register(instance='status-command', scope='window')
def edit_command(self, run=False):
@ -258,10 +265,5 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
if not config.val.search.incremental:
return
search_prefixes = {
'/': 'search -- ',
'?': 'search -r -- ',
}
if self.prefix() in ['/', '?']:
self.got_cmd[str].emit(search_prefixes[text[0]] + text[1:])
if self.prefix() in self.search_prefixes:
self.search_prefixes[self.prefix()](text[1:])