From aef6f7bd58fca667324d18027d9fa657fcbca25c Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 13 Feb 2023 14:27:39 +0100 Subject: [PATCH] Fixed control characters being included in TextInput and TextField --- CHANGELOG.md | 5 +++++ MLEM/Input/TextInput.cs | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47d10fb..65ee35a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,14 @@ Jump to version: ## 6.2.0 (In Development) +### MLEM +Fixes +- Fixed control characters being included in TextInput + ### MLEM.Ui Fixes - Fixed images not updating their hidden state properly when the displayed texture changes +- Fixed control characters being included in TextField ## 6.1.0 diff --git a/MLEM/Input/TextInput.cs b/MLEM/Input/TextInput.cs index c2945f2..98287f3 100644 --- a/MLEM/Input/TextInput.cs +++ b/MLEM/Input/TextInput.cs @@ -415,16 +415,20 @@ namespace MLEM.Input { } private bool FilterText(ref string text, bool removeMismatching) { - if (removeMismatching) { - var result = new StringBuilder(); - foreach (var codePoint in new CodePointSource(text)) { - var character = char.ConvertFromUtf32(codePoint); - if (this.InputRule(this, character)) - result.Append(character); + var result = new StringBuilder(); + foreach (var codePoint in new CodePointSource(text)) { + var character = char.ConvertFromUtf32(codePoint); + // don't include control characters + if (character.Length == 1 && char.IsControl(character, 0)) + continue; + if (this.InputRule(this, character)) { + result.Append(character); + } else if (!removeMismatching) { + // if we don't remove mismatching characters, we just fail + return false; } - text = result.ToString(); - } else if (!this.InputRule(this, text)) - return false; + } + text = result.ToString(); return true; }