Esempio n. 1
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);
            }
        }