Posted 16 years ago
by Paul Fuller
Version: 4.0.0274
Platform: .NET 2.0
Environment: Windows XP (32-bit)
I'm implementing block comment / uncomment functions similar to the EditorView.CommentLines and UncommentLines except that it wraps the selected text in /* ... */
This works however I want the selected text after the operation to be the text that was replaced - either the old text plus the enclosing /*, */ (when adding) or the old text that was contained within the comment (when removing).
There appears to be a problem with the DocumentModificationOptions.SelectInsertedText option to EditorView.ReplaceSelectedText method when the replaced text extends over more than one. The selection is extended by a number of characters equal to the number of newlines in the text.
Looks like a bug. Alternatively is there a better means to achieve this ?
Thanks, Paul
This works however I want the selected text after the operation to be the text that was replaced - either the old text plus the enclosing /*, */ (when adding) or the old text that was contained within the comment (when removing).
There appears to be a problem with the DocumentModificationOptions.SelectInsertedText option to EditorView.ReplaceSelectedText method when the replaced text extends over more than one. The selection is extended by a number of characters equal to the number of newlines in the text.
Looks like a bug. Alternatively is there a better means to achieve this ?
Thanks, Paul
internal void EditBlockCommentAdd()
{
EditorView view = m_SyntaxEditor.SelectedView;
if (view != null)
{
//view.InsertSurroundingText("/*", "*/"); // Didn't leave the text selected
if (view.SelectedText != String.Empty)
{
string workText = "/*" + view.SelectedText + "*/";
view.ReplaceSelectedText(DocumentModificationType.CommentLines, workText
,DocumentModificationOptions.SelectInsertedText);
}
}
}
internal void EditBlockCommentRemove()
{
EditorView view = m_SyntaxEditor.SelectedView;
if (view != null)
{
string workText = view.SelectedText;
int pos = workText.IndexOf("/*");
if (pos >= 0)
{
workText = workText.Remove(pos, 2);
}
pos = workText.LastIndexOf("*/");
if (pos > 0)
{
workText = workText.Remove(pos, 2);
}
if (workText != view.SelectedText)
{
view.ReplaceSelectedText(DocumentModificationType.UncommentLines, workText
,DocumentModificationOptions.SelectInsertedText);
}
}
}