Exemple #1
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);
        }
Exemple #2
0
        public bool KeyPress(char c, CharacterArea area, CharacterView view)
        {
            switch ((int)c)
            {
            case 8:
                area.TypeBackspace(view);
                return(true);

            case 9:
                break;

            case 10:
                return(false);

            case 13:
                area.TypeEnter(view);
                return(true);

            case 27:
                area.Selections.Clear();
                return(false);
            }
            if (!area.TypeCharacter(c, view, false))
            {
                return(false);
            }
            area.MoveLeft(view, false);
            return(true);
        }
Exemple #3
0
        public void MoveToHome(CharacterView view)
        {
            if (CurrentRowLength == 0)
            {
                CursorX = 0;
                JumpInHorizontalView(view);
                return;
            }
            var indentDepth = GetIndentDepth(CursorY);

            if (CursorX > indentDepth)
            {
                CursorX = indentDepth;
                JumpInHorizontalView(view);
                return;
            }
            if (CursorX == indentDepth)
            {
                CursorX = 0;
                JumpInHorizontalView(view);
                return;
            }
            CursorX = CursorX == 0 ? indentDepth : 0;
            JumpInHorizontalView(view);
        }
Exemple #4
0
 public void Indent(CharacterArea area, CharacterView view)
 {
     for (var t = 0; t < 3; t++)
     {
         area.TypeCharacter(' ', view, true);
         area.MoveLeft(view, t == 2);
     }
 }
Exemple #5
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);
            }
        }
Exemple #6
0
 private void AutoIndent(CharacterView view, int y)
 {
     if (y <= 0)
     {
         return;
     }
     for (var i = 0; i < GetIndentDepth(y - 1); i++)
     {
         TypeCharacter(' ', view, y, true);
         MoveLeft(view, true);
     }
     JumpInHorizontalView(view);
 }
Exemple #7
0
        public void TypeEnter(CharacterView view)
        {
            if (CursorX == 0)
            {
                _rows.Insert(CursorY, "");
                MoveDown(view, false);
                JumpInHorizontalView(view);
                if (_options.AutoIndent)
                {
                    AutoIndent(view);
                }
                return;
            }
            if (CursorX == CurrentRowLength)
            {
                if (CursorY >= _rows.Count - 1)
                {
                    _rows.Add("");
                }
                else
                {
                    _rows.Insert(CursorY + 1, "");
                }
                if (_options.AutoIndent)
                {
                    AutoIndent(view, CursorY + 1);
                }
                MoveDown(view, true);
                MoveLeft(view, false);
                return;
            }
            var leftPart  = _rows[CursorY].Substring(0, CursorX);
            var rightPart = _rows[CursorY].Substring(CursorX);

            _rows[CursorY] = leftPart;
            if (CursorY >= _rows.Count - 1)
            {
                _rows.Add(rightPart);
            }
            else
            {
                _rows.Insert(CursorY + 1, rightPart);
            }
            MoveDown(view, true);
            MoveToHome(view);
            if (_options.AutoIndent)
            {
                AutoIndent(view);
            }
        }
Exemple #8
0
 public void MoveUp(CharacterView view)
 {
     if (CursorY > 0)
     {
         CursorY--;
     }
     if (CursorY < view.OffsetY)
     {
         view.OffsetY--;
     }
     while (CursorX > CurrentRowLength)
     {
         MoveLeft(view, false);
     }
 }
Exemple #9
0
 public void PageUp(CharacterView view)
 {
     if (CursorY <= 0)
     {
         return;
     }
     view.OffsetY -= CharacterView.ZoomLevels.GetCurrentZoom().Rows;
     if (view.OffsetY < 0)
     {
         view.OffsetY = 0;
     }
     CursorY -= CharacterView.ZoomLevels.GetCurrentZoom().Rows;
     if (CursorY < 0)
     {
         CursorY = 0;
     }
 }
Exemple #10
0
        public void TypeDelete(CharacterView view)
        {
            if (HasSelection())
            {
                DeleteSelection(view);
                return;
            }
            var len = CurrentRowLength;

            if (len == 0 && CursorX == 0)
            {
                _rows.RemoveAt(CursorY);
                if (_rows.Count <= 0)
                {
                    _rows.Add("");
                }
                if (CursorY >= _rows.Count)
                {
                    CursorY = _rows.Count - 1;
                }
            }
            else if (len > 0 && CursorX == 0)
            {
                _rows[CursorY] = _rows[CursorY].Substring(1);
            }
            else if (len > 0 && CursorX >= len)
            {
                if (CursorY < _rows.Count - 1)
                {
                    _rows[CursorY] += _rows[CursorY + 1];
                    _rows.RemoveAt(CursorY + 1);
                }
                CursorX = len;
            }
            else if (len > 0 && CursorX == len - 1)
            {
                _rows[CursorY] = _rows[CursorY].Substring(0, len - 1);
            }
            else if (len > 0 && CursorX < len - 1)
            {
                var left  = _rows[CursorY].Substring(0, CursorX);
                var right = _rows[CursorY].Substring(CursorX + 1);
                _rows[CursorY] = left + right;
            }
        }
