Пример #1
0
        override public void Redo()
        {
            deleted = new string[orderedRanges.Length];
            int offset = 0;

            for (int i = 0; i < orderedRanges.Length; i++)
            {
                SimpleRange range = orderedRanges[i];
                range.index += offset;
                string deletedI = lines.GetText(range.index, range.count);
                lines.RemoveText(range.index, range.count);
                lines.InsertText(range.index, newText);
                offset          += newText.Length - range.count;
                orderedRanges[i] = range;
                deleted[i]       = deletedI;
            }
            if (orderedRanges.Length > 0)
            {
                selections.RemoveRange(0, selections.Count - 1);
                Selection   selection = selections[0];
                SimpleRange lastRange = orderedRanges[orderedRanges.Length - 1];
                selection.anchor = selection.caret = lastRange.index + newText.Length;
                Place place = lines.PlaceOf(selection.caret);
                lines.SetPreferredPos(selection, place);
            }
        }
Пример #2
0
        override public void Redo()
        {
            lines.ResizeSelections(ranges.Count);
            string[] lineBreaks = new string[selections.Count];
            for (int i = ranges.Count; i-- > 0;)
            {
                SimpleRange range     = ranges[i];
                Line        endLine   = lines[range.index + range.count - 1];
                Selection   selection = selections[i];
                lineBreaks[i]    = range.index + range.count == lines.LinesCount ? "" : lines.lineBreak;
                selection.anchor = lines.IndexOf(new Place(0, range.index));
                selection.caret  = lines.IndexOf(new Place(endLine.charsCount, range.index + range.count - 1));
            }

            this.eraseCommand  = null;
            this.indentCommand = null;
            InsertTextCommand eraseCommand = new InsertTextCommand(null, lineBreaks, true);

            eraseCommand.lines      = lines;
            eraseCommand.selections = selections;
            if (eraseCommand.Init())
            {
                string[] indents = new string[selections.Count];
                for (int i = 0; i < selections.Count; i++)
                {
                    Selection selection = selections[i];
                    Place     place     = lines.PlaceOf(Math.Min(selection.anchor, selection.caret));
                    Line      line      = lines[place.iLine];
                    string    text;
                    int       count;
                    line.GetFirstIntegerTabs(out text, out count);
                    indents[i] = text ?? "";
                }

                eraseCommand.Redo();
                for (int i = 0; i < selections.Count; i++)
                {
                    Selection selection = selections[i];
                    selection.anchor = selection.caret = selection.caret - lineBreaks[i].Length;
                }
                this.eraseCommand = eraseCommand;

                InsertTextCommand indentCommand = new InsertTextCommand(null, indents, true);
                indentCommand.lines      = lines;
                indentCommand.selections = selections;
                if (indentCommand.Init())
                {
                    indentCommand.Redo();
                    this.indentCommand = indentCommand;
                }
            }
        }
Пример #3
0
        public void UpdateHighlight(int index, int count)
        {
            FixRange(ref index, ref count);
            bool isOutFrame = index <_frameCharsIndex || index + count> _frameCharsIndex + _frameCharsCount;

            if (highlightRegex != ClipboardExecutor.ViRegex || isOutFrame || !frameValid)
            {
                frameValid     = true;
                highlightRegex = ClipboardExecutor.ViRegex;
                matches.Clear();
                if (highlightRegex != null)
                {
                    int frameCharsIndex = index - count / 2;
                    int frameCharsCount = count * 2;
                    FixRange(ref frameCharsIndex, ref frameCharsCount);
                    if (_frameCharsIndex != frameCharsIndex || _frameCharsCount != frameCharsCount)
                    {
                        _frameCharsIndex = frameCharsIndex;
                        _frameCharsCount = frameCharsCount;
                        _frameChars.Resize(_frameCharsCount);
                    }
                    if (_frameCharsCount > 0)
                    {
                        GetText(_frameCharsIndex, _frameCharsCount, _frameChars.buffer);
                    }
                    char[] chars = _frameChars.buffer;
                    int    ii    = 0;
                    while (ii < _frameCharsCount)
                    {
                        CharsRegularExpressions.Match match = null;
                        try
                        {
                            match = highlightRegex.Match(chars, ii, _frameCharsCount - ii);
                        }
                        catch
                        {
                        }
                        if (match == null || !match.IsMatched(0))
                        {
                            break;
                        }
                        SimpleRange range = new SimpleRange();
                        range.index = _frameCharsIndex + match.Index;
                        range.count = match.Length;
                        matches.Add(range);
                        ii = match.Index + (match.Length > 0 ? match.Length : 1);
                    }
                }
            }
        }
