Exemple #1
0
        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);
            }
        }
Exemple #2
0
        private void HandleLineInsert(ITextAreaDataSource textAreaDataSource)
        {
            var lineNo     = GetTextLineByScreenLine(CursorY);
            var positionNo = GetTextPositionByScreenLine(CursorX);
            var line       = textAreaDataSource.GetLine(lineNo) ?? string.Empty;

            var positionOffset = line.GetPositionOffset();

            textAreaDataSource.InsertLine(positionNo, lineNo, positionOffset);
            CursorX = positionOffset;
            HandleDownArrow();
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        private void HandleLinesMerge(ITextAreaDataSource textAreaDataSource)
        {
            var linePos = GetTextLineByScreenLine(CursorY);

            if (linePos == 0)
            {
                return;
            }

            var line = textAreaDataSource.GetLine(linePos - 1) ?? string.Empty;

            textAreaDataSource.MergeLines(linePos);
            HandleUpArrow();
            CursorX = line.Length;
            if (line.Length > 0)
            {
                CursorX++;
            }
        }
Exemple #5
0
        private void GetPreviousLinePosition(ITextAreaDataSource textAreaDataSource)
        {
            var lineNo = GetTextLineByScreenLine(CursorY);

            if (lineNo == 0)
            {
                return;
            }


            var line = textAreaDataSource.GetLine(lineNo - 1) ?? string.Empty;

            HandleUpArrow();
            CursorX = line.Length;

            if (CursorX > Width)
            {
                XOffset = CursorX - Width;
                CursorX = Width;
            }
        }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
 private string GetCurrentLine()
 {
     return(_textAreaDataSource?.GetLine(GetTextYPosition()));
 }