public void Sections() { string content = @"# NAME1 ----- x <- 1 # NAME2 ----- "; TextBufferMock textBuffer = null; int calls = 0; OutlineRegionsChangedEventArgs args = null; textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); using (var tree = new EditorTree(textBuffer, _editorShell)) { tree.Build(); using (var editorDocument = new EditorDocumentMock(tree)) { using (var ob = new ROutlineRegionBuilder(editorDocument, _editorShell)) { var rc1 = new OutlineRegionCollection(0); ob.BuildRegions(rc1); rc1.Should().HaveCount(2); rc1[0].DisplayText.Should().Be("# NAME1"); rc1[1].DisplayText.Should().Be("# NAME2"); rc1[0].Length.Should().Be(21); rc1[1].Length.Should().Be(13); ob.RegionsChanged += (s, e) => { calls++; args = e; }; textBuffer.Insert(2, "A"); editorDocument.EditorTree.EnsureTreeReady(); // Wait for background/idle tasks to complete var start = DateTime.Now; while (calls == 0 && (DateTime.Now - start).TotalMilliseconds < 2000) { _editorShell.DoIdle(); } calls.Should().Be(1); args.Should().NotBeNull(); args.ChangedRange.Start.Should().Be(0); args.ChangedRange.End.Should().Be(textBuffer.CurrentSnapshot.Length); args.Regions.Should().HaveCount(2); args.Regions[0].DisplayText.Should().Be("# ANAME1"); args.Regions[1].DisplayText.Should().Be("# NAME2"); args.Regions[0].Length.Should().Be(22); args.Regions[1].Length.Should().Be(13); } } } }
public IEditorScript DoIdle(int ms = 100) { for (var i = 0; i < ms; i += 20) { _editorShell.DoIdle(); UIThreadHelper.Instance.DoEvents(20); } return(this); }