Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions PSReadLine/BasicEditing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,25 +473,7 @@ public static void AddLine(ConsoleKeyInfo? key = null, object arg = null)
public static void InsertLineAbove(ConsoleKeyInfo? key = null, object arg = null)
{
// Move the current position to the beginning of the current line and only the current line.
if (_singleton.LineIsMultiLine())
{
int i = Math.Max(0, _singleton._current - 1);
for (; i > 0; i--)
{
if (_singleton._buffer[i] == '\n')
{
i += 1;
break;
}
}

_singleton._current = i;
}
else
{
_singleton._current = 0;
}

_singleton._current = GetBeginningOfLinePos(_singleton._current);
Insert('\n');
PreviousLine();
}
Expand Down
6 changes: 3 additions & 3 deletions PSReadLine/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private static int GetBeginningOfLinePos(int current)

if (_singleton.LineIsMultiLine())
{
int i = Math.Max(0, current - 1);
for (; i > 0; i--)
int i = Math.Max(0, current);
while (i > 0)
{
if (_singleton._buffer[i] == '\n')
if (_singleton._buffer[--i] == '\n')
{
i += 1;
break;
Expand Down
6 changes: 6 additions & 0 deletions test/BasicEditingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ public void InsertLineAbove()
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
"9ABC"));

// Test case - create leading blank line, cursor to stay on same line
Test("\n\n1234", Keys("1234",
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(0,0)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Ctrl_Enter, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1))));
}

[SkippableFact]
Expand Down
6 changes: 6 additions & 0 deletions test/MovementTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ public void MultilineCursorMovement()
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(5 + continutationPromptLength, 4)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(6 + continutationPromptLength, 5)),

// Using the input previously entered, check for correct cursor movements when first line is blank
_.Home, _.Home, CheckThat(() => AssertCursorLeftTopIs(0, 0)),
_.DownArrow, CheckThat(() => AssertCursorLeftTopIs(8 + continutationPromptLength, 1)),
_.Home, CheckThat(() => AssertCursorLeftTopIs(continutationPromptLength, 1)),
_.Home, CheckThat(() => AssertCursorLeftTopIs(0,0)),

// Clear the input, we were just testing movement
_.Escape
));
Expand Down