adds support for keys : Delete Home & End #12

Merged
merged 1 commit into from Jul 31, 2012
Jump to file or symbol
Failed to load files and symbols.
+44 −0
Diff settings

Always

Just for now

@@ -78,6 +78,23 @@ private ReadInfo Read()
OnBackspaceHit();
}
+ else if(keyInfo.Key == ConsoleKey.Delete)
+ {
+ if (_cursorController.IsEndOfInput())
+ return new ReadInfo { KeyInfo = keyInfo };
+
+ OnDeleteHit();
+ }
+ else if(keyInfo.Key == ConsoleKey.Home)
+ {
+ if(!_cursorController.IsStartOfInput())
+ _cursorController.MoveCursorToHome();
+ }
+ else if( keyInfo.Key == ConsoleKey.End)
+ {
+ if(!_cursorController.IsEndOfInput())
+ _cursorController.MoveCursorToEnd();
+ }
else if (keyInfo.Key == ConsoleKey.LeftArrow)
{
if (!_cursorController.IsStartOfInput())
@@ -125,6 +142,21 @@ private void OnBackspaceHit()
_cursorController.MoveLineMarkerBackward();
}
+ private void OnDeleteHit()
+ {
+ var textAfterInput = ReadFromCursorToEndOfInput();
+ _console.WriteAtCursorAndMove(' ');
+ _cursorController.MoveCursorBackward();
+ var returnPoint = _cursorController.CreateCursorReturnPoint();
+
+ returnPoint();
+ Write(textAfterInput
+ .Skip(1), false);
+
+ returnPoint();
+ _cursorController.MoveLineMarkerForward();
+ }
+
public override ConsoleColor ForegroundColor
{
get { return _console.ForegroundColor; }
@@ -285,6 +317,18 @@ public void MoveCursorToStartOfNewLine()
_lineEnd.CursorTop = _console.CursorTop;
}
+ public void MoveCursorToHome()
+ {
+ _console.CursorTop = _lineStart.CursorTop;
+ _console.CursorLeft = _lineStart.CursorLeft;
+ }
+
+ public void MoveCursorToEnd()
+ {
+ _console.CursorTop = _lineEnd.CursorTop;
+ _console.CursorLeft = _lineEnd.CursorLeft;
+ }
+
public bool IsStartOfInput()
{
return _console.CursorLeft == _lineStart.CursorLeft && _console.CursorTop == _lineStart.CursorTop;