mirror of
https://github.com/PowerShell/PSReadLine
synced 2026-06-08 12:12:13 +00:00
Fix 2 vi-mode cursor placement issues (#627)
Fix cursor placement after `cf` Also fix cursor placement with `s` at EOL. Fix #623
This commit is contained in:
@@ -576,7 +576,14 @@ namespace Microsoft.PowerShell
|
||||
public static void ViInsertWithDelete(ConsoleKeyInfo? key = null, object arg = null)
|
||||
{
|
||||
_singleton._groupUndoHelper.StartGroup(ViInsertWithDelete, arg);
|
||||
|
||||
var isEOL = _singleton._current == _singleton._buffer.Length + ViEndOfLineFactor;
|
||||
|
||||
DeleteChar(key, arg);
|
||||
if(isEOL)
|
||||
{
|
||||
_singleton._current++;
|
||||
}
|
||||
ViInsertMode(key, arg);
|
||||
}
|
||||
|
||||
|
||||
@@ -250,13 +250,13 @@ namespace Microsoft.PowerShell
|
||||
|
||||
private static void ViReplaceToChar(char keyChar, ConsoleKeyInfo? key = null, object arg = null)
|
||||
{
|
||||
bool shouldAppend = _singleton._current > 0;
|
||||
int initialCurrent = _singleton._current;
|
||||
|
||||
_singleton._groupUndoHelper.StartGroup(ReplaceChar, arg);
|
||||
ViCharacterSearcher.Set(keyChar, isBackward: false, isBackoff: false);
|
||||
if (ViCharacterSearcher.SearchDelete(keyChar, arg, backoff: false, instigator: (_key, _arg) => ViReplaceToChar(keyChar, _key, _arg)))
|
||||
{
|
||||
if (shouldAppend)
|
||||
if (_singleton._current < initialCurrent || _singleton._current >= _singleton._buffer.Length)
|
||||
{
|
||||
ViInsertWithAppend(key, arg);
|
||||
}
|
||||
|
||||
@@ -90,6 +90,22 @@ namespace Test
|
||||
));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ViDefect623()
|
||||
{
|
||||
TestSetup(KeyMode.Vi);
|
||||
|
||||
Test("012 4568", Keys(
|
||||
"012 4567", _.Escape, CheckThat(() => AssertCursorLeftIs(7)),
|
||||
"s8", _.Escape, CheckThat(() => AssertCursorLeftIs(7)), CheckThat(() => AssertLineIs("012 4568"))
|
||||
));
|
||||
|
||||
Test("asdf bzdf", Keys(
|
||||
"asdf asdf", _.Escape, "0wcfs", CheckThat(() => AssertCursorLeftIs(5)),
|
||||
"bz"
|
||||
));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ViChangeMovementUndo()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user