SetSelection() public method

Clears the selection and sets a new selection using the given ISelection object.
public SetSelection ( ISelection selection ) : void
selection ISelection
return void
		/// <summary>
		/// Selects the specified text range.
		/// </summary>
		static void SelectText(SelectionManager selectionManager, IDocument document, int startOffset, int length)
		{
			selectionManager.ClearSelection();
			TextLocation selectionStart = document.OffsetToPosition(startOffset);
			TextLocation selectionEnd = document.OffsetToPosition(startOffset + length);
			selectionManager.SetSelection(selectionStart, selectionEnd);
		}
        public void CharacterSelectStart()
        {
            const string TextMessage = "char[] validChars = new char[] {'\"', '|(', '<', '{', '['};";
            int offset;
            IDocument document = TestHelper.MakeDocument(TextMessage, out offset);

            ISelection selection = new SingleWordSelection(document, offset);
            SelectionManager selectionManager = new SelectionManager(document);
            selectionManager.SetSelection(selection);
            Assert.AreEqual("(", selectionManager.SelectedText);
        }
        public void Decrease_text_select_with_qoutes_to_only_word()
        {
            // Arrange
            const string textMessage = "\"|Hello World!\"";
            int offset;
            IDocument document = TestHelper.MakeDocument(textMessage, out offset);
            ISelection selection = new SingleWordSelection(document, offset);
            SelectionManager selectionManager = new SelectionManager(document);
            selectionManager.SetSelection(selection.StartPosition, selection.EndPosition);

            selection = new ExtendBlockSelection(document, selection);
            selectionManager.SetSelection(selection.StartPosition, selection.EndPosition);
            Assert.AreEqual("\"Hello World!\"", selectionManager.SelectedText);

            // Act
            selection = new DecreaseSelection(document, selection);
            selectionManager.SetSelection(selection);

            // Arrange
            Assert.AreEqual("Hello World!", selectionManager.SelectedText);
        }
        public void CursorAtEndOfWord23423()
        {
            const string TextMessage = "\"|Hello World\"";
            int offset;
            IDocument document = TestHelper.MakeDocument(TextMessage, out offset);

            ISelection selection = new SingleWordSelection(document, offset);
            SelectionManager selectionManager = new SelectionManager(document);
            selectionManager.SetSelection(selection);

            Assert.AreEqual("Hello", selectionManager.SelectedText);
            TestHelper.CallAllProperties(selection);
        }
        public void CursorAtEndOfWord()
        {
            const string TextMessage = "using(WorkflowRuntime| workflowRuntime = new WorkflowRuntime())";
            int offset;
            IDocument document = TestHelper.MakeDocument(TextMessage, out offset);

            ISelection selection = new SingleWordSelection(document, offset);
            SelectionManager selectionManager = new SelectionManager(document);
            selectionManager.SetSelection(selection);

            Assert.AreEqual("WorkflowRuntime", selectionManager.SelectedText);
            TestHelper.CallAllProperties(selection);
        }
        public void WordCloseToDot()
        {
            const string TextMessage = "char answer = Console|.ReadKey().KeyChar;";
            int offset;
            IDocument document = TestHelper.MakeDocument(TextMessage, out offset);

            ISelection selection = new SingleWordSelection(document, offset);
            SelectionManager selectionManager = new SelectionManager(document);
            selectionManager.SetSelection(selection);
            Assert.AreEqual("Console", selectionManager.SelectedText);

            offset += 1;
            selection = new SingleWordSelection(document, offset);
            selectionManager.SetSelection(selection);
            Assert.AreEqual("ReadKey", selectionManager.SelectedText);
            TestHelper.CallAllProperties(selection);
        }
        public void SelectNerestWord()
        {
            const string TextMessage = "\tIs |the bug fixed?";
            int offset;
            IDocument document = TestHelper.MakeDocument(TextMessage, out offset);

            ISelection selection = new SingleWordSelection(document, offset);
            SelectionManager selectionManager = new SelectionManager(document);
            selectionManager.SetSelection(selection);
            Assert.AreEqual("the", selectionManager.SelectedText);

            offset--;
            selection = new SingleWordSelection(document, offset);
            selectionManager.SetSelection(selection);
            Assert.AreEqual("Is", selectionManager.SelectedText);
            TestHelper.CallAllProperties(selection);
        }
        public void NullDocument()
        {
            const string TextMessage = null;
            IDocument document = TestHelper.MakeDocument(TextMessage);
            int offset = 21;
            ISelection selection = new SingleWordSelection(document, offset);
            SelectionManager selectionManager = new SelectionManager(document);
            selectionManager.SetSelection(selection);
            Assert.IsEmpty(selectionManager.SelectedText);
            TestHelper.CallAllProperties(selection);

            offset = -2;
            selection = new SingleWordSelection(document, offset);
            selectionManager.SetSelection(selection);
            Assert.IsEmpty(selectionManager.SelectedText);
            TestHelper.CallAllProperties(selection);
        }
        public void NoSelectionOffsetEndOfDocument()
        {
            const string TextMessage = "using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())\n\n\n";
            IDocument document = TestHelper.MakeDocument(TextMessage);
            int offset = 240;
            ISelection selection = new SingleWordSelection(document, offset);
            SelectionManager selectionManager = new SelectionManager(document);
            selectionManager.SetSelection(selection);

            Assert.IsTrue(selection.IsEmpty);
            Assert.IsEmpty(selectionManager.SelectedText);
            TestHelper.CallAllProperties(selection);
        }
        public void CursorPositionBeforeText()
        {
            const string TextMessage = "\rusing(WorkflowRuntime workflowRuntime = new WorkflowRuntime())";
            IDocument document = TestHelper.MakeDocument(TextMessage);
            int offset = -1;
            ISelection selection = new SingleWordSelection(document, offset);
            SelectionManager selectionManager = new SelectionManager(document);
            selectionManager.SetSelection(selection);

            Assert.AreEqual("using", selectionManager.SelectedText);
            TestHelper.CallAllProperties(selection);
        }
        public void CursorBeforeQuotationMark()
        {
            const string TextMessage = "\"hello there|\"";
            int offset;
            IDocument document = TestHelper.MakeDocument(TextMessage, out offset);

            ISelection selection = new SingleWordSelection(document, offset);
            SelectionManager selectionManager = new SelectionManager(document);
            selectionManager.SetSelection(selection);

            Assert.AreEqual("there", selectionManager.SelectedText);
            TestHelper.CallAllProperties(selection);
        }