public void TestProjectionUpdate ()
		{
			var editor = TextEditorFactory.CreateNewEditor ();
			editor.Text = "1234567890";

			var projectedDocument = TextEditorFactory.CreateNewDocument (
				new StringTextSource ("__12__34__56__78__90"),
				"a"
			);

			var segments = new List<ProjectedSegment> ();
			for (int i = 0; i < 5; i++) {
				segments.Add (new ProjectedSegment (i * 2, 2 + i * 4, 2));
			}
			var projection = new Projection.Projection (projectedDocument, segments);
			var tww = new TestWorkbenchWindow ();
			var content = new TestViewContent ();
			tww.ViewContent = content;

			var originalContext = new Document (tww);
			var projectedEditor = projection.CreateProjectedEditor (originalContext);
			editor.SetOrUpdateProjections (originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.All);
			editor.InsertText (1, "foo");
			Assert.AreEqual ("__1foo2__34__56__78__90", projectedEditor.Text);

			Assert.AreEqual (2, projection.ProjectedSegments.ElementAt (0).ProjectedOffset);
			Assert.AreEqual (2 + "foo".Length, projection.ProjectedSegments.ElementAt (0).Length);
			for (int i = 1; i < 5; i++) {
				Assert.AreEqual (2 + i * 4 + "foo".Length, projection.ProjectedSegments.ElementAt (i).ProjectedOffset);
				Assert.AreEqual (2, projection.ProjectedSegments.ElementAt (i).Length);
			}
		}
Example #2
0
        public void TestProjectionCompletion()
        {
            var editor  = TextEditorFactory.CreateNewEditor();
            var options = new CustomEditorOptions(editor.Options);

            options.EditorTheme = "Tango";
            editor.Options      = options;
            editor.Text         = "12345678901234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var tww        = new TestWorkbenchWindow();
            var content    = new TestViewContent();

            tww.ViewContent = content;

            var originalContext = new Document(tww);
            var projectedEditor = projection.CreateProjectedEditor(originalContext);
            TestCompletionExtension orignalExtension;

            editor.SetExtensionChain(originalContext, new [] { orignalExtension = new TestCompletionExtension(editor)
                                                               {
                                                                   CompletionWidget = new EmptyCompletionWidget(editor)
                                                               } });
            TestCompletionExtension projectedExtension;

            projectedEditor.SetExtensionChain(originalContext, new [] { projectedExtension = new TestCompletionExtension(editor)
                                                                        {
                                                                            CompletionWidget = new EmptyCompletionWidget(projectedEditor)
                                                                        } });

            editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None);
            editor.CaretOffset = 1;

            var service = new CommandManager();

            service.LoadCommands("/MonoDevelop/Ide/Commands");
            service.DispatchCommand(TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter);
            Assert.IsFalse(orignalExtension.CompletionRun);
            Assert.IsTrue(projectedExtension.CompletionRun);

            editor.CaretOffset = 15;
            CompletionWindowManager.HideWindow();
            service.DispatchCommand(TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter);
            Assert.IsTrue(orignalExtension.CompletionRun);
        }
Example #3
0
        public void TestProjectionUpdate()
        {
            var editor = TextEditorFactory.CreateNewEditor();

            editor.Text = "1234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var tww        = new TestWorkbenchWindow();
            var content    = new TestViewContent();

            tww.ViewContent = content;

            var originalContext = new Document(tww);

            using (var testCase = new TextEditorExtensionTestCase(originalContext, content, tww, null, false)) {
                var projectedEditor = projection.CreateProjectedEditor(originalContext);
                editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.All);
                editor.InsertText(1, "foo");
                Assert.AreEqual("__1foo2__34__56__78__90", projectedEditor.Text);

                Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(0).ProjectedOffset);
                Assert.AreEqual(2 + "foo".Length, projection.ProjectedSegments.ElementAt(0).Length);
                for (int i = 1; i < 5; i++)
                {
                    Assert.AreEqual(2 + i * 4 + "foo".Length, projection.ProjectedSegments.ElementAt(i).ProjectedOffset);
                    Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(i).Length);
                }
            }
        }
