public int UnComment(TextDocument textDocument, ISegment segment, int caret = -1, bool format = true)
        {
            var result = caret;

            var lines = VisualLineGeometryBuilder.GetLinesForSegmentInDocument(textDocument, segment);

            textDocument.BeginUpdate();

            foreach (var line in lines)
            {
                var index = textDocument.GetText(line).IndexOf("//");

                if (index >= 0)
                {
                    textDocument.Replace(line.Offset + index, 2, string.Empty);
                }
            }

            if (format)
            {
                result = Format(textDocument, (uint)segment.Offset, (uint)segment.Length, caret);
            }

            textDocument.EndUpdate();

            return(result);
        }
        public int UnComment(TextDocument textDocument, int firstLine, int endLine, int caret = -1, bool format = true)
        {
            var result = caret;

            textDocument.BeginUpdate();

            for (int line = firstLine; line <= endLine; line++)
            {
                var docLine = textDocument.GetLineByNumber(line);
                var index   = textDocument.GetText(docLine).IndexOf("//");

                if (index >= 0)
                {
                    textDocument.Replace(docLine.Offset + index, 2, string.Empty);
                }
            }

            textDocument.EndUpdate();

            if (format)
            {
                var startOffset = textDocument.GetLineByNumber(firstLine).Offset;
                var endOffset   = textDocument.GetLineByNumber(endLine).EndOffset;
                result = Format(textDocument, (uint)startOffset, (uint)(endOffset - startOffset), caret);
            }

            return(result);
        }
示例#3
0
 public TextDocumentWriter(TextDocument doc)
 {
     _doc = doc;
     _doc.BeginUpdate();
     _undoStackSize           = doc.UndoStack.SizeLimit;
     _doc.UndoStack.SizeLimit = 0;
     _i = _doc.TextLength;
 }
        public static int ApplyReplacements(TextDocument document, int cursor, XDocument replacements)
        {
            var elements = replacements.Elements().First().Elements();

            document.BeginUpdate();

            var offsetChange = 0;

            foreach (var element in elements)
            {
                switch (element.Name.LocalName)
                {
                case "cursor":
                    cursor = Convert.ToInt32(element.Value);
                    break;

                case "replacement":
                    var offset            = -1;
                    var replacementLength = -1;
                    var attributes        = element.Attributes();

                    foreach (var attribute in attributes)
                    {
                        switch (attribute.Name.LocalName)
                        {
                        case "offset":
                            offset = Convert.ToInt32(attribute.Value);
                            break;

                        case "length":
                            replacementLength = Convert.ToInt32(attribute.Value);
                            break;
                        }
                    }

                    if (offset >= document.TextLength)
                    {
                        //document.Insert(offset, element.Value);
                    }
                    if (offset + replacementLength > document.TextLength)
                    {
                        //document.Replace(offset, document.TextLength - offset, element.Value);
                    }
                    else
                    {
                        document.Replace(offsetChange + offset, replacementLength, element.Value);
                    }

                    offsetChange += element.Value.Length - replacementLength;
                    break;
                }
            }

            document.EndUpdate();

            return(cursor);
        }
示例#5
0
        public void Nested_Batch_Document_Changes_Should_Invalidate_Lines()
        {
            TextView     textView = new TextView();
            TextDocument document = new TextDocument();

            using var textEditorModel = new TextEditorModel(
                      textView, document, null);

            document.Text = "puppy\npuppy\npuppy";

            document.BeginUpdate();

            document.Insert(0, "*");
            Assert.AreEqual(0, textEditorModel.InvalidRange.StartLine,
                            "Wrong InvalidRange.StartLine 1");
            Assert.AreEqual(0, textEditorModel.InvalidRange.EndLine,
                            "Wrong InvalidRange.EndLine 1");

            document.BeginUpdate();
            document.Insert(7, "*");
            Assert.AreEqual(0, textEditorModel.InvalidRange.StartLine,
                            "Wrong InvalidRange.StartLine 2");
            Assert.AreEqual(1, textEditorModel.InvalidRange.EndLine,
                            "Wrong InvalidRange.EndLine 2");

            document.Insert(14, "*");
            Assert.AreEqual(0, textEditorModel.InvalidRange.StartLine,
                            "Wrong InvalidRange.StartLine 3");
            Assert.AreEqual(2, textEditorModel.InvalidRange.EndLine,
                            "Wrong InvalidRange.EndLine 3");

            document.EndUpdate();
            Assert.IsNotNull(textEditorModel.InvalidRange,
                             "InvalidRange should not be null");
            document.EndUpdate();
            Assert.IsNull(textEditorModel.InvalidRange,
                          "InvalidRange should be null");

            Assert.AreEqual("*puppy", textEditorModel.GetLineText(0));
            Assert.AreEqual("*puppy", textEditorModel.GetLineText(1));
            Assert.AreEqual("*puppy", textEditorModel.GetLineText(2));
        }
