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:
srdubya
2018-01-28 11:53:29 -08:00
committed by Jason Shirk
parent 2c8bfd39ce
commit c385dd5bcb
3 changed files with 25 additions and 2 deletions
+7
View File
@@ -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);
}
+2 -2
View File
@@ -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);
}
+16
View File
@@ -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()
{