Browse Source

Fixed SD2-1127. Can now comment out a region of text between two existing block comments.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2300 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
c2ac5dad22
  1. 16
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs
  2. 17
      src/Libraries/ICSharpCode.TextEditor/Test/BlockCommentTests.cs

16
src/Libraries/ICSharpCode.TextEditor/Project/Src/Actions/MiscActions.cs

@ -440,8 +440,10 @@ namespace ICSharpCode.TextEditor.Actions @@ -440,8 +440,10 @@ namespace ICSharpCode.TextEditor.Actions
commentEndOffset += selectionStartOffset;
}
// Find start of comment before selected text.
// Find start of comment before or partially inside the
// selected text.
int commentEndBeforeStartOffset = -1;
if (commentStartOffset == -1) {
int offset = selectionEndOffset + commentStart.Length - 1;
if (offset > document.TextLength) {
@ -449,9 +451,17 @@ namespace ICSharpCode.TextEditor.Actions @@ -449,9 +451,17 @@ namespace ICSharpCode.TextEditor.Actions
}
string text = document.GetText(0, offset);
commentStartOffset = text.LastIndexOf(commentStart);
if (commentStartOffset >= 0) {
// Find end of comment before comment start.
commentEndBeforeStartOffset = text.IndexOf(commentEnd, commentStartOffset, selectionStartOffset - commentStartOffset);
if (commentEndBeforeStartOffset > commentStartOffset) {
commentStartOffset = -1;
}
}
}
// Find end of comment after selected text.
// Find end of comment after or partially after the
// selected text.
if (commentEndOffset == -1) {
int offset = selectionStartOffset + 1 - commentEnd.Length;
@ -460,7 +470,7 @@ namespace ICSharpCode.TextEditor.Actions @@ -460,7 +470,7 @@ namespace ICSharpCode.TextEditor.Actions
}
string text = document.GetText(offset, document.TextLength - offset);
commentEndOffset = text.IndexOf(commentEnd);
if (commentEndOffset >= 0) {
if (commentEndOffset >= 0) {
commentEndOffset += offset;
}
}

17
src/Libraries/ICSharpCode.TextEditor/Test/BlockCommentTests.cs

@ -143,5 +143,22 @@ namespace ICSharpCode.TextEditor.Tests @@ -143,5 +143,22 @@ namespace ICSharpCode.TextEditor.Tests
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.IsNull(commentRegion);
}
[Test]
public void TwoExistingBlockComments()
{
document.TextContent = "<a>\r\n" +
"<!--<b></b>-->\r\n" +
"\t<c></c>\r\n" +
"<!--<d></d>-->\r\n" +
"</a>";
string selectedText = "<c></c>";
int selectionStartOffset = document.TextContent.IndexOf(selectedText);
int selectionEndOffset = selectionStartOffset + selectedText.Length;
BlockCommentRegion commentRegion = ToggleBlockComment.FindSelectedCommentRegion(document, commentStart, commentEnd, selectionStartOffset, selectionEndOffset);
Assert.IsNull(commentRegion);
}
}
}

Loading…
Cancel
Save