diff --git a/CaseConverter/ConvertCaseCommand.cs b/CaseConverter/ConvertCaseCommand.cs index dc07534..c2e4852 100644 --- a/CaseConverter/ConvertCaseCommand.cs +++ b/CaseConverter/ConvertCaseCommand.cs @@ -55,8 +55,34 @@ protected override void Execute(object sender, EventArgs e) var selection = textDocument.Selection; if (selection.IsEmpty == false) { - var selectedText = selection.Text; - selection.ReplaceText(selectedText, StringCaseConverter.Convert(selectedText, convertPatterns)); + //var selectedText = selection.Text; + //selection.ReplaceText(selectedText, StringCaseConverter.Convert(selectedText, convertPatterns)); + if (selection.TextRanges.Count > 1) + { + foreach (TextRange item in selection.TextRanges) + { + var text = item.StartPoint.GetText(item.EndPoint); + if (string.IsNullOrEmpty(text)) + { + continue; + } + int options = (int)(vsFindOptions.vsFindOptionsMatchWholeWord | + vsFindOptions.vsFindOptionsMatchCase | + vsFindOptions.vsFindOptionsMatchInHiddenText | + vsFindOptions.vsFindOptionsSearchSubfolders | + vsFindOptions.vsFindOptionsKeepModifiedDocumentsOpen); + dte.Find.FindReplace(vsFindAction.vsFindActionReplaceAll, + text, + options, + StringCaseConverter.Convert(text, convertPatterns), + vsFindTarget.vsFindTargetCurrentDocumentSelection, ResultsLocation: vsFindResultsLocation.vsFindResultsNone); + } + } + else + { + var selectedText = selection.Text; + selection.ReplaceText(selectedText, StringCaseConverter.Convert(selectedText, convertPatterns)); + } } else {