From: Holger Schemel Date: Thu, 22 Oct 2020 16:31:50 +0000 (+0200) Subject: fixed bug with text area gadgets when pressing "Escape" key X-Git-Tag: 4.2.0.4~10 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=f0a36d142c51c8936afa8f9e7bbcf10946c8170a;p=rocksndiamonds.git fixed bug with text area gadgets when pressing "Escape" key This bugs happens when leaving a text area gadget by pressing the "Escape" key. While this is allowed and does not cause the previous text area content to be restored (as text area gadgets cannot be left using the "Enter" key, and as there may be huge amount of text being entered), the corresponding callback function is not called, so the entered text is lost as soon as the gadget gets unmapped. --- diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index f84815b0..c961021a 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -2228,6 +2228,8 @@ boolean HandleGadgetsKeyInput(Key key) { if (anyTextGadgetActive()) { + boolean gadget_changed = ((gi->event_mask & GD_EVENT_TEXT_LEAVING) != 0); + // restore previous text (before activating text gadget) if (gi->type & GD_TYPE_TEXT_INPUT) { @@ -2236,8 +2238,24 @@ boolean HandleGadgetsKeyInput(Key key) CheckRangeOfNumericInputGadget(gi); } + // store current text for text area gadgets when pressing "Escape" key + if (gi->type & GD_TYPE_TEXT_AREA) + { + if (!strEqual(gi->textarea.last_value, gi->textarea.value)) + strcpy(gi->textarea.last_value, gi->textarea.value); + else + gadget_changed = FALSE; + } + DrawGadget(gi, DG_UNPRESSED, gi->direct_draw); + if (gi->type & GD_TYPE_TEXT_AREA) + { + gi->event.type = GD_EVENT_TEXT_LEAVING; + + DoGadgetCallbackAction(gi, gadget_changed); + } + last_gi = NULL; StopTextInput();