From 5f770be65662758ca50839ed8dfa2e5fa908e834 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 23 Dec 2012 17:02:51 +0100 Subject: [PATCH] Fixed SearchAndReplaceBinding.Detach --- .../SearchAndReplace/Project/SearchOptions.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/AddIns/Misc/SearchAndReplace/Project/SearchOptions.cs b/src/AddIns/Misc/SearchAndReplace/Project/SearchOptions.cs index 3414b68982..843a635687 100644 --- a/src/AddIns/Misc/SearchAndReplace/Project/SearchOptions.cs +++ b/src/AddIns/Misc/SearchAndReplace/Project/SearchOptions.cs @@ -159,15 +159,18 @@ namespace SearchAndReplace public class SearchAndReplaceBinding : DefaultLanguageBinding { + TextArea textArea; SearchInputHandler handler; public override void Attach(ITextEditor editor) { - TextArea textArea = editor.GetService(typeof(TextArea)) as TextArea; - if (textArea == null) return; - handler = new SearchInputHandler(textArea); - textArea.DefaultInputHandler.NestedInputHandlers.Add(handler); - handler.SearchOptionsChanged += SearchOptionsChanged; + base.Attach(editor); + textArea = editor.GetService(typeof(TextArea)) as TextArea; + if (textArea != null) { + handler = new SearchInputHandler(textArea); + textArea.DefaultInputHandler.NestedInputHandlers.Add(handler); + handler.SearchOptionsChanged += SearchOptionsChanged; + } } void SearchOptionsChanged(object sender, SearchOptionsChangedEventArgs e) @@ -180,10 +183,12 @@ namespace SearchAndReplace public override void Detach() { - if (handler != null) { - handler.SearchOptionsChanged -= SearchOptionsChanged; + base.Detach(); + if (textArea != null) { + textArea.DefaultInputHandler.NestedInputHandlers.Remove(handler); + textArea = null; + handler = null; } - handler = null; } } }