GUI: temporarily disable InputText undo/redo

issue #624
This commit is contained in:
tildearrow 2022-09-22 04:04:32 -05:00
parent 02d2077162
commit cec31b23de
2 changed files with 41 additions and 7 deletions

View file

@ -3713,7 +3713,12 @@ static bool STB_TEXTEDIT_INSERTCHARS(ImGuiInputTextState* obj, int pos, const Im
{
const bool is_resizable = (obj->Flags & ImGuiInputTextFlags_CallbackResize) != 0;
const int text_len = obj->CurLenW;
IM_ASSERT(pos <= text_len);
if (pos > text_len) {
printf("failing STB_TEXTEDIT_INSERTCHARS assertion! oh man...\n");
obj->Edited = true; // ???
obj->ClearText();
return false;
}
const int new_text_len_utf8 = ImTextCountUtf8BytesFromStr(new_text, new_text + new_text_len);
if (!is_resizable && (new_text_len_utf8 + obj->CurLenA + 1 > obj->BufCapacityA))
@ -3776,8 +3781,11 @@ static void stb_textedit_replace(ImGuiInputTextState* str, STB_TexteditState* st
state->cursor = text_len;
state->has_preferred_x = 0;
return;
} else {
state->cursor = 0;
printf("STB_TEXTEDIT_INSERTCHARS fail!\n");
}
IM_ASSERT(0); // Failed to insert character, normally shouldn't happen because of how we currently use stb_textedit_replace()
//IM_ASSERT(0); // Failed to insert character, normally shouldn't happen because of how we currently use stb_textedit_replace()
}
} // namespace ImStb
@ -3962,7 +3970,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
const bool is_multiline = (flags & ImGuiInputTextFlags_Multiline) != 0;
const bool is_readonly = (flags & ImGuiInputTextFlags_ReadOnly) != 0;
const bool is_password = (flags & ImGuiInputTextFlags_Password) != 0;
const bool is_undoable = (flags & ImGuiInputTextFlags_NoUndoRedo) == 0;
// https://github.com/tildearrow/furnace/issues/624
const bool is_undoable = 0; //(flags & ImGuiInputTextFlags_NoUndoRedo) == 0;
const bool is_resizable = (flags & ImGuiInputTextFlags_CallbackResize) != 0;
if (is_resizable)
IM_ASSERT(callback != NULL); // Must provide a callback if you set the ImGuiInputTextFlags_CallbackResize flag!

View file

@ -717,6 +717,9 @@ static int stb_textedit_paste_internal(STB_TEXTEDIT_STRING *str, STB_TexteditSta
state->cursor += len;
state->has_preferred_x = 0;
return 1;
} else {
printf("stb_textedit_paste_internal failed.\n");
state->cursor=0;
}
// note: paste failure will leave deleted selection, may be restored with an undo (see https://github.com/nothings/stb/issues/734 for details)
return 0;
@ -746,6 +749,9 @@ retry:
if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) {
++state->cursor;
state->has_preferred_x = 0;
} else {
printf("key failed: first section.\n");
state->cursor=0;
}
} else {
stb_textedit_delete_selection(str,state); // implicitly clamps
@ -753,6 +759,9 @@ retry:
stb_text_makeundo_insert(state, state->cursor, 1);
++state->cursor;
state->has_preferred_x = 0;
} else {
printf("key failed: second section.\n");
state->cursor=0;
}
}
}
@ -1275,14 +1284,22 @@ static void stb_text_undo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state)
STB_TEXTEDIT_DELETECHARS(str, u.where, u.delete_length);
}
bool steFailed=false;
// check type of recorded action:
if (u.insert_length) {
// easy case: was a deletion, so we need to insert n characters
STB_TEXTEDIT_INSERTCHARS(str, u.where, &s->undo_char[u.char_storage], u.insert_length);
if (!STB_TEXTEDIT_INSERTCHARS(str, u.where, &s->undo_char[u.char_storage], u.insert_length)) {
printf("undo u.insert_length failed\n");
state->cursor=0;
steFailed=true;
}
s->undo_char_point -= u.insert_length;
}
state->cursor = u.where + u.insert_length;
if (!steFailed) {
state->cursor = u.where + u.insert_length;
}
s->undo_point--;
s->redo_point--;
@ -1327,13 +1344,21 @@ static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state)
STB_TEXTEDIT_DELETECHARS(str, r.where, r.delete_length);
}
bool steFailed=false;
if (r.insert_length) {
// easy case: need to insert n characters
STB_TEXTEDIT_INSERTCHARS(str, r.where, &s->undo_char[r.char_storage], r.insert_length);
if (!STB_TEXTEDIT_INSERTCHARS(str, r.where, &s->undo_char[r.char_storage], r.insert_length)) {
printf("redo insert char failed\n");
state->cursor=0;
steFailed=true;
}
s->redo_char_point += r.insert_length;
}
state->cursor = r.where + r.insert_length;
if (!steFailed) {
state->cursor = r.where + r.insert_length;
}
s->undo_point++;
s->redo_point++;