From c4c826f2d1877df132e21773e938c81555944f06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Wed, 3 Nov 2021 14:42:26 +0100 Subject: [PATCH] overridable update for editor instead of onTextChanged --- CrowEditBase/src/Editor.cs | 4 +-- CrowEditBase/src/SourceEditor.cs | 44 ++++++++++++++------------------ 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/CrowEditBase/src/Editor.cs b/CrowEditBase/src/Editor.cs index 435c2f3..7e5abce 100644 --- a/CrowEditBase/src/Editor.cs +++ b/CrowEditBase/src/Editor.cs @@ -57,7 +57,7 @@ namespace Crow } } public event EventHandler TextChanged; - public virtual void OnTextChanged(object sender, TextChangeEventArgs e) + public void OnTextChanged(object sender, TextChangeEventArgs e) { if (disableTextChangedEvent) return; @@ -879,7 +879,7 @@ namespace Crow update (new TextChange (selection.Start, selection.Length, IFace.Clipboard)); } - protected void update (TextChange change) { + protected virtual void update (TextChange change) { OnTextChanged (this, new TextChangeEventArgs (change)); diff --git a/CrowEditBase/src/SourceEditor.cs b/CrowEditBase/src/SourceEditor.cs index 9121ac9..9169cb1 100644 --- a/CrowEditBase/src/SourceEditor.cs +++ b/CrowEditBase/src/SourceEditor.cs @@ -56,31 +56,6 @@ namespace Crow } bool suggestionsActive => overlay != null && overlay.IsVisible; - public override void OnTextChanged(object sender, TextChangeEventArgs e) - { - if (disableTextChangedEvent) - return; - - base.OnTextChanged(sender, e); - - if (Document is SourceDocument srcdoc) - srcdoc.updateCurrentTokAndNode (CurrentLoc.Value); - - if (!disableSuggestions && HasFocus) - tryGetSuggestions (); - - RegisterForGraphicUpdate(); - - lock (IFace.UpdateMutex) { - if (Document is SourceDocument doc) { - doc.NotifyValueChanged ("SyntaxRootChildNodes", (object)null); - doc.NotifyValueChanged ("SyntaxRootChildNodes", doc.SyntaxRootChildNodes); - CurrentNode?.ExpandToTheTop(); - } - } - //Console.WriteLine ($"{pos}: {suggestionTok.AsString (_text)} {suggestionTok}"); - } - protected void tryGetSuggestions () { if (currentLoc.HasValue && Document is SourceDocument srcDoc) { IList suggs = srcDoc.GetSuggestions (CurrentLoc.Value); @@ -784,6 +759,25 @@ namespace Crow return cursor; } + protected override void update (TextChange change) { + base.update (change); + + if (Document is SourceDocument srcdoc) + srcdoc.updateCurrentTokAndNode (CurrentLoc.Value); + + if (!disableSuggestions && HasFocus) + tryGetSuggestions (); + + RegisterForGraphicUpdate(); + lock (IFace.UpdateMutex) { + if (Document is SourceDocument doc) { + doc.NotifyValueChanged ("SyntaxRootChildNodes", (object)null); + doc.NotifyValueChanged ("SyntaxRootChildNodes", doc.SyntaxRootChildNodes); + CurrentNode?.ExpandToTheTop(); + } + } + //Console.WriteLine ($"{pos}: {suggestionTok.AsString (_text)} {suggestionTok}"); + } } } \ No newline at end of file -- 2.47.3