Make cursor keys go through completion if a text was entered

This hopefully helps with people who try to use arrow keys for the completion,
while still making the command history somewhat discoverable.
This commit is contained in:
Florian Bruhin 2017-11-19 20:07:35 +01:00
parent c14135a6ce
commit 62f37df573
7 changed files with 51 additions and 9 deletions

View File

@ -74,6 +74,10 @@ Changed
download. download.
- Much improved user stylesheet handling which reduces flickering - Much improved user stylesheet handling which reduces flickering
and updates immediately after setting a stylesheet. and updates immediately after setting a stylesheet.
- `:completion-item-focus` now has a `--history` flag which causes it to go
through the command history when no text was entered. The default bindings for
cursor keys in the completion changed to use that, so that they can be used
again to navigate through completion items when a text was entered.
Fixed Fixed
~~~~~ ~~~~~

View File

@ -1428,13 +1428,16 @@ Delete the current completion item.
[[completion-item-focus]] [[completion-item-focus]]
=== completion-item-focus === completion-item-focus
Syntax: +:completion-item-focus 'which'+ Syntax: +:completion-item-focus [*--history*] 'which'+
Shift the focus of the completion menu to another item. Shift the focus of the completion menu to another item.
==== positional arguments ==== positional arguments
* +'which'+: 'next', 'prev', 'next-category', or 'prev-category'. * +'which'+: 'next', 'prev', 'next-category', or 'prev-category'.
==== optional arguments
* +*-H*+, +*--history*+: Navigate through command history if no text was typed.
[[completion-item-yank]] [[completion-item-yank]]
=== completion-item-yank === completion-item-yank
Syntax: +:completion-item-yank [*--sel*]+ Syntax: +:completion-item-yank [*--sel*]+

View File

@ -17,15 +17,24 @@ did in your old configuration, compared to the old defaults.
Other changes in default settings: Other changes in default settings:
- `<Up>` and `<Down>` in the completion now navigate through command history - In v1.1.x and newer, `<Up>` and `<Down>` navigate through command history
instead of selecting completion items. Use `<Tab>`/`<Shift-Tab>` to cycle if no text was entered yet.
through the completion instead. With v1.0.x, they always navigate through command history instead of selecting
completion items. Use `<Tab>`/`<Shift-Tab>` to cycle through the completion
instead.
You can get back the old behavior by doing: You can get back the old behavior by doing:
+ +
---- ----
:bind -m command <Up> completion-item-focus prev :bind -m command <Up> completion-item-focus prev
:bind -m command <Down> completion-item-focus next :bind -m command <Down> completion-item-focus next
---- ----
+
or always navigate through command history with
+
----
:bind -m command <Up> command-history-prev
:bind -m command <Down> command-history-next
----
- The default for `completion.web_history_max_items` is now set to `-1`, showing - The default for `completion.web_history_max_items` is now set to `-1`, showing
an unlimited number of items in the completion for `:open` as the new an unlimited number of items in the completion for `:open` as the new

View File