示例#6
0
 public void IndentLines(TextDocument document, int beginLine, int endLine)
 {
     _doBeginUpdateManually = true;
     document.BeginUpdate();
     while (beginLine <= endLine)
     {
         IndentLine(document, document.GetLineByNumber(beginLine));
         beginLine++;
     }
     document.EndUpdate();
     _doBeginUpdateManually = false;
 }
示例#7
0
        public void RawlyIndentLine(int tabsToInsert, TextDocument document, DocumentLine line)
        {
            if (!_doBeginUpdateManually)
            {
                document.BeginUpdate();
            }

            /*
             * 1) Remove old indentation
             * 2) Insert new one
             */

            // 1)
            int prevInd = 0;
            int curOff  = line.Offset;

            if (curOff < document.TextLength)
            {
                char curChar = '\0';
                while (curOff < document.TextLength && ((curChar = document.GetCharAt(curOff)) == ' ' || curChar == '\t'))
                {
                    prevInd++;
                    curOff++;
                }

                document.Remove(line.Offset, prevInd);
            }

            // 2)
            string indentString = "";

            for (int i = 0; i < tabsToInsert; i++)
            {
                indentString += dEditor.Editor.Options.IndentationString;
            }

            document.Insert(line.Offset, indentString);
            if (!_doBeginUpdateManually)
            {
                document.EndUpdate();
            }
        }
        public int Comment(TextDocument textDocument, int firstLine, int endLine, int caret = -1, bool format = true)
        {
            var result = caret;

            textDocument.BeginUpdate();

            for (int line = firstLine; line <= endLine; line++)
            {
                textDocument.Insert(textDocument.GetLineByNumber(line).Offset, "//");
            }

            textDocument.EndUpdate();

            if (format)
            {
                var startOffset = textDocument.GetLineByNumber(firstLine).Offset;
                var endOffset   = textDocument.GetLineByNumber(endLine).EndOffset;
                result = Format(textDocument, (uint)startOffset, (uint)(endOffset - startOffset), caret);
            }

            return(result);
        }
        public int Comment(TextDocument textDocument, ISegment segment, int caret = -1, bool format = true)
        {
            var result = caret;

            var lines = VisualLineGeometryBuilder.GetLinesForSegmentInDocument(textDocument, segment);

            textDocument.BeginUpdate();

            foreach (var line in lines)
            {
                textDocument.Insert(line.Offset, "//");
            }

            if (format)
            {
                result = Format(textDocument, (uint)segment.Offset, (uint)segment.Length, caret);
            }

            textDocument.EndUpdate();

            return(result);
        }
示例#10
0
        private void HandleTextInput(string input)
        {
            InvalidateSelectedWord();

            if (!string.IsNullOrEmpty(input))
            {
                TextDocument.BeginUpdate();

                DeleteSelection();

                var caretIndex = CaretIndex;

                if (caretIndex >= 0)
                {
                    TextDocument.Insert(caretIndex, input);
                    CaretIndex    += input.Length;
                    SelectionStart = SelectionEnd = CaretIndex;
                    TextView.Invalidate();
                }

                TextDocument.EndUpdate();
            }
        }
示例#11
0
        private void TransformSelectedLines(Action <IDocumentLine> transformLine)
        {
            var selection = GetSelectionAsSegment();
            var lines     = VisualLineGeometryBuilder.GetLinesForSegmentInDocument(TextDocument, selection);

            if (lines.Count() > 0)
            {
                var anchors = new TextSegmentCollection <TextSegment>(TextDocument);

                anchors.Add(selection);

                TextDocument.BeginUpdate();

                foreach (var line in lines)
                {
                    transformLine(line);
                }

                TextDocument.EndUpdate();

                SetSelection(selection);
            }
        }
示例#12
0
 public void StartUndoableAction()
 {
     document.BeginUpdate();
 }
示例#13
0
 public void BeginUpdate()
 {
     Document.BeginUpdate();
 }