예제 #1
0
        static void SelectColumn(IEditor editor, bool right, int line, int caretOld, int caretNew)
        {
            int x1, y1, x2, y2;

            if (editor.SelectionExists)
            {
                if (editor.SelectionKind != PlaceKind.Column)
                {
                    return;
                }

                // editor selection
                var place = editor.SelectionPlace;
                y1 = place.First.Y;
                y2 = place.Last.Y;

                // screen selection and carets
                int select1 = editor.ConvertColumnEditorToScreen(y1, place.First.X);
                int select2 = editor.ConvertColumnEditorToScreen(y2, place.Last.X);
                int caret1  = editor.ConvertColumnEditorToScreen(line, caretOld);
                int caret2  = editor.ConvertColumnEditorToScreen(line, caretNew);

                if (right)
                {
                    if (caret1 < select2 && caret2 > select2)
                    {
                        // invert selection
                        x1 = select2 + 1;
                        x2 = caret2 - 1;
                    }
                    else if (caret1 != select1)
                    {
                        // expand selection
                        x1 = select1;
                        x2 = caret2 - 1;
                    }
                    else
                    {
                        // reduce selection
                        x1 = caret2;
                        x2 = select2;
                    }
                }
                else
                {
                    if (caret2 >= select1)
                    {
                        // reduce selection
                        x1 = select1;
                        x2 = caret2 - 1;
                    }
                    else if (caret1 > select1)
                    {
                        // invert selection
                        x1 = caret2;
                        x2 = select1 - 1;
                    }
                    else
                    {
                        // expand selection
                        x1 = caret2;
                        x2 = select2;
                    }
                }
            }
            else
            {
                // start selection
                y1 = y2 = line;
                if (right)
                {
                    x1 = editor.ConvertColumnEditorToScreen(y1, caretOld);
                    x2 = editor.ConvertColumnEditorToScreen(y1, caretNew - 1);
                }
                else
                {
                    x1 = editor.ConvertColumnEditorToScreen(y1, caretNew);
                    x2 = editor.ConvertColumnEditorToScreen(y1, caretOld - 1);
                }
            }

            // set/drop selection and set the caret
            editor.GoTo(caretNew, line);
            editor.SelectText(x1, y1, x2, y2, PlaceKind.Column);
            editor.Redraw();
        }
예제 #2
0
        static void SelectColumn(IEditor editor, bool right, int line, int caretOld, int caretNew)
        {
            int x1, y1, x2, y2;
            if (editor.SelectionExists)
            {
                if (editor.SelectionKind != PlaceKind.Column)
                    return;

                // editor selection
                var place = editor.SelectionPlace;
                y1 = place.First.Y;
                y2 = place.Last.Y;

                // screen selection and carets
                int select1 = editor.ConvertColumnEditorToScreen(y1, place.First.X);
                int select2 = editor.ConvertColumnEditorToScreen(y2, place.Last.X);
                int caret1 = editor.ConvertColumnEditorToScreen(line, caretOld);
                int caret2 = editor.ConvertColumnEditorToScreen(line, caretNew);

                if (right)
                {
                    if (caret1 < select2 && caret2 > select2)
                    {
                        // invert selection
                        x1 = select2 + 1;
                        x2 = caret2 - 1;
                    }
                    else if (caret1 != select1)
                    {
                        // expand selection
                        x1 = select1;
                        x2 = caret2 - 1;
                    }
                    else
                    {
                        // reduce selection
                        x1 = caret2;
                        x2 = select2;
                    }
                }
                else
                {
                    if (caret2 >= select1)
                    {
                        // reduce selection
                        x1 = select1;
                        x2 = caret2 - 1;
                    }
                    else if (caret1 > select1)
                    {
                        // invert selection
                        x1 = caret2;
                        x2 = select1 - 1;
                    }
                    else
                    {
                        // expand selection
                        x1 = caret2;
                        x2 = select2;
                    }
                }
            }
            else
            {
                // start selection
                y1 = y2 = line;
                if (right)
                {
                    x1 = editor.ConvertColumnEditorToScreen(y1, caretOld);
                    x2 = editor.ConvertColumnEditorToScreen(y1, caretNew - 1);
                }
                else
                {
                    x1 = editor.ConvertColumnEditorToScreen(y1, caretNew);
                    x2 = editor.ConvertColumnEditorToScreen(y1, caretOld - 1);
                }
            }

            // set/drop selection and set the caret
            editor.GoTo(caretNew, line);
            editor.SelectText(x1, y1, x2, y2, PlaceKind.Column);
            editor.Redraw();
        }