public bool HandleInput(EditorInput input) { switch (input) { case EditorInput.UpArrow: Cursor = Cursor.Move(Buffer, MoveDirection.Up); return false; case EditorInput.DownArrow: Cursor = Cursor.Move(Buffer, MoveDirection.Down); return false; case EditorInput.LeftArrow: Cursor = Cursor.Move(Buffer, MoveDirection.Left); return false; case EditorInput.RightArrow: Cursor = Cursor.Move(Buffer, MoveDirection.Right); return false; case EditorInput.Enter: Buffer.SplitLine(Cursor); Cursor = Cursor.Move(Buffer, MoveDirection.Right); return true; case EditorInput.Backspace: if (Cursor.AtFirstColumn(Buffer)) { if (!Cursor.AtStart(Buffer)) { Cursor = Cursor.Move(Buffer, MoveDirection.Left); Buffer.MergeLine(Cursor.Line + 1); return true; } } else { Buffer.RemoveAt(Cursor, 1); Cursor = Cursor.Move(Buffer, MoveDirection.Left); return true; } return false; case EditorInput.Tab: Buffer.InsertAt(Cursor, " "); Cursor.Column += 4; return true; case EditorInput.ShiftTab: return false; } return false; }
public bool HandleInput(EditorInput input) { switch (input) { case EditorInput.UpArrow: Cursor = Cursor.Move(Buffer, MoveDirection.Up); return false; case EditorInput.DownArrow: Cursor = Cursor.Move(Buffer, MoveDirection.Down); return false; case EditorInput.LeftArrow: Cursor = Cursor.Move(Buffer, MoveDirection.Left); return false; case EditorInput.RightArrow: Cursor = Cursor.Move(Buffer, MoveDirection.Right); return false; case EditorInput.Enter: Buffer.SplitLine(Cursor); Cursor = Cursor.Move(Buffer, MoveDirection.Right); return true; case EditorInput.Backspace: if (Cursor.AtFirstColumn(Buffer)) { if (!Cursor.AtStart(Buffer)) { Cursor = Cursor.Move(Buffer, MoveDirection.Left); Buffer.MergeLine(Cursor.Line + 1); return true; } } else { Buffer.RemoveAt(Cursor, 1); Cursor = Cursor.Move(Buffer, MoveDirection.Left); return true; } return false; case EditorInput.Delete: if (!Cursor.AtLastColumn(Buffer)) { var newCursor = new Cursor(Cursor.Line, Cursor.Column + 1); Buffer.RemoveAt(newCursor, 1); return true; } else { if (!Cursor.AtLastLine(Buffer)) { Buffer.MergeLine(Cursor.Line + 1); return true; } } return false; case EditorInput.Tab: Buffer.InsertAt(Cursor, " "); Cursor.Column += 4; return true; case EditorInput.ShiftTab: return false; case EditorInput.Home: Cursor.Column = 0; return false; case EditorInput.ControlHome: Cursor.Line = 0; Cursor.Column = 0; return false; case EditorInput.End: Cursor.Column = Buffer.Lines[Cursor.Line].Data.Length; return false; case EditorInput.ControlEnd: Cursor.Line = Buffer.Lines.Count - 1; Cursor.Column = Buffer.Lines[Cursor.Line].Data.Length; return false; case EditorInput.PageUp: int newLine = Cursor.Line - (Height - 1); if (newLine < 0) Cursor.Line = 0; else Cursor.Line = newLine; this.StartLine = Cursor.Line; if (Cursor.Column > Buffer.Lines[Cursor.Line].Data.Length) Cursor.Column = Buffer.Lines[Cursor.Line].Data.Length; return true; case EditorInput.ControlPageUp: Cursor.Line = StartLine; Cursor.Column = StartColumn; return false; case EditorInput.PageDown: newLine = Cursor.Line + (Height - 1); if (newLine > Buffer.Lines.Count) Cursor.Line = Buffer.Lines.Count - 1; else Cursor.Line = newLine; this.StartLine = Cursor.Line; if (Cursor.Column > Buffer.Lines[Cursor.Line].Data.Length) Cursor.Column = Buffer.Lines[Cursor.Line].Data.Length; return true; case EditorInput.ControlPageDown: Cursor.Line = Math.Min(StartLine + Height - 2, Buffer.Lines.Count - 1); Cursor.Column = Math.Min(StartColumn + Width - GetGutterWidth() - 1, Buffer.Lines[Cursor.Line].Data.Length); return false; case EditorInput.ControlUpArrow: if (StartLine > 0) StartLine -= 1; return true; case EditorInput.ControlDownArrow: if (StartLine < Buffer.Lines.Count) StartLine += 1; return true; } return false; }