edit_command_buffer: speed up setting cursor position by line/column

alt-e restores the cursor position received from the editor, moving by
one character at a time.  This can be super slow on large commandlines,
even on release builds.  Let's fix that by setting the coordinates
directly.
This commit is contained in:
Johannes Altmanninger
2024-11-01 19:01:50 +01:00
parent 6525e3d11a
commit 85404bf7a9
6 changed files with 97 additions and 24 deletions

View File

@@ -110,13 +110,10 @@ function edit_command_buffer --description 'Edit the command buffer in an extern
set -l line $pos[2]
set -l indent (math (string length -- "$raw_lines[$line]") - (string length -- "$unindented_lines[$line]"))
set -l column (math $pos[3] - $indent)
commandline -C 0
for _line in (seq $line)[2..]
commandline -f down-line
end
commandline -f beginning-of-line
for _column in (seq $column)[2..]
commandline -f forward-single-char
if not commandline --line $line 2>/dev/null
commandline -f end-of-buffer
else
commandline --column $column 2>/dev/null || commandline -f end-of-line
end
end
command rm $cursor_from_editor