From 3acce3b70cffda2c2e131da4b3f46e1f6b8955e5 Mon Sep 17 00:00:00 2001 From: Tig Date: Fri, 28 Jun 2024 15:15:29 -0700 Subject: [PATCH] Fixed TextField.OnTextChanging --- Terminal.Gui/Views/TextField.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 8ef482655..a204d223d 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -532,9 +532,11 @@ public class TextField : View return; } - CancelEventArgs newText = OnTextChanging (value.Replace ("\t", "").Split ("\n") [0]); + string newText = value.Replace ("\t", "").Split ("\n") [0]; + CancelEventArgs args = new (oldText, newText); + OnTextChanging (args); - if (newText.Cancel) + if (args.Cancel) { if (_cursorPosition > _text.Count) { @@ -545,7 +547,7 @@ public class TextField : View } ClearAllSelection (); - _text = newText.NewValue.EnumerateRunes ().ToList (); + _text = args.NewValue.EnumerateRunes ().ToList (); if (!Secret && !_historyText.IsFromHistory) { @@ -1102,13 +1104,12 @@ public class TextField : View /// Virtual method that invoke the event if it's defined. /// The new text to be replaced. - /// Returns the - public virtual CancelEventArgs OnTextChanging (string newText) + /// The event arguments. + public bool OnTextChanging (CancelEventArgs args) { - CancelEventArgs ev = new (string.Empty, newText); - TextChanging?.Invoke (this, ev); + TextChanging?.Invoke (this, args); - return ev; + return args.Cancel; } /// Paste the selected text from the clipboard.