Skip to content

Commit

Permalink
Use SDL_StepBackUTF8()
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 9, 2024
1 parent 2faa0bf commit 3029cd2
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions examples/editbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,19 +633,14 @@ void EditBox_Backspace(EditBox *edit)
return;
}

const char *start = &edit->text->text[edit->cursor];
const char *current = start;
/* Step back over the previous UTF-8 character */
do {
if (current == edit->text->text) {
break;
}
--current;
} while ((*current & 0xC0) == 0x80);

int length = (int)(start - current);
TTF_DeleteTextString(edit->text, edit->cursor - length, length);
edit->cursor -= length;
if (edit->cursor > 0) {
const char *start = &edit->text->text[edit->cursor];
const char *next = start;
SDL_StepBackUTF8(edit->text->text, &next);
int length = (int)(uintptr_t)(start - next);
TTF_DeleteTextString(edit->text, edit->cursor - length, length);
edit->cursor -= length;
}
}

void EditBox_BackspaceToBeginning(EditBox *edit)
Expand Down

0 comments on commit 3029cd2

Please sign in to comment.