@ -430,13 +430,13 @@ Default:
* +pass:[&lt;Ctrl-U&gt;]+: +pass:[rl-unix-line-discard]+ * +pass:[&lt;Ctrl-U&gt;]+: +pass:[rl-unix-line-discard]+
* +pass:[&lt;Ctrl-W&gt;]+: +pass:[rl-unix-word-rubout]+ * +pass:[&lt;Ctrl-W&gt;]+: +pass:[rl-unix-word-rubout]+
* +pass:[&lt;Ctrl-Y&gt;]+: +pass:[rl-yank]+ * +pass:[&lt;Ctrl-Y&gt;]+: +pass:[rl-yank]+
* +pass:[&lt;Down&gt;]+: +pass:[command-history-next]+ * +pass:[&lt;Down&gt;]+: +pass:[completion-item-focus --history next]+
* +pass:[&lt;Escape&gt;]+: +pass:[leave-mode]+ * +pass:[&lt;Escape&gt;]+: +pass:[leave-mode]+
* +pass:[&lt;Return&gt;]+: +pass:[command-accept]+ * +pass:[&lt;Return&gt;]+: +pass:[command-accept]+
* +pass:[&lt;Shift-Delete&gt;]+: +pass:[completion-item-del]+ * +pass:[&lt;Shift-Delete&gt;]+: +pass:[completion-item-del]+
* +pass:[&lt;Shift-Tab&gt;]+: +pass:[completion-item-focus prev]+ * +pass:[&lt;Shift-Tab&gt;]+: +pass:[completion-item-focus prev]+
* +pass:[&lt;Tab&gt;]+: +pass:[completion-item-focus next]+ * +pass:[&lt;Tab&gt;]+: +pass:[completion-item-focus next]+
* +pass:[&lt;Up&gt;]+: +pass:[command-history-prev]+ * +pass:[&lt;Up&gt;]+: +pass:[completion-item-focus --history priv]+
- +pass:[hint]+: - +pass:[hint]+:
* +pass:[&lt;Ctrl-B&gt;]+: +pass:[hint all tab-bg]+ * +pass:[&lt;Ctrl-B&gt;]+: +pass:[hint all tab-bg]+

View File

@ -226,14 +226,31 @@ class CompletionView(QTreeView):
modes=[usertypes.KeyMode.command], scope='window') modes=[usertypes.KeyMode.command], scope='window')
@cmdutils.argument('which', choices=['next', 'prev', 'next-category', @cmdutils.argument('which', choices=['next', 'prev', 'next-category',
'prev-category']) 'prev-category'])
def completion_item_focus(self, which): @cmdutils.argument('history', flag='H')
def completion_item_focus(self, which, history=False):
"""Shift the focus of the completion menu to another item. """Shift the focus of the completion menu to another item.
Args: Args:
which: 'next', 'prev', 'next-category', or 'prev-category'. which: 'next', 'prev', 'next-category', or 'prev-category'.
history: Navigate through command history if no text was typed.
""" """
if not self._active: if not self._active:
return return
if history:
status = objreg.get('status-command', scope='window',
window=self._win_id)
if status.text() == ':' or status.history.is_browsing():
if which == 'next':
status.command_history_next()
return
elif which == 'prev':
status.command_history_prev()
return
else:
raise cmdexc.CommandError("Can't combine --history with "
"{}!".format(which))
selmodel = self.selectionModel() selmodel = self.selectionModel()
if which == 'next': if which == 'next':

View File

@ -2269,8 +2269,8 @@ bindings.default:
command: command:
<Ctrl-P>: command-history-prev <Ctrl-P>: command-history-prev
<Ctrl-N>: command-history-next <Ctrl-N>: command-history-next
<Up>: command-history-prev <Up>: completion-item-focus --history prev
<Down>: command-history-next <Down>: completion-item-focus --history next
<Shift-Tab>: completion-item-focus prev <Shift-Tab>: completion-item-focus prev
<Tab>: completion-item-focus next <Tab>: completion-item-focus next
<Ctrl-Tab>: completion-item-focus next-category <Ctrl-Tab>: completion-item-focus next-category

View File

@ -469,6 +469,15 @@ Feature: Various utility commands.
And I run :command-accept And I run :command-accept
Then the message "blah" should be shown Then the message "blah" should be shown
Scenario: Calling previous command with :completion-item-focus
When I run :set-cmd-text :message-info blah
And I run :command-accept
And I wait for "blah" in the log
And I run :set-cmd-text :
And I run :completion-item-focus prev --history
And I run :command-accept
Then the message "blah" should be shown
Scenario: Browsing through commands Scenario: Browsing through commands
When I run :set-cmd-text :message-info blarg When I run :set-cmd-text :message-info blarg
And I run :command-accept And I run :command-accept