Пример #4
0
        override public void Undo()
        {
            int offset = 0;

            for (int i = 0; i < orderedRanges.Length; i++)
            {
                SimpleRange range = orderedRanges[i];
                range.index += offset;
                string deletedI = deleted[i];
                lines.RemoveText(range.index, newText.Length);
                lines.InsertText(range.index, deletedI);
                offset          += deletedI.Length - newText.Length;
                orderedRanges[i] = range;
            }
            deleted = null;
            SetSelectionMementos(mementos);
            lines.viStoreSelector.ViStoreMementos(mementos);
        }
        override public void Redo()
        {
            lines.ResizeSelections(ranges.Count);
            for (int i = ranges.Count; i-- > 0;)
            {
                SimpleRange range     = ranges[i];
                Selection   selection = selections[i];
                selection.anchor = lines.IndexOf(new Place(0, range.index));
                Line endLine = lines[range.index + range.count - 1];
                selection.caret = lines.IndexOf(new Place(endLine.charsCount, range.index + range.count - 1));
            }

            EraseSelectionCommand eraseCommand = new EraseSelectionCommand();

            eraseCommand.lines      = lines;
            eraseCommand.selections = lines.selections;
            if (eraseCommand.Init())
            {
                eraseCommand.Redo();
                this.eraseCommand = eraseCommand;
            }
        }
Пример #6
0
        override public void Undo()
        {
            int k = 0;

            for (int i = 0; i < ranges.Count; i++)
            {
                SimpleRange  range    = ranges[i];
                LineIterator iterator = lines.GetLineRange(range.index, range.count);

                while (iterator.MoveNext())
                {
                    Memento deletedI = deleted[k++];
                    Line    line     = iterator.current;
                    line.Chars_RemoveRange(0, deletedI.count);
                    line.Chars_InsertRange(0, deletedI.text);
                    iterator.InvalidateCurrentText(deletedI.text.Length - deletedI.count);
                }
            }
            deleted = null;
            SetSelectionMementos(mementos);
            lines.ResetTextCache();
            lines.viStoreSelector.ViStoreMementos(mementos);
        }
Пример #7
0
        override public void Redo()
        {
            lines.ResizeSelections(ranges.Count);
            for (int i = ranges.Count; i-- > 0;)
            {
                SimpleRange range     = ranges[i];
                Line        endLine   = lines[range.index + range.count - 1];
                Selection   selection = selections[i];
                if (range.index > 0 && range.index + range.count == lines.LinesCount)
                {
                    Line startLine = lines[range.index - 1];
                    selection.anchor = lines.IndexOf(new Place(startLine.NormalCount, range.index - 1));
                    selection.caret  = lines.IndexOf(new Place(endLine.charsCount, range.index + range.count - 1));
                }
                else
                {
                    selection.anchor = lines.IndexOf(new Place(0, range.index));
                    selection.caret  = lines.IndexOf(new Place(endLine.charsCount, range.index + range.count - 1));
                }
            }

            EraseSelectionCommand eraseCommand = new EraseSelectionCommand();

            eraseCommand.lines      = lines;
            eraseCommand.selections = lines.selections;
            if (eraseCommand.Init())
            {
                eraseCommand.Redo();
                this.eraseCommand = eraseCommand;
            }
            else
            {
                this.eraseCommand = null;
            }
            controller.ViMoveHome(false, true);
        }
