|
|
|
@ -14,8 +14,6 @@ using ICSharpCode.SharpDevelop; |
|
|
|
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
|
|
|
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; |
|
|
|
using ICSharpCode.SharpDevelop.Editor; |
|
|
|
using ICSharpCode.SharpDevelop.Editor; |
|
|
|
using ICSharpCode.SharpDevelop.Gui; |
|
|
|
using ICSharpCode.SharpDevelop.Gui; |
|
|
|
using ICSharpCode.TextEditor; |
|
|
|
|
|
|
|
using ICSharpCode.TextEditor.Document; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace SearchAndReplace |
|
|
|
namespace SearchAndReplace |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -39,24 +37,21 @@ namespace SearchAndReplace |
|
|
|
public static void Replace(IProgressMonitor monitor) |
|
|
|
public static void Replace(IProgressMonitor monitor) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SetSearchOptions(); |
|
|
|
SetSearchOptions(); |
|
|
|
if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { |
|
|
|
if (lastResult != null) { |
|
|
|
ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorControlProvider; |
|
|
|
ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider; |
|
|
|
if (provider != null) { |
|
|
|
if (provider != null) { |
|
|
|
TextEditorControl textarea = provider.TextEditorControl; |
|
|
|
ITextEditor textarea = provider.TextEditor; |
|
|
|
SelectionManager selectionManager = textarea.ActiveTextAreaControl.TextArea.SelectionManager; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (selectionManager.SelectionCollection.Count == 1 |
|
|
|
if (textarea.SelectionStart == lastResult.Offset |
|
|
|
&& selectionManager.SelectionCollection[0].Offset == lastResult.Offset |
|
|
|
&& textarea.SelectionLength == lastResult.Length |
|
|
|
&& selectionManager.SelectionCollection[0].Length == lastResult.Length |
|
|
|
|
|
|
|
&& lastResult.FileName == textarea.FileName) |
|
|
|
&& lastResult.FileName == textarea.FileName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string replacePattern = lastResult.TransformReplacePattern(SearchOptions.ReplacePattern); |
|
|
|
string replacePattern = lastResult.TransformReplacePattern(SearchOptions.ReplacePattern); |
|
|
|
|
|
|
|
|
|
|
|
textarea.BeginUpdate(); |
|
|
|
using (textarea.Document.OpenUndoGroup()) { |
|
|
|
selectionManager.ClearSelection(); |
|
|
|
textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern); |
|
|
|
textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern); |
|
|
|
textarea.Select(lastResult.Offset + replacePattern.Length, 0); // clear selection and set caret position
|
|
|
|
textarea.ActiveTextAreaControl.Caret.Position = textarea.Document.OffsetToPosition(lastResult.Offset + replacePattern.Length); |
|
|
|
} |
|
|
|
textarea.EndUpdate(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -73,24 +68,21 @@ namespace SearchAndReplace |
|
|
|
|
|
|
|
|
|
|
|
public static bool ReplaceNextInSelection(IProgressMonitor monitor) |
|
|
|
public static bool ReplaceNextInSelection(IProgressMonitor monitor) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { |
|
|
|
if (lastResult != null) { |
|
|
|
ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorControlProvider; |
|
|
|
ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider; |
|
|
|
if (provider != null) { |
|
|
|
if (provider != null) { |
|
|
|
TextEditorControl textarea = provider.TextEditorControl; |
|
|
|
ITextEditor textarea = provider.TextEditor; |
|
|
|
SelectionManager selectionManager = textarea.ActiveTextAreaControl.TextArea.SelectionManager; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (selectionManager.SelectionCollection.Count == 1 |
|
|
|
if (textarea.SelectionStart == lastResult.Offset |
|
|
|
&& selectionManager.SelectionCollection[0].Offset == lastResult.Offset |
|
|
|
&& textarea.SelectionLength == lastResult.Length |
|
|
|
&& selectionManager.SelectionCollection[0].Length == lastResult.Length |
|
|
|
|
|
|
|
&& lastResult.FileName == textarea.FileName) |
|
|
|
&& lastResult.FileName == textarea.FileName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string replacePattern = lastResult.TransformReplacePattern(SearchOptions.ReplacePattern); |
|
|
|
string replacePattern = lastResult.TransformReplacePattern(SearchOptions.ReplacePattern); |
|
|
|
|
|
|
|
|
|
|
|
textarea.BeginUpdate(); |
|
|
|
using (textarea.Document.OpenUndoGroup()) { |
|
|
|
selectionManager.ClearSelection(); |
|
|
|
textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern); |
|
|
|
textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern); |
|
|
|
textarea.Select(lastResult.Offset + replacePattern.Length, 0); // clear selection and set caret position
|
|
|
|
textarea.ActiveTextAreaControl.Caret.Position = textarea.Document.OffsetToPosition(lastResult.Offset + replacePattern.Length); |
|
|
|
} |
|
|
|
textarea.EndUpdate(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textSelection.Length -= lastResult.Length - replacePattern.Length; |
|
|
|
textSelection.Length -= lastResult.Length - replacePattern.Length; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -386,11 +378,11 @@ namespace SearchAndReplace |
|
|
|
|
|
|
|
|
|
|
|
static void ClearSelection() |
|
|
|
static void ClearSelection() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { |
|
|
|
ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider; |
|
|
|
ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorControlProvider; |
|
|
|
if (provider != null) { |
|
|
|
if (provider != null) { |
|
|
|
ITextEditor editor = provider.TextEditor; |
|
|
|
provider.TextEditorControl.ActiveTextAreaControl.TextArea.SelectionManager.ClearSelection(); |
|
|
|
if (editor.SelectionLength > 0) |
|
|
|
} |
|
|
|
editor.Select(editor.Caret.Offset, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|