mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
abbrevs: Allow for setting cursor position within expanded abbrev
This commit is contained in:
parent
98fb262fbb
commit
9ba2eb5934
1 changed files with 17 additions and 1 deletions
|
@ -56,6 +56,21 @@ def revert_abbrev(buffer):
|
|||
return True
|
||||
|
||||
|
||||
def set_cursor_position(buffer):
|
||||
abbrevs = getattr(builtins, "abbrevs", None)
|
||||
if abbrevs is None:
|
||||
return False
|
||||
global last_expanded
|
||||
abbr = abbrevs[last_expanded]
|
||||
pos = abbr.rfind("<edit>")
|
||||
if pos == -1:
|
||||
return False
|
||||
buffer.cursor_position = buffer.cursor_position - (len(abbr) - pos)
|
||||
buffer.delete(6)
|
||||
last_expanded = None
|
||||
return True
|
||||
|
||||
|
||||
@events.on_ptk_create
|
||||
def custom_keybindings(bindings, **kw):
|
||||
|
||||
|
@ -70,7 +85,8 @@ def custom_keybindings(bindings, **kw):
|
|||
buffer = event.app.current_buffer
|
||||
if not revert_abbrev(buffer):
|
||||
expand_abbrev(buffer)
|
||||
buffer.insert_text(" ")
|
||||
if last_expanded is None or not set_cursor_position(buffer):
|
||||
buffer.insert_text(" ")
|
||||
|
||||
@handler(
|
||||
Keys.ControlJ, filter=IsMultiline() & insert_mode & ~completion_is_selected
|
||||
|
|
Loading…
Add table
Reference in a new issue