public static void InsertLine(this ITextAreaDataSource src, int positionNo, int lineNo, int positionOffset) { lock (src.LockObject) { var line = src.Lines.ContainsKey(lineNo) ? src.Lines[lineNo] : null; src.PutGapIntoLine(lineNo); if (line != null) { var(line1, line2) = SplitEnterLine(line, positionNo); src.Update(lineNo, line1); src.Update(lineNo + 1, new string(' ', positionOffset) + line2); } } }
private void HandleBackspace(ITextAreaDataSource textAreaDataSource) { var cursorPosition = GetTextPositionByScreenLine(CursorX); if (cursorPosition <= 0) { HandleLinesMerge(textAreaDataSource); return; } var textLineNo = GetTextLineByScreenLine(CursorY); var str = textAreaDataSource.GetLine(textLineNo); str = str.BackspaceTextArea(cursorPosition); CursorX--; textAreaDataSource.Update(textLineNo, str); }
public static void MergeLines(this ITextAreaDataSource src, int lineNo) { lock (src.LockObject) { var line1 = src.GetLine(lineNo - 1) ?? string.Empty; var line2 = src.GetLine(lineNo) ?? string.Empty; if (!string.IsNullOrEmpty(line1)) { line1 += " "; } src.Update(lineNo - 1, line1 + line2); src.DeleteLine(lineNo); } }
public void KeyPressed(ConsoleKeyInfo key) { var textDataSource = _textAreaDataSource; if (textDataSource == null) { return; } switch (key.Key) { case ConsoleKey.RightArrow: if ((key.Modifiers & ConsoleModifiers.Shift) != 0) { FindNextWord(); } else { HandleRightArrow(); } return; case ConsoleKey.LeftArrow: if ((key.Modifiers & ConsoleModifiers.Shift) != 0) { FindPreviousWord(textDataSource); } else { HandleLeftArrow(textDataSource); } return; case ConsoleKey.DownArrow: HandleDownArrow(); return; case ConsoleKey.UpArrow: HandleUpArrow(); return; case ConsoleKey.Backspace: HandleBackspace(textDataSource); return; case ConsoleKey.Enter: HandleLineInsert(textDataSource); return; } if (key.IsKeyWithTextChar()) { var textLineNo = GetTextYPosition(); var str = _textAreaDataSource.GetLine(textLineNo); str = str.InsertTextAreaSymbol(GetTextPositionByScreenLine(CursorX), key.KeyChar); CursorX++; _textAreaDataSource.Update(textLineNo, str); } }