Exemple #11
0
 public void MoveDown(CharacterView view, bool batch)
 {
     if (CursorY < _rows.Count - 1)
     {
         CursorY++;
     }
     if (!batch)
     {
         if (CursorY > view.OffsetY + CharacterView.ZoomLevels.GetCurrentZoom().Rows - 1)
         {
             view.OffsetY++;
         }
     }
     while (CursorX > CurrentRowLength)
     {
         CursorX--;
     }
 }
Exemple #12
0
        public void KeyDown(Keys keyCode, CharacterArea area, CharacterView view)
        {
            switch (keyCode)
            {
            case Keys.Delete:
                area.TypeDelete(view);
                break;

            case Keys.Down:
                area.MoveDown(view, false);
                break;

            case Keys.Up:
                area.MoveUp(view);
                break;

            case Keys.Left:
                area.MoveRight(view, false);
                break;

            case Keys.Right:
                area.MoveLeft(view, false);
                break;

            case Keys.Home:
                area.MoveToHome(view);
                break;

            case Keys.End:
                area.MoveToEnd(view);
                break;

            case Keys.PageUp:
                area.PageUp(view);
                break;

            case Keys.PageDown:
                area.PageDown(view);
                break;
            }
        }
Exemple #13
0
 public void PageDown(CharacterView view)
 {
     if (CursorY >= _rows.Count - 1)
     {
         return;
     }
     view.OffsetY += CharacterView.ZoomLevels.GetCurrentZoom().Rows;
     if (view.OffsetY > _rows.Count - CharacterView.ZoomLevels.GetCurrentZoom().Rows)
     {
         view.OffsetY = _rows.Count - CharacterView.ZoomLevels.GetCurrentZoom().Rows;
     }
     if (_rows.Count <= CharacterView.ZoomLevels.GetCurrentZoom().Rows)
     {
         view.OffsetY = 0;
     }
     CursorY += CharacterView.ZoomLevels.GetCurrentZoom().Rows;
     if (CursorY >= _rows.Count)
     {
         CursorY = _rows.Count - 1;
     }
 }
Exemple #14
0
        private void JumpInHorizontalView(CharacterView view)
        {
            var targetX = CursorX;

            if (CursorX > 0 && _options.ScrollAhead)
            {
                targetX--;
            }
            while (targetX < view.OffsetX)
            {
                view.OffsetX--;
            }
            targetX = CursorX;
            if (_options.ScrollAhead)
            {
                targetX++;
            }
            while (targetX > view.OffsetX + CharacterView.ZoomLevels.GetCurrentZoom().Columns - 1)
            {
                view.OffsetX++;
            }
        }
Exemple #15
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);
        }
Exemple #16
0
 public void MoveLeft(CharacterView view, bool batch)
 {
     if (CursorX < CurrentRowLength)
     {
         CursorX++;
         if (CursorX > view.OffsetX + CharacterView.ZoomLevels.GetCurrentZoom().Columns - 1)
         {
             view.OffsetX++;
         }
         return;
     }
     if (CursorY >= _rows.Count - 1)
     {
         return;
     }
     MoveDown(view, batch);
     CursorX = 0;
     if (!batch)
     {
         JumpInHorizontalView(view);
     }
 }
Exemple #17
0
 public void MoveRight(CharacterView view, bool batch)
 {
     if (CursorX > 0)
     {
         CursorX--;
         if (CursorX < view.OffsetX)
         {
             view.OffsetX--;
         }
         return;
     }
     if (CursorY <= 0)
     {
         return;
     }
     MoveUp(view);
     CursorX = CurrentRowLength;
     if (!batch)
     {
         JumpInHorizontalView(view);
     }
 }
Exemple #18
0
        public bool TypeCharacter(char c, CharacterView view, int y, bool batch)
        {
            var r = _rows[y];

            if (string.IsNullOrEmpty(r))
            {
                _rows[y] = new string(c, 1);
                if (!batch)
                {
                    JumpInHorizontalView(view);
                }
                return(true);
            }
            if (CursorX < r.Length)
            {
                _rows[y] = r.Insert(CursorX, new string(c, 1));
                return(true);
            }
            if (CursorX > r.Length)
            {
                CursorX = r.Length;
                if (!batch)
                {
                    JumpInHorizontalView(view);
                }
            }
            try
            {
                _rows[y] = r.Insert(CursorX, new string(c, 1));
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #19
0
 public void SelectionEnd(CharacterView view)
 {
 }
Exemple #20
0
 public void SelectionHome(CharacterView view)
 {
 }
Exemple #21
0
 public void SelectionPageDown(CharacterView view)
 {
 }
Exemple #22
0
 public void SelectionPageUp(CharacterView view)
 {
 }
Exemple #23
0
 public void SelectionRight(CharacterView view)
 {
 }
Exemple #24
0
 public void SelectionLeft(CharacterView view)
 {
 }
Exemple #25
0
 private void AutoIndent(CharacterView view) =>
 AutoIndent(view, CursorY);
Exemple #26
0
 public bool TypeCharacter(char c, CharacterView view, bool batch) =>
 TypeCharacter(c, view, CursorY, batch);
Exemple #27
0
 public void MoveToEnd(CharacterView view)
 {
     CursorX = CurrentRowLength;
     JumpInHorizontalView(view);
 }