]> O.S.I.I.S - jp/crowedit.git/commitdiff
overridable update for editor instead of onTextChanged
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 3 Nov 2021 13:42:26 +0000 (14:42 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 3 Nov 2021 13:42:26 +0000 (14:42 +0100)
CrowEditBase/src/Editor.cs
CrowEditBase/src/SourceEditor.cs

index 435c2f3a7a0d8d83e4661c84fccbf44b22a4d93a..7e5abce4922d025aad20c44e8ae38bd88f8d7ee7 100644 (file)
@@ -57,7 +57,7 @@ namespace Crow
                        }
                }
                public event EventHandler<TextChangeEventArgs> 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));
 
index 9121ac9246e6541448e45026f0d22eb73ea1d0d7..9169cb182551eb6482ea35c487a73c653d12adca 100644 (file)
@@ -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