diff --git a/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs b/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs index 29073d4..9e482f6 100644 --- a/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs +++ b/VTMLEditor/GuiElements/Vanilla/GuiElementTextArea.cs @@ -35,14 +35,34 @@ public GuiElementTextArea( this.OnTextChanged = OnTextChanged; } + private bool textChangedBatchedQueued; + internal override void TextChanged() { - if (Autoheight) + if(textChangedBatchedQueued) return; + api.Event.EnqueueMainThreadTask(TextChangedBatched, "TextChangedBatched"); + textChangedBatchedQueued = true; + } + + private void TextChangedBatched() + { + try + { + 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 { - Bounds.fixedHeight = Math.Max(minHeight, textUtil.GetMultilineTextHeight(Font, string.Join("\n", lines), Bounds.InnerWidth)); + textChangedBatchedQueued = false; } - Bounds.CalcWorldBounds(); - base.TextChanged(); } public override void ComposeTextElements(Context ctx, ImageSurface surface)