Merge branch 'dont_select_first'

This commit is contained in:
Anthony Scopatz 2016-06-25 18:25:57 -04:00
commit ce3d21e21d
2 changed files with 43 additions and 1 deletions

13
news/completion.rst Normal file
View file

@ -0,0 +1,13 @@
**Added:** None
**Changed:**
* `prompt_toolkit` completion no longer automatically selects the first entry on first tab-press when completing multiple directories at once
**Deprecated:** None
**Removed:** None
**Fixed:** None
**Security:** None

View file

@ -4,7 +4,8 @@ import builtins
from prompt_toolkit.enums import DEFAULT_BUFFER
from prompt_toolkit.filters import (Condition, Filter, IsMultiline,
HasSelection)
HasSelection, EmacsInsertMode,
ViInsertMode)
from prompt_toolkit.keys import Keys
from xonsh.aliases import xonsh_exit
from xonsh.tools import ON_WINDOWS
@ -127,6 +128,7 @@ def load_xonsh_bindings(key_bindings_manager):
"""
handle = key_bindings_manager.registry.add_binding
has_selection = HasSelection()
insert_mode = ViInsertMode() | EmacsInsertMode()
@handle(Keys.Tab, filter=TabShouldInsertIndentFilter())
def _(event):
@ -175,5 +177,32 @@ def load_xonsh_bindings(key_bindings_manager):
b.cursor_left(count=abs(relative_begin_index))
b.cursor_down(count=1)
@handle(Keys.ControlI, filter=insert_mode)
def generate_completions(event):
"""
Tab-completion: where the first tab completes the common suffix and the
second tab lists all the completions.
Notes
-----
This method was forked from the mainline prompt-toolkit repo.
Copyright (c) 2014, Jonathan Slenders, All rights reserved.
"""
b = event.current_buffer
def second_tab():
if b.complete_state:
b.complete_next()
else:
event.cli.start_completion(select_first=False)
# On the second tab-press, or when already navigating through
# completions.
if event.is_repeat or b.complete_state:
second_tab()
else:
event.cli.start_completion(insert_common_part=True,
select_first=False)
def _is_blank(l):
return len(l.strip()) == 0