Beispiel #1
0
        public static EditorTree ApplyTextChange(string expression, int start, int oldLength, int newLength, string newText)
        {
            TextBufferMock textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType);

            EditorTree tree = new EditorTree(textBuffer);

            tree.Build();

            TextChange tc = new TextChange();

            tc.OldRange        = new TextRange(start, oldLength);
            tc.NewRange        = new TextRange(start, newLength);
            tc.OldTextProvider = new TextProvider(textBuffer.CurrentSnapshot);

            if (oldLength == 0 && newText.Length > 0)
            {
                textBuffer.Insert(start, newText);
            }
            else if (oldLength > 0 && newText.Length > 0)
            {
                textBuffer.Replace(new Span(start, oldLength), newText);
            }
            else
            {
                textBuffer.Delete(new Span(start, oldLength));
            }

            return(tree);
        }
Beispiel #2
0
        public static EditorTree ApplyTextChange(IServiceContainer services, string expression, int start, int oldLength, int newLength, string newText)
        {
            var textBuffer = new TextBufferMock(expression, RContentTypeDefinition.ContentType).ToEditorBuffer();
            var tree       = new EditorTree(textBuffer, services);

            tree.Build();

            if (oldLength == 0 && newText.Length > 0)
            {
                textBuffer.Insert(start, newText);
            }
            else if (oldLength > 0 && newText.Length > 0)
            {
                textBuffer.Replace(new TextRange(start, oldLength), newText);
            }
            else
            {
                textBuffer.Delete(new TextRange(start, oldLength));
            }

            return(tree);
        }