Exemple #1
0
        /// <summary>
        /// Runs the specified operation.
        /// </summary>
        /// <param name="editor">The active editor or null.</param>
        /// <param name="line">The active line or null.</param>
        /// <param name="operation">The operation to run.</param>
        /// <param name="right">True for right, false for left.</param>
        /// <param name="alt">True for the alternative operation.</param>
        static void Run(IEditor editor, ILine line, Operation operation, bool right, bool alt)
        {
            Point caret   = line == null ? editor.Caret : new Point(line.Caret, 0);
            int   iColumn = caret.X;
            int   iLine   = caret.Y;

            for (; ;)
            {
                ILine currentLine = line ?? editor[iLine];
                var   text        = currentLine.Text;

                int newX = -1;
                foreach (Match match in Regex.Matches(text))
                {
                    if (right)
                    {
                        if (match.Index > iColumn)
                        {
                            newX = match.Index;
                            break;
                        }
                    }
                    else
                    {
                        if (match.Index >= iColumn)
                        {
                            break;
                        }

                        newX = match.Index;
                    }
                }

                // :: new position is not found in the line
                if (newX < 0)
                {
                    if (alt || line != null)
                    {
                        return;
                    }

                    if (right)
                    {
                        if (++iLine >= editor.Count)
                        {
                            return;
                        }

                        iColumn = -1;
                    }
                    else
                    {
                        if (--iLine < 0)
                        {
                            return;
                        }

                        iColumn = int.MaxValue;
                    }

                    continue;
                }

                if (operation == Operation.Step)
                {
                    // :: step
                    if (line == null)
                    {
                        editor.GoTo(newX, iLine);
                        editor.UnselectText();
                        editor.Redraw();
                    }
                    else
                    {
                        //_100819_142053 Mantis#1464 Here was a kludge

                        line.UnselectText();
                        line.Caret = newX;
                    }
                }
                else if (operation == Operation.Select)
                {
                    // :: select
                    if (alt)
                    {
                        SelectColumn(editor, right, iLine, caret.X, newX);
                    }
                    else
                    {
                        SelectStream(editor, line, right, caret, new Point(newX, iLine));
                    }
                }
                else
                {
                    // :: delete
                    if (line == null)
                    {
                        if (!right && newX == 0 && caret.X > 0 && currentLine.Length == 0)
                        {
                            // "Cursor beyond end of line" and the line is empty
                            editor.UnselectText();
                            editor.GoToColumn(0);
                        }
                        else
                        {
                            // select the step text and delete it
                            if (!editor.SelectionExists)
                            {
                                if (right)
                                {
                                    editor.SelectText(caret.X, caret.Y, newX - 1, iLine);
                                }
                                else
                                {
                                    editor.SelectText(newX, iLine, caret.X - 1, caret.Y);
                                }
                            }
                            editor.DeleteText();
                        }
                        editor.Redraw();
                    }
                    else
                    {
                        if (line.SelectionSpan.Length <= 0)
                        {
                            if (right)
                            {
                                line.SelectText(caret.X, newX);
                            }
                            else
                            {
                                line.SelectText(newX, caret.X);
                            }
                        }
                        newX = line.SelectionSpan.Start;
                        line.SelectedText = string.Empty;
                        line.Caret        = newX;
                    }
                }

                return;
            }
        }
Exemple #2
0
        /// <summary>
        /// Runs the specified operation.
        /// </summary>
        /// <param name="editor">The active editor or null.</param>
        /// <param name="line">The active line or null.</param>
        /// <param name="operation">The operation to run.</param>
        /// <param name="right">True for right, false for left.</param>
        /// <param name="alt">True for the alternative operation.</param>
        static void Run(IEditor editor, ILine line, Operation operation, bool right, bool alt)
        {
            Point caret = line == null ? editor.Caret : new Point(line.Caret, 0);
            int iColumn = caret.X;
            int iLine = caret.Y;

            for (; ; )
            {
                ILine currentLine = line ?? editor[iLine];
                var text = currentLine.Text;

                int newX = -1;
                foreach (Match match in Regex.Matches(text))
                {
                    if (right)
                    {
                        if (match.Index > iColumn)
                        {
                            newX = match.Index;
                            break;
                        }
                    }
                    else
                    {
                        if (match.Index >= iColumn)
                            break;

                        newX = match.Index;
                    }
                }

                // :: new position is not found in the line
                if (newX < 0)
                {
                    if (alt || line != null)
                        return;

                    if (right)
                    {
                        if (++iLine >= editor.Count)
                            return;

                        iColumn = -1;
                    }
                    else
                    {
                        if (--iLine < 0)
                            return;

                        iColumn = int.MaxValue;
                    }

                    continue;
                }

                if (operation == Operation.Step)
                {
                    // :: step
                    if (line == null)
                    {
                        editor.GoTo(newX, iLine);
                        editor.UnselectText();
                        editor.Redraw();
                    }
                    else
                    {
                        //_100819_142053 Mantis#1464 Here was a kludge

                        line.UnselectText();
                        line.Caret = newX;
                    }
                }
                else if (operation == Operation.Select)
                {
                    // :: select
                    if (alt)
                        SelectColumn(editor, right, iLine, caret.X, newX);
                    else
                        SelectStream(editor, line, right, caret, new Point(newX, iLine));
                }
                else
                {
                    // :: delete
                    if (line == null)
                    {
                        if (!right && newX == 0 && caret.X > 0 && currentLine.Length == 0)
                        {
                            // "Cursor beyond end of line" and the line is empty
                            editor.UnselectText();
                            editor.GoToColumn(0);
                        }
                        else
                        {
                            // select the step text and delete it
                            if (!editor.SelectionExists)
                            {
                                if (right)
                                    editor.SelectText(caret.X, caret.Y, newX - 1, iLine);
                                else
                                    editor.SelectText(newX, iLine, caret.X - 1, caret.Y);
                            }
                            editor.DeleteText();
                        }
                        editor.Redraw();
                    }
                    else
                    {
                        if (line.SelectionSpan.Length <= 0)
                        {
                            if (right)
                                line.SelectText(caret.X, newX);
                            else
                                line.SelectText(newX, caret.X);
                        }
                        newX = line.SelectionSpan.Start;
                        line.SelectedText = string.Empty;
                        line.Caret = newX;
                    }
                }

                return;
            }
        }