mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
Android: Fix if you touched on a text input widget to move the caret to somewhere in the text, then press backspace multiple times, the game crashed
The soft keyboard actually ignores the caret you see in the text input widget, but that's another story
This commit is contained in:
parent
64da5c6909
commit
ad01e2e28e
@ -501,6 +501,11 @@ void LInput_Init(struct LScreen* s, struct LInput* w, int width, const char* hin
|
||||
s->widgets[s->numWidgets++] = (struct LWidget*)w;
|
||||
}
|
||||
|
||||
/* If caret position is now beyond end of text, resets to -1 */
|
||||
static CC_INLINE void LInput_ClampCaret(struct LInput* w) {
|
||||
if (w->caretPos >= w->text.length) w->caretPos = -1;
|
||||
}
|
||||
|
||||
void LInput_SetText(struct LInput* w, const cc_string* text_) {
|
||||
cc_string text; char textBuffer[STRING_SIZE];
|
||||
struct DrawTextArgs args;
|
||||
@ -514,6 +519,7 @@ void LInput_SetText(struct LInput* w, const cc_string* text_) {
|
||||
textWidth = Drawer2D_TextWidth(&args);
|
||||
w->width = max(w->minWidth, textWidth + inputExpand);
|
||||
w->_textHeight = Drawer2D_TextHeight(&args);
|
||||
LInput_ClampCaret(w);
|
||||
}
|
||||
|
||||
static CC_NOINLINE cc_bool LInput_AppendRaw(struct LInput* w, char c) {
|
||||
@ -557,7 +563,7 @@ void LInput_Backspace(struct LInput* w) {
|
||||
}
|
||||
|
||||
if (w->TextChanged) w->TextChanged(w);
|
||||
if (w->caretPos >= w->text.length) w->caretPos = -1;
|
||||
LInput_ClampCaret(w);
|
||||
LWidget_Redraw(w);
|
||||
}
|
||||
|
||||
@ -568,7 +574,7 @@ void LInput_Delete(struct LInput* w) {
|
||||
if (w->caretPos == -1) w->caretPos = 0;
|
||||
|
||||
if (w->TextChanged) w->TextChanged(w);
|
||||
if (w->caretPos >= w->text.length) w->caretPos = -1;
|
||||
LInput_ClampCaret(w);
|
||||
LWidget_Redraw(w);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user