Example #1
0
        public void TypeBackspace(CharacterView view)
        {
            var len         = CurrentRowLength;
            var viewOffsetX = 0;
            var viewOffsetY = 0;

            if (CursorX == 0 && CursorY > 0)
            {
                var prevRowLength = _rows[CursorY - 1].Length;
                _rows[CursorY - 1] += _rows[CursorY];
                _rows.RemoveAt(CursorY);
                CursorX = prevRowLength;
                CursorY--;
                if (CursorY > 0)
                {
                    viewOffsetY--;
                }
            }
            else if (CursorX > 0 && CursorX > len)
            {
                MoveLeft(view, false);
                if (CursorX > 0)
                {
                    viewOffsetX--;
                }
            }
            else if (CursorX == 1)
            {
                _rows[CursorY] = _rows[CursorY].Substring(1);
                CursorX        = 0;
            }
            else if (len > 0 && CursorX == len)
            {
                _rows[CursorY] = _rows[CursorY].Substring(0, len - 1);
                CursorX--;
                viewOffsetX--;
            }
            else if (CursorX > 0)
            {
                var left  = _rows[CursorY].Substring(0, CursorX - 1);
                var right = _rows[CursorY].Substring(CursorX);
                _rows[CursorY] = left + right;
                CursorX--;
                viewOffsetX--;
            }
            if (_options.ScrollAhead)
            {
                view.EnsurePositionIsVisible(CursorX + viewOffsetX, CursorY + viewOffsetY);
            }
            else
            {
                view.EnsurePositionIsVisible(Cursor);
            }
        }
Example #2
0
        private void DeleteSelection(CharacterView view)
        {
            var selectionOperations = Selections.OrderByDescending(x => x.LineIndex).ToList();

            foreach (var selectionOperation in selectionOperations)
            {
                switch (selectionOperation.SelectionType)
                {
                case SelectionType.NotSelected:
                    continue;

                case SelectionType.FullRow:
                    _rows.RemoveAt(selectionOperation.LineIndex);
                    continue;

                case SelectionType.Range:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            if (_rows.Count < 1)
            {
                _rows.Add("");
            }
            while (CursorY >= _rows.Count)
            {
                CursorY--;
            }
            Selections.ClearSelection();
            view.EnsurePositionIsVisible(Cursor);
        }
Example #3
0
        public void Outdent(CharacterArea area, CharacterView view)
        {
            if (area.CurrentRowLength <= 0)
            {
                return;
            }
            for (var t = 0; t < 3; t++)
            {
                if (area.CurrentRow[0] != ' ')
                {
                    continue;
                }
                area.DeleteAt(0, area.CursorY);
                if (area.CursorX > 0)
                {
                    area.CursorX--;
                }
            }
            var offsetX = _options.ScrollAhead && area.CursorX > 0 ? -1 : 0;

            view.EnsurePositionIsVisible(area.CursorX + offsetX, area.CursorY);
        }