Skip to content

Commit

Permalink
Remove LineIsMultiline in favor of multi-line agnostic algorithms (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
springcomp committed Feb 11, 2021
1 parent 6cf129e commit 0de6368
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 56 deletions.
20 changes: 6 additions & 14 deletions PSReadLine/BasicEditing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,25 +522,17 @@ public static void InsertLineAbove(ConsoleKeyInfo? key = null, object arg = null
/// </summary>
public static void InsertLineBelow(ConsoleKeyInfo? key = null, object arg = null)
{
// Move the current position to the end of the current line and only the current line.
if (_singleton.LineIsMultiLine())
int i = _singleton._current;
for (; i < _singleton._buffer.Length; i++)
{
int i = _singleton._current;
for (; i < _singleton._buffer.Length; i++)
if (_singleton._buffer[i] == '\n')
{
if (_singleton._buffer[i] == '\n')
{
break;
}
break;
}

_singleton._current = i;
}
else
{
_singleton._current = _singleton._buffer.Length;
}

_singleton._current = i;

Insert('\n');
}
}
Expand Down
46 changes: 20 additions & 26 deletions PSReadLine/Movement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,16 @@ public partial class PSConsoleReadLine
/// </summary>
public static void EndOfLine(ConsoleKeyInfo? key = null, object arg = null)
{
if (_singleton.LineIsMultiLine())
int i = _singleton._current;
for (; i < _singleton._buffer.Length; i++)
{
int i = _singleton._current;
for (; i < _singleton._buffer.Length; i++)
if (_singleton._buffer[i] == '\n')
{
if (_singleton._buffer[i] == '\n')
{
break;
}
break;
}

_singleton.MoveCursor((i == _singleton._current) ? _singleton._buffer.Length : i);
}
else
{
_singleton.MoveCursor(_singleton._buffer.Length);
}

_singleton.MoveCursor((i == _singleton._current) ? _singleton._buffer.Length : i);
}

/// <summary>
Expand Down Expand Up @@ -97,7 +90,7 @@ public static void ViForwardChar(ConsoleKeyInfo? key = null, object arg = null)
}
else
{
ViOffsetCursorPosition(+ numericArg);
ViOffsetCursorPosition(+numericArg);
}
}
}
Expand All @@ -109,7 +102,7 @@ public static void ViBackwardChar(ConsoleKeyInfo? key = null, object arg = null)
{
if (TryGetArgAsInt(arg, out var numericArg, 1))
{
ViOffsetCursorPosition(- numericArg);
ViOffsetCursorPosition(-numericArg);
}
}

Expand Down Expand Up @@ -225,7 +218,8 @@ private void MoveToLineImpl(int lineOffset)
point = point ?? ConvertOffsetToPoint(_current);
int newY = point.Value.Y + lineOffset;

Point newPoint = new Point() {
Point newPoint = new Point()
{
X = _moveToLineDesiredColumn,
Y = Math.Max(newY, _initialY)
};
Expand Down Expand Up @@ -470,18 +464,18 @@ public static void GotoBrace(ConsoleKeyInfo? key = null, object arg = null)
int direction;
switch (token.Kind)
{
case TokenKind.LParen: toMatch = TokenKind.RParen; direction = 1; break;
case TokenKind.LCurly: toMatch = TokenKind.RCurly; direction = 1; break;
case TokenKind.LBracket: toMatch = TokenKind.RBracket; direction = 1; break;
case TokenKind.LParen: toMatch = TokenKind.RParen; direction = 1; break;
case TokenKind.LCurly: toMatch = TokenKind.RCurly; direction = 1; break;
case TokenKind.LBracket: toMatch = TokenKind.RBracket; direction = 1; break;

case TokenKind.RParen: toMatch = TokenKind.LParen; direction = -1; break;
case TokenKind.RCurly: toMatch = TokenKind.LCurly; direction = -1; break;
case TokenKind.RBracket: toMatch = TokenKind.LBracket; direction = -1; break;
case TokenKind.RParen: toMatch = TokenKind.LParen; direction = -1; break;
case TokenKind.RCurly: toMatch = TokenKind.LCurly; direction = -1; break;
case TokenKind.RBracket: toMatch = TokenKind.LBracket; direction = -1; break;

default:
// Nothing to match (don't match inside strings/comments)
Ding();
return;
default:
// Nothing to match (don't match inside strings/comments)
Ding();
return;
}

var matchCount = 0;
Expand Down
21 changes: 7 additions & 14 deletions PSReadLine/Movement.vi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,14 @@ public static void ViEndOfPreviousGlob(ConsoleKeyInfo? key = null, object arg =
/// Move the cursor to the end of the current logical line.
/// </summary>
public static void MoveToEndOfLine(ConsoleKeyInfo? key = null, object arg = null)
{
if (_singleton.LineIsMultiLine())
{
var eol = GetEndOfLogicalLinePos(_singleton._current);
if (eol != _singleton._current)
{
_singleton.MoveCursor(eol);
}
_singleton._moveToEndOfLineCommandCount++;
_singleton._moveToLineDesiredColumn = int.MaxValue;
}
else
{
var eol = GetEndOfLogicalLinePos(_singleton._current);
if (eol != _singleton._current)
{
_singleton.MoveCursor(Math.Max(0, _singleton._buffer.Length + ViEndOfLineFactor));
}
_singleton.MoveCursor(eol);
}
_singleton._moveToEndOfLineCommandCount++;
_singleton._moveToLineDesiredColumn = int.MaxValue;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions PSReadLine/Movement.vi.multiline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public void MoveToFirstLine(ConsoleKeyInfo? key = null, object arg = null)
/// <param name="arg" />
public void MoveToLastLine(ConsoleKeyInfo? key = null, object arg = null)
{
if (!LineIsMultiLine())
var count = GetLogicalLineCount();
if (count == 1)
{
Ding(key, arg);
return;
}

var count = GetLogicalLineCount();
var currentLine = GetLogicalLineNumber();

var pos = ConvertOffsetToPoint(_singleton._current);
Expand Down
1 change: 1 addition & 0 deletions PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ private string InputLoop()
// nor a "move to line" command. In that case, the desired column
// number will be computed from the current position on the logical line.

_moveToEndOfLineCommandCount = 0;
_moveToLineDesiredColumn = -1;
}
}
Expand Down

0 comments on commit 0de6368

Please sign in to comment.