Example #4
0
        public void TestProjectionHighlighting()
        {
            var editor  = TextEditorFactory.CreateNewEditor();
            var options = new CustomEditorOptions(editor.Options);

            options.EditorTheme = "Tango";
            editor.Options      = options;
            editor.Text         = "1234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var tww        = new TestWorkbenchWindow();
            var content    = new TestViewContent();

            tww.ViewContent = content;

            var originalContext = new Document(tww);

            using (var testCase = new TextEditorExtensionTestCase(originalContext, content, tww, null, false)) {
                var projectedEditor = projection.CreateProjectedEditor(originalContext);
                projectedEditor.SemanticHighlighting = new TestSemanticHighlighting(projectedEditor, originalContext);
                editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None);

                var markup = editor.GetMarkup(0, editor.Length, new MarkupOptions(MarkupFormat.Pango));
                var color  = "#3363a4";
                Assert.AreEqual("<span foreground=\"" + color + "\">1</span><span foreground=\"#222222\">234</span><span foreground=\"" + color + "\">5</span><span foreground=\"#222222\">678</span><span foreground=\"" + color + "\">9</span><span foreground=\"#222222\">0</span>", markup);
            }
        }
        public async Task TestProjectionUpdate()
        {
            var editor = TextEditorFactory.CreateNewEditor();

            editor.Text = "1234567890";

            var projectedDocument = TextEditorFactory.CreateNewDocument(
                new StringTextSource("__12__34__56__78__90"),
                "a"
                );

            var segments = new List <ProjectedSegment> ();

            for (int i = 0; i < 5; i++)
            {
                segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2));
            }
            var projection = new Projection.Projection(projectedDocument, segments);
            var content    = new TestViewContent();
            await content.Initialize(new FileDescriptor ("Foo.cs", null, null));

            using (var testCase = await TextEditorExtensionTestCase.Create(content, null, false)) {
                var originalContext = testCase.Document.DocumentContext;
                var projectedEditor = projection.CreateProjectedEditor(originalContext);
                editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.All);
                editor.InsertText(1, "foo");
                Assert.AreEqual("__1foo2__34__56__78__90", projectedEditor.Text);

                Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(0).ProjectedOffset);
                Assert.AreEqual(2 + "foo".Length, projection.ProjectedSegments.ElementAt(0).Length);
                for (int i = 1; i < 5; i++)
                {
                    Assert.AreEqual(2 + i * 4 + "foo".Length, projection.ProjectedSegments.ElementAt(i).ProjectedOffset);
                    Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(i).Length);
                }
            }
        }
		public void TestProjectionHighlighting ()
		{
			var editor = TextEditorFactory.CreateNewEditor ();
			var options = new CustomEditorOptions (editor.Options);
			options.ColorScheme = "Tango";
			editor.Options = options;
			editor.Text = "1234567890";

			var projectedDocument = TextEditorFactory.CreateNewDocument (
				new StringTextSource ("__12__34__56__78__90"),
				"a"
			);

			var segments = new List<ProjectedSegment> ();
			for (int i = 0; i < 5; i++) {
				segments.Add (new ProjectedSegment (i * 2, 2 + i * 4, 2));
			}
			var projection = new Projection.Projection (projectedDocument, segments);
			var tww = new TestWorkbenchWindow ();
			var content = new TestViewContent ();
			tww.ViewContent = content;

			var originalContext = new Document (tww);
			var projectedEditor = projection.CreateProjectedEditor (originalContext);
			projectedEditor.SemanticHighlighting = new TestSemanticHighlighting (projectedEditor, originalContext);
			editor.SetOrUpdateProjections (originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None);

			var markup = editor.GetPangoMarkup (0, editor.Length);
			var color = "#75507B";
			Assert.AreEqual ("<span foreground=\"" + color + "\">1</span><span foreground=\"#222222\">234</span><span foreground=\"" + color + "\">5</span><span foreground=\"#222222\">678</span><span foreground=\"" + color + "\">9</span><span foreground=\"#222222\">0</span>", markup);
		}
		public void TestProjectionCompletion ()
		{
			var editor = TextEditorFactory.CreateNewEditor ();
			var options = new CustomEditorOptions (editor.Options);
			options.ColorScheme = "Tango";
			editor.Options = options;
			editor.Text = "12345678901234567890";

			var projectedDocument = TextEditorFactory.CreateNewDocument (
				new StringTextSource ("__12__34__56__78__90"),
				"a"
			);

			var segments = new List<ProjectedSegment> ();
			for (int i = 0; i < 5; i++) {
				segments.Add (new ProjectedSegment (i * 2, 2 + i * 4, 2));
			}
			var projection = new Projection.Projection (projectedDocument, segments);
			var tww = new TestWorkbenchWindow ();
			var content = new TestViewContent ();
			tww.ViewContent = content;

			var originalContext = new Document (tww);
			var projectedEditor = projection.CreateProjectedEditor (originalContext);
			TestCompletionExtension orignalExtension;
			editor.SetExtensionChain (originalContext, new [] { orignalExtension = new TestCompletionExtension (editor) });
			TestCompletionExtension projectedExtension;
			projectedEditor.SetExtensionChain (originalContext, new [] { projectedExtension = new TestCompletionExtension (editor) });

			orignalExtension.CompletionWidget = new EmptyCompletionWidget (editor);
			projectedExtension.CompletionWidget = new EmptyCompletionWidget (projectedEditor);

			editor.SetOrUpdateProjections (originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None);
			editor.CaretOffset = 1;

			var service = new CommandManager ();
			service.LoadCommands ("/MonoDevelop/Ide/Commands");
			service.DispatchCommand (TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter);
			Assert.IsFalse (orignalExtension.CompletionRun);
			Assert.IsTrue (projectedExtension.CompletionRun);

			editor.CaretOffset = 15;

			service.DispatchCommand (TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter);
			Assert.IsTrue (orignalExtension.CompletionRun);
		}