On undo after execute, restore the cursor position

Ever since 149594f974 (Initial revision, 2005-09-20), we move the
cursor to the end of the commandline just before executing it.

This is so we can move the cursor to the line below the command line,
so moving the cursor is relevant if one presses enter on say, the
first line of a multi-line commandline.

As mentioned in #10838 and others, it can be useful to restore the
cursor position when recalling commandline from history. Make undo
restore the position where enter was pressed, instead of implicitly
moving the cursor to the end. This allows to quickly correct small
mistakes in large commandlines that failed recently.

This requires a new way of moving the cursor below the command line.
Test changes include unrelated cleanup of history.py.
This commit is contained in:
Johannes Altmanninger
2024-12-21 10:27:52 +01:00
parent f9fb026085
commit 610338cc70
10 changed files with 87 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from pexpect_helper import SpawnedProc
from pexpect_helper import SpawnedProc, TO_END
import os
import sys
import signal
@@ -16,7 +16,7 @@ send("set -g fish_key_bindings fish_vi_key_bindings\r")
expect_prompt()
send("echo ready to go\r")
expect_prompt(f"\r\n.*ready to go\r\n")
expect_prompt(TO_END + f"ready to go\r\n")
send(
"function add_change --on-variable fish_bind_mode ; set -g MODE_CHANGES $MODE_CHANGES $fish_bind_mode ; end\r"
)
@@ -42,7 +42,7 @@ send("i")
sleep(10 if "CI" in os.environ else 1)
send("echo mode changes: $MODE_CHANGES\r")
expect_prompt("\r\n.*mode changes: default insert default insert\r\n")
expect_prompt(TO_END + "mode changes: default insert default insert\r\n")
# Regression test for #8125.
# Control-C should return us to insert mode.
@@ -70,4 +70,4 @@ sleep(timeout)
# We should be back in insert mode now.
send("echo mode changes: $MODE_CHANGES\r")
expect_prompt("\r\n.*mode changes: default insert\r\n")
expect_prompt(TO_END + "mode changes: default insert\r\n")