コード例 #1
0
        public void InsertAtEnd()
        {
            var text = "Hello World";
            var doc  = new PlainTextDocument();

            doc.InsertAt(0, text);
            doc.InsertAt(doc.TextLength, " More");
            doc.TextAt(0, doc.TextLength).Should().Be("Hello World More");
            doc.Root.Count.Should().Be(1);
            doc.Root.Offset.Should().Be(0);
            doc.Root.EndOffset.Should().Be(16);
        }
コード例 #2
0
        public void EditDocument()
        {
            var doc = new PlainTextDocument();

            doc.InsertAt(0, "A");
            doc.Root.Offset.Should().Be(0);
            doc.Root.EndOffset.Should().Be(1);
            doc.DeleteAt(0, doc.TextLength);
            doc.Root.Offset.Should().Be(0);
            doc.Root.EndOffset.Should().Be(0);
            doc.InsertAt(0, "B");
            doc.Root.Offset.Should().Be(0);
            doc.Root.EndOffset.Should().Be(1);
        }
コード例 #3
0
        public void AppendToLineBreaksAtEndOfLine()
        {
            var text = "Hello World\n";
            var doc  = new PlainTextDocument();

            doc.InsertAt(0, text);
            doc.InsertAt(doc.TextLength, " More");
            doc.TextAt(0, doc.TextLength).Should().Be(text + " More");
            doc.Root.Offset.Should().Be(0);
            doc.Root.EndOffset.Should().Be(17);
            doc.Root.Count.Should().Be(2);
            doc.Root[0].Offset.Should().Be(0);
            doc.Root[0].EndOffset.Should().Be(12);
            doc.Root[1].Offset.Should().Be(12);
            doc.Root[1].EndOffset.Should().Be(17);
        }
コード例 #4
0
        public void InsertNewLine()
        {
            var doc = new PlainTextDocument();

            doc.InsertAt(0, "Hello World!");
            doc.Root.Offset.Should().Be(0);
            doc.Root.EndOffset.Should().Be(12);
            doc.Root.Count.Should().Be(1);
            doc.Root[0].Offset.Should().Be(0);
            doc.Root[0].EndOffset.Should().Be(12);

            doc.InsertAt(5, '\n');
            doc.Root.Count.Should().Be(2);
            doc.Root[0].Offset.Should().Be(0);
            doc.Root[0].EndOffset.Should().Be(6);
            doc.Root[1].Offset.Should().Be(6);
            doc.Root[1].EndOffset.Should().Be(13);
        }
コード例 #5
0
        public void InsertOrdinaryText()
        {
            var doc = new PlainTextDocument();

            doc.InsertAt(0, "Hello World");
            doc.TextAt(0, doc.TextLength).Should().Be("Hello World");
            doc.Root.Offset.Should().Be(0);
            doc.Root.EndOffset.Should().Be(11);
            doc.Root.Count.Should().Be(1);
        }
コード例 #6
0
        public void InsertWithLineBreaks()
        {
            var text = "Hello\nWorld";
            var doc  = new PlainTextDocument();

            doc.InsertAt(0, text);
            doc.Root.Offset.Should().Be(0);
            doc.Root.EndOffset.Should().Be(11);
            doc.Root.Count.Should().Be(2);
        }
コード例 #7
0
        ParagraphTextView <PlainTextDocument> CreateView(string text = null)
        {
            var doc = new PlainTextDocument();

            doc.InsertAt(0, text ?? "Hello World, Here I am. Long text ahead here. A long word, that is impossible to break apart.");
            var node = doc.Root[0];

            var view = new ParagraphTextView <PlainTextDocument>(node, textStyle, new PlainTextViewFactory());

            return(view);
        }
コード例 #8
0
        ParagraphTextView <PlainTextDocument> CreateView(string text)
        {
            var doc = new PlainTextDocument();

            doc.InsertAt(0, text);
            var node = doc.Root[0];

            var view = new ParagraphTextView <PlainTextDocument>(node, textStyle, new PlainTextViewFactory());

            return(view);
        }
コード例 #9
0
        public void RemoveAllText()
        {
            var text = "Hello World";
            var doc  = new PlainTextDocument();

            doc.InsertAt(0, text);
            doc.DeleteAt(0, text.Length);
            doc.TextAt(0, doc.TextLength).Should().Be("");
            doc.Root.Offset.Should().Be(0);
            doc.Root.EndOffset.Should().Be(0);
            doc.Root.Count.Should().Be(1);
        }
コード例 #10
0
        public void RemoveAcrossLineBreaks()
        {
            var text = "Hello World\n More";
            var doc  = new PlainTextDocument();

            doc.InsertAt(0, text);

            doc.DeleteAt(6, 7);
            doc.TextAt(0, doc.TextLength).Should().Be("Hello More");
            doc.Root.Offset.Should().Be(0);
            doc.Root.EndOffset.Should().Be(10);
            doc.Root.Count.Should().Be(1);
        }
コード例 #11
0
        BlockTextView <PlainTextDocument> CreateView(string text = null)
        {
            var doc = new PlainTextDocument();

            doc.InsertAt(0, text ?? "Hello World, Here I am. \nLong text ahead here. \nA long word, that is impossible to break apart.");

            var textStyle = LayoutTestStyle.CreateTextStyle(styleSystem);
            var factory   = new PlainTextViewFactory();
            var view      = new BlockTextView <PlainTextDocument>(doc.Root, textStyle);

            for (var i = 0; i < doc.Root.Count; i += 1)
            {
                view.Add(new ParagraphTextView <PlainTextDocument>(doc.Root[i], textStyle, factory));
            }
            return(view);
        }
コード例 #12
0
        public static TestDocumentView <PlainTextDocument> SetUp(Alignment alignment = Alignment.Start, string text = null)
        {
            var doc = new PlainTextDocument();

            doc.InsertAt(0, text ?? "Hello World, Here I am. Long text ahead here. This is the first paragraph.\nAfter a line break, we should see a second paragraph in the document.");

            var style      = LayoutTestStyle.Create();
            var textStyles = style.StyleSystem.StylesFor <TextStyleDefinition>();

            var documentView = new TestDocumentView <PlainTextDocument>(new PlainTextDocumentEditor(style));

            documentView.Style.SetValue(textStyles.Alignment, alignment);
            documentView.Style.SetValue(textStyles.Font, style.Style.MediumFont);
            documentView.Document = doc;

            style.StyleResolver.AddRoot(documentView);

            return(documentView);
        }
コード例 #13
0
        TextChunkView <PlainTextDocument> CreateChunk(int?start = null, int?end = null, string text = null)
        {
            var doc = new PlainTextDocument();

            doc.InsertAt(0, text ?? "Hello World, Here I am. Can you see me? This is on the next line.");
            var node = doc.Root[0];

            var startOffset = start ?? node.Offset;
            var endOffset   = end ?? node.EndOffset;

            var chunk = new TextChunkView <PlainTextDocument>(
                new TextProcessingRules(),
                node,
                textStyle,
                node.Document.CreatePosition(startOffset, Bias.Forward),
                node.Document.CreatePosition(endOffset, Bias.Backward));

            chunk.Initialize();
            return(chunk);
        }