public static void ReplaceAll(int offset, int length, IProgressMonitor monitor) { SetSearchOptions(); find.Reset(); if (!find.SearchStrategy.CompilePattern()) { return; } for (int count = 0;; count++) { SearchResult result = find.FindNext(offset, length); if (result == null) { ShowReplaceDoneMessage(count, monitor); return; } string replacement = result.TransformReplacePattern(SearchOptions.ReplacePattern); find.Replace(result.Offset, result.Length, replacement); length -= result.Length - replacement.Length; // HACK - Move the cursor to the correct offset - the caret gets // moved before the replace range if we replace a string with a // single character. The ProvidedDocInfo.Replace method assumes that // the current offset is at the end of the found text which it is not. find.CurrentDocumentInformation.CurrentOffset = result.Offset + replacement.Length - 1; } }
public static void ReplaceAll(IProgressMonitor monitor) { SetSearchOptions(); ClearSelection(); find.Reset(); if (!find.SearchStrategy.CompilePattern()) { return; } List <TextEditorControl> textAreas = new List <TextEditorControl>(); TextEditorControl textArea = null; for (int count = 0;; count++) { SearchResult result = SearchReplaceManager.find.FindNext(); if (result == null) { if (count != 0) { foreach (TextEditorControl ta in textAreas) { ta.EndUpdate(); ta.Refresh(); } } ShowReplaceDoneMessage(count, monitor); find.Reset(); return; } else { if (textArea == null || textArea.FileName != result.FileName) { // we need to open another text area textArea = OpenTextArea(result.FileName); if (textArea != null) { if (!textAreas.Contains(textArea)) { textArea.BeginUpdate(); textArea.ActiveTextAreaControl.TextArea.SelectionManager.SelectionCollection.Clear(); textAreas.Add(textArea); } } } if (textArea != null) { string transformedPattern = result.TransformReplacePattern(SearchOptions.ReplacePattern); find.Replace(result.Offset, result.Length, transformedPattern); if (find.CurrentDocumentInformation.Document == null) { textArea.Document.Replace(result.Offset, result.Length, transformedPattern); } } else { count--; } } } }