Пример #8
0
 public static int CompareLeftToRight(SimpleRange a, SimpleRange b)
 {
     return(a.index == b.index ? a.count - b.count : a.index - b.index);
 }
Пример #9
0
        override public void Redo()
        {
            int deletedLength = 0;

            for (int i = 0; i < ranges.Count; i++)
            {
                SimpleRange range = ranges[i];
                deletedLength += range.count;
            }
            deleted = new Memento[deletedLength];
            SelectionPart[] parts = new SelectionPart[mementos.Length * 2];
            for (int i = 0; i < mementos.Length; i++)
            {
                SelectionMemento memento = mementos[i];
                if (memento.anchor <= memento.caret)
                {
                    parts[i * 2]     = new SelectionPart(false, memento.index);
                    parts[i * 2 + 1] = new SelectionPart(true, memento.index);
                }
                else
                {
                    parts[i * 2]     = new SelectionPart(true, memento.index);
                    parts[i * 2 + 1] = new SelectionPart(false, memento.index);
                }
            }

            int k      = 0;
            int iPart  = 0;
            int offset = 0;

            for (int i = 0; i < ranges.Count; i++)
            {
                SimpleRange  range    = ranges[i];
                LineIterator iterator = lines.GetLineRange(range.index, range.count);

                int lineStart = lines.IndexOf(new Place(0, range.index));
                while (iterator.MoveNext())
                {
                    Line        line     = iterator.current;
                    int         oldCount = line.charsCount;
                    string      deletedI;
                    List <char> chars = new List <char>();
                    int         tabsCount;
                    line.GetFirstIntegerTabs(out deletedI, out tabsCount);
                    if (isLeft)
                    {
                        if (lines.spacesInsteadTabs)
                        {
                            AddChars(chars, ' ', (tabsCount - 1) * lines.tabSize);
                        }
                        else
                        {
                            AddChars(chars, '\t', tabsCount - 1);
                        }
                        if (tabsCount == 0)
                        {
                            string spaces = "";
                            for (int j = deletedI.Length; j < line.charsCount && line.chars[j].c == ' '; j++)
                            {
                                spaces += ' ';
                            }
                            deletedI = spaces + deletedI;
                        }
                    }
                    else
                    {
                        if (lines.spacesInsteadTabs)
                        {
                            AddChars(chars, ' ', (tabsCount + 1) * lines.tabSize);
                        }
                        else
                        {
                            AddChars(chars, '\t', tabsCount + 1);
                        }
                    }
                    line.Chars_RemoveRange(0, deletedI.Length);
                    line.Chars_InsertRange(0, chars);
                    int delta = chars.Count - deletedI.Length;
                    iterator.InvalidateCurrentText(delta);
                    deleted[k++] = new Memento(deletedI, chars.Count);
                    while (iPart < parts.Length)
                    {
                        SelectionPart part           = parts[iPart];
                        Selection     selection      = selections[part.index];
                        int           selectionValue = part.isCaret ? selection.caret : selection.anchor;
                        if (delta < 0 && selectionValue - lineStart >= 0 && selectionValue - lineStart < -delta)
                        {
                            selectionValue = lineStart;
                        }
                        else if (selectionValue >= lineStart)
                        {
                            break;
                        }
                        if (part.isCaret)
                        {
                            selection.caret = selectionValue + offset;
                        }
                        else
                        {
                            selection.anchor = selectionValue + offset;
                        }
                        iPart++;
                    }
                    offset    += delta;
                    lineStart += oldCount;
                }
            }
            while (iPart < parts.Length)
            {
                SelectionPart part = parts[iPart++];
                if (part.isCaret)
                {
                    selections[part.index].caret += offset;
                }
                else
                {
                    selections[part.index].anchor += offset;
                }
            }
            lines.ResetTextCache();
        }