From 8fdacbc4c0dd1d43aff34a8be30e0a460db90ead Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Wed, 2 Jul 2014 02:00:03 +0200 Subject: [PATCH] Fix #105: Toggling multiple block comments --- .../Project/Src/Editor/IFormattingStrategy.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Main/Base/Project/Src/Editor/IFormattingStrategy.cs b/src/Main/Base/Project/Src/Editor/IFormattingStrategy.cs index d688dcecdc..d8fbb21a8e 100644 --- a/src/Main/Base/Project/Src/Editor/IFormattingStrategy.cs +++ b/src/Main/Base/Project/Src/Editor/IFormattingStrategy.cs @@ -154,10 +154,10 @@ namespace ICSharpCode.SharpDevelop.Editor editor.Select(region.EndOffset, selectionLength); region = FindSelectedCommentRegion(editor, blockStart, blockEnd); } else { - region = null; + region = null; } } while(region != null); - + } else { editor.Document.Insert(endOffset, blockEnd); editor.Document.Insert(startOffset, blockStart); @@ -187,8 +187,16 @@ namespace ICSharpCode.SharpDevelop.Editor if (commentStartOffset >= 0) { commentEndOffset = selectedText.IndexOf(commentEnd, commentStartOffset + commentStart.Length - editor.SelectionStart); - } else { - commentEndOffset = selectedText.IndexOf(commentEnd); + } + + // Try to search end of comment in whole selection + bool startAfterEnd = false; + int commentEndOffsetWholeText = selectedText.IndexOf(commentEnd); + if ((commentEndOffsetWholeText >= 0) && (commentEndOffsetWholeText < (commentStartOffset - editor.SelectionStart))) { + // There seems to be an end offset before the start offset in selection + commentStartOffset = -1; + startAfterEnd = true; + commentEndOffset = commentEndOffsetWholeText; } if (commentEndOffset >= 0) { @@ -205,7 +213,11 @@ namespace ICSharpCode.SharpDevelop.Editor offset = document.TextLength; } string text = document.GetText(0, offset); - commentStartOffset = text.LastIndexOf(commentStart); + if (startAfterEnd) { + commentStartOffset = text.LastIndexOf(commentStart, editor.SelectionStart); + } else { + commentStartOffset = text.LastIndexOf(commentStart); + } if (commentStartOffset >= 0) { // Find end of comment before comment start. commentEndBeforeStartOffset = text.IndexOf(commentEnd, commentStartOffset, editor.SelectionStart - commentStartOffset);