From ad1420152c9f10e54479047370d4ef719d8051bd Mon Sep 17 00:00:00 2001 From: jacob1 Date: Tue, 25 Apr 2023 00:30:07 -0400 Subject: [PATCH] Fix delete key not functioning correctly in textboxes when text is selected --- src/gui/interface/Textbox.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/gui/interface/Textbox.cpp b/src/gui/interface/Textbox.cpp index 21b6ecd14..ae8421db8 100644 --- a/src/gui/interface/Textbox.cpp +++ b/src/gui/interface/Textbox.cpp @@ -360,10 +360,11 @@ void Textbox::OnVKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, StopTextEditing(); if (HasSelection()) { - if (getLowerSelectionBound() < 0 || getHigherSelectionBound() > (int)backingText.length()) + int lowerBound = getLowerSelectionBound(), higherBound = getHigherSelectionBound(); + if (lowerBound < 0 || higherBound > (int)backingText.length()) return; - backingText.Erase(getLowerSelectionBound(), getHigherSelectionBound()); - cursor = getLowerSelectionBound(); + backingText.Erase(lowerBound, higherBound - lowerBound); + cursor = lowerBound; changed = true; } else if (backingText.length() && cursor < (int)backingText.length()) @@ -387,10 +388,11 @@ void Textbox::OnVKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, StopTextEditing(); if (HasSelection()) { - if (getLowerSelectionBound() < 0 || getHigherSelectionBound() > (int)backingText.length()) + int lowerBound = getLowerSelectionBound(), higherBound = getHigherSelectionBound(); + if (lowerBound < 0 || higherBound > (int)backingText.length()) return; - backingText.erase(backingText.begin()+getLowerSelectionBound(), backingText.begin()+getHigherSelectionBound()); - cursor = getLowerSelectionBound(); + backingText.Erase(lowerBound, higherBound - lowerBound); + cursor = lowerBound; changed = true; } else if (backingText.length() && cursor > 0)