@@ -1115,6 +1115,10 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
1115
1115
ctx->KeyPress (ImGuiKey_Tab);
1116
1116
IM_CHECK_STR_EQ (vars.CompletionBuffer .c_str (), " Hello World......................................." );
1117
1117
1118
+ // Test undo after callback changes
1119
+ ctx->KeyPress (ImGuiMod_Ctrl | ImGuiKey_Z);
1120
+ IM_CHECK_STR_EQ (vars.CompletionBuffer .c_str (), " Hello World" );
1121
+
1118
1122
// FIXME: Not testing History callback :)
1119
1123
ctx->ItemClick (" History" );
1120
1124
ctx->KeyCharsAppend (" ABCDEF" );
@@ -1130,6 +1134,12 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
1130
1134
ctx->KeyPress (ImGuiKey_DownArrow);
1131
1135
IM_CHECK_STR_EQ (vars.HistoryBuffer .c_str (), " Pressed Down!" );
1132
1136
1137
+ // Test undo after callback changes
1138
+ ctx->KeyPress (ImGuiMod_Ctrl | ImGuiKey_Z);
1139
+ IM_CHECK_STR_EQ (vars.HistoryBuffer .c_str (), " Pressed Up!" );
1140
+ ctx->KeyPress (ImGuiMod_Ctrl | ImGuiKey_Z);
1141
+ IM_CHECK_STR_EQ (vars.HistoryBuffer .c_str (), " ABCD" );
1142
+
1133
1143
ctx->ItemClick (" Edit" );
1134
1144
IM_CHECK_STR_EQ (vars.EditBuffer .c_str (), " " );
1135
1145
IM_CHECK_EQ (vars.EditCount , 0 );
@@ -1162,28 +1172,34 @@ void RegisterTests_WidgetsInputText(ImGuiTestEngine* e)
1162
1172
}
1163
1173
return 0 ;
1164
1174
};
1165
- ImGui::InputText (" Hello" , vars.Str1 , IM_ARRAYSIZE (vars.Str1 ), ImGuiInputTextFlags_CallbackAlways, callback);
1175
+ ImGui::InputText (" Hello" , vars.Str1 , IM_ARRAYSIZE (vars.Str1 ), vars. Bool1 ? ImGuiInputTextFlags_None : ImGuiInputTextFlags_CallbackAlways, callback);
1166
1176
ImGui::End ();
1167
1177
};
1168
1178
t->TestFunc = [](ImGuiTestContext* ctx)
1169
1179
{
1180
+ ImGuiTestGenericVars& vars = ctx->GenericVars ;
1170
1181
ctx->SetRef (" Test Window" );
1171
1182
ctx->ItemInput (" Hello" );
1172
1183
ImGuiInputTextState* state = &ctx->UiContext ->InputTextState ;
1173
1184
IM_CHECK (state && state->ID == ctx->GetID (" Hello" ));
1174
1185
ctx->KeyCharsAppend (" ab" );
1175
1186
IM_CHECK (state->CurLenA == 2 );
1176
1187
IM_CHECK (state->CurLenW == 2 );
1177
- IM_CHECK ( strcmp ( state->TextA .Data , " ab" ) == 0 );
1188
+ IM_CHECK_STR_EQ ( state->TextA .Data , " ab" );
1178
1189
IM_CHECK (state->Stb ->cursor == 2 );
1179
1190
ctx->KeyCharsAppend (" c" );
1180
1191
IM_CHECK (state->CurLenA == 3 );
1181
1192
IM_CHECK (state->CurLenW == 1 );
1182
- IM_CHECK ( strcmp ( state->TextA .Data , " \xE5\xA5\xBD " ) == 0 );
1193
+ IM_CHECK_STR_EQ ( state->TextA .Data , " \xE5\xA5\xBD " );
1183
1194
IM_CHECK (state->TextW .Data [0 ] == 0x597D );
1184
1195
IM_CHECK (state->TextW .Data [1 ] == 0 );
1185
1196
IM_CHECK (state->Stb ->cursor == 1 );
1186
1197
IM_CHECK (state->Stb ->select_start == 0 && state->Stb ->select_end == 1 );
1198
+
1199
+ // Test undo after callback changes
1200
+ vars.Bool1 = true ; // Disable callback otherwise "abc" after undo will immediately we rewritten
1201
+ ctx->KeyPress (ImGuiMod_Ctrl | ImGuiKey_Z);
1202
+ IM_CHECK_STR_EQ (state->TextA .Data , " abc" );
1187
1203
};
1188
1204
1189
1205
// ## Test resize callback (#3009, #2006, #1443, #1008)
0 commit comments