In this way you'll save the other combinations with Control + Q to other tools. It would maybe be more useful to make it more distinct like: if (character.Modifiers = ConsoleModifiers.Control & character.Key = ConsoleKey.Q) Therefore you should do like this: (ConsoleModifiers.Control & character.Modifiers) = ConsoleModifiers.ControlĬonsider if this input check is suitable: if ((ConsoleModifiers.Control & character.Modifiers) != 0 & character.Key = ConsoleKey.Q)īecause of the flag-behavior of ConsoleModifiers.Control it will be true if any combination of Modifiers are pressed that involve Control (+ Q). Is potentially wrong because the value of ConsoleModifiers.Control could actually be 0. (ConsoleModifiers.Control & character.Modifiers) != 0 Return !Char.IsControl(character.Ke圜har) Private bool IsTextChar(ConsoleKeyInfo character) In Editor.HandleInput() you should check if a character is a text char before you insert: else if (IsTextChar(character)) I suppose it to be: internal Cursor MoveToCol(int col)
In Cursor.MoveToCol(int col) you don't use the argument col: internal Cursor MoveToCol(int col) Instead you should do something like this: linesDeepCopy = newLines In Buffer.SplitLine(.) you replace the next line with the second part of the split instead of inserting it after the first part: linesDeepCopy = newLines Public static void MoveCursor(int row, int col) Row = Math.Min(buffer.LineCount() - 1, Math.Max(Row, 0)) Ĭol = Math.Min(buffer.LineLength(Row), Math.Max(Col, 0)) Return new Cursor(Row, Col + 1).Clamp(buffer) Return new Cursor(Row, Col - 1).Clamp(buffer) Return new Cursor(Row + 1, Col).Clamp(buffer) Return new Cursor(Row - 1, Col).Clamp(buffer) Var linesDeepCopy = _lines.Select(x => x).ToList() Internal Buffer SplitLine(int row, int col) LinesDeepCopy = linesDeepCopy.Remove(col, 1)
LinesDeepCopy = linesDeepCopy.Insert(col, character) Var linesDeepCopy = _lines.Select(x => x).ToArray() Internal Buffer Insert(string character, int row, int col) _buffer = _buffer.Insert(character.Ke圜har.ToString(), _cursor.Row, _cursor.Col) ĪNSI.MoveCursor(_cursor.Row, _cursor.Col) _cursor = _cursor.Down(_buffer).MoveToCol(0) _buffer = _buffer.SplitLine(_cursor.Row, _cursor.Col)
_buffer = _buffer.Delete(_cursor.Row, _cursor.Col - 1) Įlse if(character.Key = ConsoleKey.Enter) If ((ConsoleModifiers.Control & character.Modifiers) != 0 &Įlse if ((ConsoleModifiers.Control & character.Modifiers) != 0 &Įlse if (character.Key = ConsoleKey.Backspace)
#TEXT EDITOR FOR XML SCHEMA STACK OVERFLOW CODE#
The method SplitLine was a head scratcher (really showcased the terseness of Ruby) where his line splitting and new carriage code looks like and I couldn't come up with anything like it in C#. I do have questions whether the code is up to mark in terms of new C# conventions, haven't violated any biggies or gone overboard with LINQ. Implementation wise it's faithful to what he does. It's in Ruby but I wanted to do it in C# just to see how much it differs.
#TEXT EDITOR FOR XML SCHEMA STACK OVERFLOW SERIES#
I have been following along Gary Bernhardt's excellent video series on "Building a Text Editor From Scratch".