From 999506bc3e6ce3954862ffd7622d1f0ad3fc4ead Mon Sep 17 00:00:00 2001 From: Wspekva Date: Mon, 13 Apr 2026 19:38:33 +0200 Subject: [PATCH] Fix backspace bug in PixelGameEngine::UpdateTextEntry function --- olcPixelGameEngine.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index 5e59a87a..3c16ccc2 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -4406,10 +4406,17 @@ namespace olc nTextEntryCursor = std::max(0, nTextEntryCursor - 1); else if (sym == "_R") nTextEntryCursor = std::min(int32_t(sTextEntryString.size()), nTextEntryCursor + 1); - else if (sym == "\b" && nTextEntryCursor > 0) + else if (sym == "\b") { - sTextEntryString.erase(nTextEntryCursor - 1, 1); - nTextEntryCursor = std::max(0, nTextEntryCursor - 1); + if (nTextEntryCursor > 0) + { + sTextEntryString.erase(nTextEntryCursor - 1, 1); + nTextEntryCursor = std::max(0, nTextEntryCursor - 1); + } + else + { + // Consume the backspace character to prevent it from ending up in the TextEntry string + } } else if (sym == "_X" && size_t(nTextEntryCursor) < sTextEntryString.size()) sTextEntryString.erase(nTextEntryCursor, 1);