From 5be29d057e5a231da530c03fdb5ad879c15e5bcc Mon Sep 17 00:00:00 2001 From: _Kristof_ Date: Fri, 10 Oct 2025 09:25:55 +0200 Subject: [PATCH 1/3] throttle text update (this was the simplest way to do it but might want to look into options that allow for larger throttles) --- VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs b/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs index 29073d4..938db65 100644 --- a/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs +++ b/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs @@ -35,7 +35,16 @@ public GuiElementTextArea( this.OnTextChanged = OnTextChanged; } + private bool textChangeDelayed; + internal override void TextChanged() + { + if(textChangeDelayed) return; + textChangeDelayed = true; + api.Event.EnqueueMainThreadTask(TextChangedDelayed, "TextChangedDelayed"); + } + + private void TextChangedDelayed() { if (Autoheight) { @@ -43,6 +52,7 @@ internal override void TextChanged() } Bounds.CalcWorldBounds(); base.TextChanged(); + textChangeDelayed = false; } public override void ComposeTextElements(Context ctx, ImageSurface surface) From 95217d73ba5ddaee3b41708fd36d7548f24734a2 Mon Sep 17 00:00:00 2001 From: _Kristof_ Date: Fri, 10 Oct 2025 09:52:08 +0200 Subject: [PATCH 2/3] Add try catch and rename for clarity --- .../GuiElements/Vanilla/GuiElementTextArea.cs | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs b/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs index 938db65..3c1d3e9 100644 --- a/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs +++ b/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs @@ -35,24 +35,34 @@ public GuiElementTextArea( this.OnTextChanged = OnTextChanged; } - private bool textChangeDelayed; + private bool textChangedBatchedQueued; internal override void TextChanged() { - if(textChangeDelayed) return; - textChangeDelayed = true; - api.Event.EnqueueMainThreadTask(TextChangedDelayed, "TextChangedDelayed"); + if(textChangedBatchedQueued) return; + textChangedBatchedQueued = true; + api.Event.EnqueueMainThreadTask(TextChangedBatched, "TextChangedBatched"); } - private void TextChangedDelayed() + private void TextChangedBatched() { - if (Autoheight) + try { - Bounds.fixedHeight = Math.Max(minHeight, textUtil.GetMultilineTextHeight(Font, string.Join("\n", lines), Bounds.InnerWidth)); + if (Autoheight) + { + Bounds.fixedHeight = Math.Max(minHeight, textUtil.GetMultilineTextHeight(Font, string.Join("\n", lines), Bounds.InnerWidth)); + } + Bounds.CalcWorldBounds(); + base.TextChanged(); + } + catch(Exception ex) + { + api.Logger.Error("[VTMLEditor] an error occured during text change: {0}", ex); + } + finally + { + textChangedBatchedQueued = false; } - Bounds.CalcWorldBounds(); - base.TextChanged(); - textChangeDelayed = false; } public override void ComposeTextElements(Context ctx, ImageSurface surface) From 57dc3b221b8f86a710d2030ed488a84e624377d8 Mon Sep 17 00:00:00 2001 From: _Kristof_ Date: Fri, 10 Oct 2025 09:55:52 +0200 Subject: [PATCH 3/3] swap order of operations (in the very big off chance that `EnqueueMainThreadTask`, not that it really matters as you'd have far bigger issues if that fails) --- VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs b/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs index 3c1d3e9..9e482f6 100644 --- a/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs +++ b/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs @@ -40,8 +40,8 @@ public GuiElementTextArea( internal override void TextChanged() { if(textChangedBatchedQueued) return; - textChangedBatchedQueued = true; api.Event.EnqueueMainThreadTask(TextChangedBatched, "TextChangedBatched"); + textChangedBatchedQueued = true; } private void TextChangedBatched()