diff --git a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs index 59afb3d720..81202a53ae 100644 --- a/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs +++ b/src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDocumentEditor.cs @@ -56,7 +56,7 @@ namespace ICSharpCode.WixBinding WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region); using (textEditor.Document.OpenUndoGroup()) { - + // Replace the original xml with the new xml and indent it. int originalLineCount = document.TotalNumberOfLines; int initialIndent = GetIndent(region.BeginLine); @@ -66,14 +66,12 @@ namespace ICSharpCode.WixBinding // Indent the xml. int insertedCharacterCount = IndentAllLinesTheSame(region.BeginLine + 1, region.EndLine + addedLineCount, initialIndent); - // Select the text just inserted. - int textInsertedLength = insertedCharacterCount + xml.Length; - textEditor.Select(segment.Offset, textInsertedLength); - // Make sure the text inserted is visible. textEditor.JumpTo(region.BeginLine + 1, 1); - textEditor.Caret.Position = document.OffsetToPosition(segment.Offset + textInsertedLength); + // Select the text just inserted. + int textInsertedLength = insertedCharacterCount + xml.Length; + textEditor.Select(segment.Offset, textInsertedLength); } } @@ -103,17 +101,15 @@ namespace ICSharpCode.WixBinding // Indent the xml. int insertedCharacterCount = IndentLines(line, line + addedLineCount, initialIndent); - // Select the text just inserted. - int textInsertedLength = xml.Length + insertedCharacterCount; - textEditor.Select(offset, textInsertedLength); - // Make sure the text inserted is visible. textEditor.JumpTo(line + 1, 1); - textEditor.Caret.Position = document.OffsetToPosition(offset + textInsertedLength); + // Select the text just inserted. + int textInsertedLength = xml.Length + insertedCharacterCount; + textEditor.Select(offset, textInsertedLength); } } - + /// /// Indents the lines and returns the total number of extra characters added. /// @@ -137,7 +133,7 @@ namespace ICSharpCode.WixBinding for (int i = begin; i <= end; ++i) { totalInsertedCharacters += IndentLine(i, indent); } - return totalInsertedCharacters; + return totalInsertedCharacters; } /// diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertTextTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertTextTestFixture.cs index 4615eb7534..ed643b24d6 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertTextTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorInsertTextTestFixture.cs @@ -86,15 +86,6 @@ namespace WixBinding.Tests.Gui Assert.AreEqual(expectedText, textEditor.SelectedText); } - [Test] - public void CursorAtEndOfSelectedText() - { - int col = 2; - int line = 5; - Location expectedLocation = new Location(col, line); - Assert.AreEqual(expectedLocation, textEditor.Caret.Position); - } - [Test] public void InsertCanBeUndoneInOneStep() { diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceTextTestFixture.cs b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceTextTestFixture.cs index d9a937398d..6dd4811cb3 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceTextTestFixture.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Gui/WixDocumentEditorReplaceTextTestFixture.cs @@ -94,15 +94,6 @@ namespace WixBinding.Tests.Gui Assert.AreEqual(expectedText, textEditor.SelectedText); } - [Test] - public void CursorAtEndOfSelectedText() - { - int col = 14; - int line = 3; - Location expectedLocation = new Location(col, line); - Assert.AreEqual(expectedLocation, textEditor.Caret.Position); - } - [Test] public void InsertCanBeUndoneInOneStep() { diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs index d748351672..bece80d64f 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/MockTextEditor.cs @@ -140,7 +140,8 @@ namespace WixBinding.Tests.Utils public void JumpTo(int line, int column) { locationJumpedTo = new Location(column, line); - } + selection = new SimpleSelection(-1, -1); + } public Location LocationJumpedTo { get { return locationJumpedTo; } diff --git a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockTextEditorTests.cs b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockTextEditorTests.cs index e2f65e51be..25810f936d 100644 --- a/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockTextEditorTests.cs +++ b/src/AddIns/BackendBindings/WixBinding/Test/Utils/Tests/MockTextEditorTests.cs @@ -116,5 +116,17 @@ namespace WixBinding.Tests.Utils.Tests Assert.AreEqual("abc-replaced-ghi", textEditor.Document.Text); } + + [Test] + public void NoTextSelectedAfterJumpToMethodIsCalled() + { + int offset = 1; + int length = 2; + textEditor.Document.Text = "test\r\nsecond line"; + textEditor.Select(offset, length); + textEditor.JumpTo(2, 1); + + Assert.AreEqual(String.Empty, textEditor.SelectedText); + } } }