Exemple #1
0
 public void SplitLine(Cursor where)
 {
     var line = Lines[where.Line];
     var rest = line.Data.Substring(where.Column);
     line.Data = line.Data.Substring(0, where.Column);
     Lines.Insert(where.Line + 1, new Line(rest, line.Ending));
 }
        public CommandPalette(IConsole context, int x, int y, int w)
        {
            console = context;

            Focused = true;

            X = x;
            Y = y;
            Width = w;
            Height = 2;

            buffer = new Buffer();
            cursor = new Cursor(0, 0);
        }
Exemple #3
0
 private void Translate(Cursor where, out int x, out int y)
 {
     x = X + GetGutterWidth() + where.Column - StartColumn;
     y = Y + 1 + where.Line - StartLine;
 }
Exemple #4
0
        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;
        }
Exemple #5
0
        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;
        }
Exemple #6
0
 public void RemoveAt(Cursor where, int count)
 {
     var line = Lines[where.Line];
     line.Data = line.Data.Remove(where.Column - 1, count);
 }
Exemple #7
0
 public void InsertAt(Cursor where, string what)
 {
     var line = Lines[where.Line];
     line.Data = line.Data.Insert(where.Column, what);
 }
 public void Clear()
 {
     buffer = new Buffer();
     cursor = new Cursor(0, 0);
 }