Combine completion-item-{prev,next}.
- Use a single command completion-item-focus with a next/prev argument. - Add a rule to translate old configs. - Regenerate the docs. See #1095.
This commit is contained in:
parent
743d2dc327
commit
7038db6b17
@ -914,8 +914,7 @@ How many steps to zoom out.
|
|||||||
|<<command-history-next,command-history-next>>|Go forward in the commandline history.
|
|<<command-history-next,command-history-next>>|Go forward in the commandline history.
|
||||||
|<<command-history-prev,command-history-prev>>|Go back in the commandline history.
|
|<<command-history-prev,command-history-prev>>|Go back in the commandline history.
|
||||||
|<<completion-item-del,completion-item-del>>|Delete the current completion item.
|
|<<completion-item-del,completion-item-del>>|Delete the current completion item.
|
||||||
|<<completion-item-next,completion-item-next>>|Select the next completion item.
|
|<<completion-item-focus,completion-item-focus>>|Shift the focus of the completion menu to another item.
|
||||||
|<<completion-item-prev,completion-item-prev>>|Select the previous completion item.
|
|
||||||
|<<drop-selection,drop-selection>>|Drop selection and keep selection mode enabled.
|
|<<drop-selection,drop-selection>>|Drop selection and keep selection mode enabled.
|
||||||
|<<enter-mode,enter-mode>>|Enter a key mode.
|
|<<enter-mode,enter-mode>>|Enter a key mode.
|
||||||
|<<follow-hint,follow-hint>>|Follow a hint.
|
|<<follow-hint,follow-hint>>|Follow a hint.
|
||||||
@ -991,13 +990,14 @@ Go back in the commandline history.
|
|||||||
=== completion-item-del
|
=== completion-item-del
|
||||||
Delete the current completion item.
|
Delete the current completion item.
|
||||||
|
|
||||||
[[completion-item-next]]
|
[[completion-item-focus]]
|
||||||
=== completion-item-next
|
=== completion-item-focus
|
||||||
Select the next completion item.
|
Syntax: +:completion-item-focus 'which'+
|
||||||
|
|
||||||
[[completion-item-prev]]
|
Shift the focus of the completion menu to another item.
|
||||||
=== completion-item-prev
|
|
||||||
Select the previous completion item.
|
==== positional arguments
|
||||||
|
* +'which'+: 'next' or 'previous'
|
||||||
|
|
||||||
[[drop-selection]]
|
[[drop-selection]]
|
||||||
=== drop-selection
|
=== drop-selection
|
||||||
|
@ -181,16 +181,14 @@ class CompletionView(QTreeView):
|
|||||||
# Item is a real item, not a category header -> success
|
# Item is a real item, not a category header -> success
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
def _next_prev_item(self, prev):
|
@cmdutils.register(instance='completion', hide=True,
|
||||||
"""Handle a tab press for the CompletionView.
|
modes=[usertypes.KeyMode.command], scope='window')
|
||||||
|
@cmdutils.argument('which', choices=['next', 'prev'])
|
||||||
Select the previous/next item and write the new text to the
|
def completion_item_focus(self, which):
|
||||||
statusbar.
|
"""Shift the focus of the completion menu to another item.
|
||||||
|
|
||||||
Helper for completion_item_next and completion_item_prev.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
prev: True for prev item, False for next one.
|
which: 'next' or 'prev'
|
||||||
"""
|
"""
|
||||||
# selmodel can be None if 'show' and 'auto-open' are set to False
|
# selmodel can be None if 'show' and 'auto-open' are set to False
|
||||||
# https://github.com/The-Compiler/qutebrowser/issues/1731
|
# https://github.com/The-Compiler/qutebrowser/issues/1731
|
||||||
@ -198,7 +196,7 @@ class CompletionView(QTreeView):
|
|||||||
if selmodel is None:
|
if selmodel is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
idx = self._next_idx(prev)
|
idx = self._next_idx(which == 'prev')
|
||||||
if not idx.isValid():
|
if not idx.isValid():
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -278,18 +276,6 @@ class CompletionView(QTreeView):
|
|||||||
scrollbar.setValue(scrollbar.minimum())
|
scrollbar.setValue(scrollbar.minimum())
|
||||||
super().showEvent(e)
|
super().showEvent(e)
|
||||||
|
|
||||||
@cmdutils.register(instance='completion', hide=True,
|
|
||||||
modes=[usertypes.KeyMode.command], scope='window')
|
|
||||||
def completion_item_prev(self):
|
|
||||||
"""Select the previous completion item."""
|
|
||||||
self._next_prev_item(True)
|
|
||||||
|
|
||||||
@cmdutils.register(instance='completion', hide=True,
|
|
||||||
modes=[usertypes.KeyMode.command], scope='window')
|
|
||||||
def completion_item_next(self):
|
|
||||||
"""Select the next completion item."""
|
|
||||||
self._next_prev_item(False)
|
|
||||||
|
|
||||||
@cmdutils.register(instance='completion', hide=True,
|
@cmdutils.register(instance='completion', hide=True,
|
||||||
modes=[usertypes.KeyMode.command], scope='window')
|
modes=[usertypes.KeyMode.command], scope='window')
|
||||||
def completion_item_del(self):
|
def completion_item_del(self):
|
||||||
|
@ -1415,8 +1415,7 @@ KEY_SECTION_DESC = {
|
|||||||
"Useful hidden commands to map in this section:\n\n"
|
"Useful hidden commands to map in this section:\n\n"
|
||||||
" * `command-history-prev`: Switch to previous command in history.\n"
|
" * `command-history-prev`: Switch to previous command in history.\n"
|
||||||
" * `command-history-next`: Switch to next command in history.\n"
|
" * `command-history-next`: Switch to next command in history.\n"
|
||||||
" * `completion-item-prev`: Select previous item in completion.\n"
|
" * `completion-item-focus`: Select another item in completion.\n"
|
||||||
" * `completion-item-next`: Select next item in completion.\n"
|
|
||||||
" * `command-accept`: Execute the command currently in the "
|
" * `command-accept`: Execute the command currently in the "
|
||||||
"commandline."),
|
"commandline."),
|
||||||
'prompt': (
|
'prompt': (
|
||||||
@ -1589,8 +1588,8 @@ KEY_DATA = collections.OrderedDict([
|
|||||||
('command', collections.OrderedDict([
|
('command', collections.OrderedDict([
|
||||||
('command-history-prev', ['<Ctrl-P>']),
|
('command-history-prev', ['<Ctrl-P>']),
|
||||||
('command-history-next', ['<Ctrl-N>']),
|
('command-history-next', ['<Ctrl-N>']),
|
||||||
('completion-item-prev', ['<Shift-Tab>', '<Up>']),
|
('completion-item-focus prev', ['<Shift-Tab>', '<Up>']),
|
||||||
('completion-item-next', ['<Tab>', '<Down>']),
|
('completion-item-focus next', ['<Tab>', '<Down>']),
|
||||||
('completion-item-del', ['<Ctrl-D>']),
|
('completion-item-del', ['<Ctrl-D>']),
|
||||||
('command-accept', RETURN_KEYS),
|
('command-accept', RETURN_KEYS),
|
||||||
])),
|
])),
|
||||||
@ -1686,4 +1685,7 @@ CHANGED_KEY_COMMANDS = [
|
|||||||
(re.compile(r'^yank -p'), r'yank pretty-url'),
|
(re.compile(r'^yank -p'), r'yank pretty-url'),
|
||||||
(re.compile(r'^yank-selected -p'), r'yank selection -s'),
|
(re.compile(r'^yank-selected -p'), r'yank selection -s'),
|
||||||
(re.compile(r'^yank-selected'), r'yank selection'),
|
(re.compile(r'^yank-selected'), r'yank selection'),
|
||||||
|
|
||||||
|
(re.compile(r'^completion-item-next'), r'completion-item-focus next'),
|
||||||
|
(re.compile(r'^completion-item-prev'), r'completion-item-focus prev'),
|
||||||
]
|
]
|
||||||
|
@ -122,7 +122,7 @@ def test_maybe_resize_completion(completionview, config_stub, qtbot):
|
|||||||
([[]], 1, None),
|
([[]], 1, None),
|
||||||
([[]], -1, None),
|
([[]], -1, None),
|
||||||
])
|
])
|
||||||
def test_completion_item_next_prev(tree, count, expected, completionview):
|
def test_completion_item_focus(tree, count, expected, completionview):
|
||||||
"""Test that on_next_prev_item moves the selection properly.
|
"""Test that on_next_prev_item moves the selection properly.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -140,21 +140,18 @@ def test_completion_item_next_prev(tree, count, expected, completionview):
|
|||||||
filtermodel = sortfilter.CompletionFilterModel(model,
|
filtermodel = sortfilter.CompletionFilterModel(model,
|
||||||
parent=completionview)
|
parent=completionview)
|
||||||
completionview.set_model(filtermodel)
|
completionview.set_model(filtermodel)
|
||||||
if count < 0:
|
direction = 'prev' if count < 0 else 'next'
|
||||||
for _ in range(-count):
|
for _ in range(abs(count)):
|
||||||
completionview.completion_item_prev()
|
completionview.completion_item_focus(direction)
|
||||||
else:
|
|
||||||
for _ in range(count):
|
|
||||||
completionview.completion_item_next()
|
|
||||||
idx = completionview.selectionModel().currentIndex()
|
idx = completionview.selectionModel().currentIndex()
|
||||||
assert filtermodel.data(idx) == expected
|
assert filtermodel.data(idx) == expected
|
||||||
|
|
||||||
|
|
||||||
def test_completion_item_next_prev_no_model(completionview):
|
def test_completion_item_focus_no_model(completionview):
|
||||||
"""Test that next/prev won't crash with no model set.
|
"""Test that next/prev won't crash with no model set.
|
||||||
|
|
||||||
This can happen if completion.show and completion.auto-open are False.
|
This can happen if completion.show and completion.auto-open are False.
|
||||||
Regression test for issue #1722.
|
Regression test for issue #1722.
|
||||||
"""
|
"""
|
||||||
completionview.completion_item_prev()
|
completionview.completion_item_focus('prev')
|
||||||
completionview.completion_item_next()
|
completionview.completion_item_focus('next')
|
||||||
|
Loading…
Reference in New Issue
Block a user