Skip to content

Commit

Permalink
InputText: amends: fixes overwrite mode handling. (7925)
Browse files Browse the repository at this point in the history
Note that there is a bug (not new) when undoing restores the cursor at a wrong position.
  • Loading branch information
ocornut committed Sep 10, 2024
1 parent 5cdd090 commit ce5f7ab
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions imstb_textedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,11 @@ static void stb_textedit_text(IMSTB_TEXTEDIT_STRING* str, STB_TexteditState* sta
return;

if (state->insert_mode && !STB_TEXT_HAS_SELECTION(state) && state->cursor < STB_TEXTEDIT_STRINGLEN(str)) {
stb_text_makeundo_replace(str, state, state->cursor, 1, 1);
STB_TEXTEDIT_DELETECHARS(str, state->cursor, 1);
// [DEAR IMGUI] This assume that text contains a single character.
// [DEAR IMGUI] FIXME: When undoing the restored cursor position is wrong, but it's not a new bug.
int prev_char_len = IMSTB_TEXTEDIT_GETNEXTCHARINDEX(str, state->cursor) - state->cursor;
stb_text_makeundo_replace(str, state, state->cursor, prev_char_len, text_len);
STB_TEXTEDIT_DELETECHARS(str, state->cursor, prev_char_len);
if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, text, text_len)) {
state->cursor += text_len;
state->has_preferred_x = 0;
Expand Down

0 comments on commit ce5f7ab

Please sign in to comment.