Fix delete key not functioning correctly in textboxes when text is selected

This commit is contained in:
jacob1
2023-04-25 00:30:07 -04:00
parent 8b7a96b5ef
commit ad1420152c

View File

@@ -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)