From 68a91d306074b3b36a6627889d9ec75c8094ad57 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 24 Feb 2026 17:10:56 +0100 Subject: [PATCH] InputText: Shift+Enter in multi-line editor always adds a new line. (#9239) --- docs/CHANGELOG.txt | 3 +++ imgui.h | 4 ++-- imgui_widgets.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index ae8208da6..fc15fe0af 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -57,6 +57,9 @@ Other Changes: through non-visible chunks. (#3823, #9251, #6990, #6042) Using SetNextItemStorageID() + TreeNodeGetOpen() makes this notably easier than it was prior to 1.91. +- InputText: + - Shift+Enter in multi-line editor always adds a new line, regardless of + ImGuiInputTextFlags_CtrlEnterForNewLine being set or not. (#9239) - Style: border sizes are now scaled (and rounded) by ScaleAllSizes(). - Clipper: - Clear `DisplayStart`/`DisplayEnd` fields when `Step()` returns false. diff --git a/imgui.h b/imgui.h index 5fe0e8297..f038f68f6 100644 --- a/imgui.h +++ b/imgui.h @@ -30,7 +30,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345') #define IMGUI_VERSION "1.92.7 WIP" -#define IMGUI_VERSION_NUM 19262 +#define IMGUI_VERSION_NUM 19263 #define IMGUI_HAS_TABLE // Added BeginTable() - from IMGUI_VERSION_NUM >= 18000 #define IMGUI_HAS_TEXTURES // Added ImGuiBackendFlags_RendererHasTextures - from IMGUI_VERSION_NUM >= 19198 @@ -1259,7 +1259,7 @@ enum ImGuiInputTextFlags_ ImGuiInputTextFlags_AllowTabInput = 1 << 5, // Pressing TAB input a '\t' character into the text field ImGuiInputTextFlags_EnterReturnsTrue = 1 << 6, // Return 'true' when Enter is pressed (as opposed to every time the value was modified). Consider using IsItemDeactivatedAfterEdit() instead! ImGuiInputTextFlags_EscapeClearsAll = 1 << 7, // Escape key clears content if not empty, and deactivate otherwise (contrast to default behavior of Escape to revert) - ImGuiInputTextFlags_CtrlEnterForNewLine = 1 << 8, // In multi-line mode, validate with Enter, add new line with Ctrl+Enter (default is opposite: validate with Ctrl+Enter, add line with Enter). + ImGuiInputTextFlags_CtrlEnterForNewLine = 1 << 8, // In multi-line mode: validate with Enter, add new line with Ctrl+Enter (default is opposite: validate with Ctrl+Enter, add line with Enter). Note that Shift+Enter always enter a new line either way. // Other options ImGuiInputTextFlags_ReadOnly = 1 << 9, // Read-only mode diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 522915067..775375ecf 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5046,6 +5046,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; const bool is_enter = Shortcut(ImGuiKey_Enter, f_repeat, id) || Shortcut(ImGuiKey_KeypadEnter, f_repeat, id); const bool is_ctrl_enter = Shortcut(ImGuiMod_Ctrl | ImGuiKey_Enter, f_repeat, id) || Shortcut(ImGuiMod_Ctrl | ImGuiKey_KeypadEnter, f_repeat, id); + const bool is_shift_enter = Shortcut(ImGuiMod_Shift | ImGuiKey_Enter, f_repeat, id) || Shortcut(ImGuiMod_Shift | ImGuiKey_KeypadEnter, f_repeat, id); const bool is_gamepad_validate = nav_gamepad_active && (IsKeyPressed(ImGuiKey_NavGamepadActivate, false) || IsKeyPressed(ImGuiKey_NavGamepadInput, false)); const bool is_cancel = Shortcut(ImGuiKey_Escape, f_repeat, id) || (nav_gamepad_active && Shortcut(ImGuiKey_NavGamepadCancel, f_repeat, id)); @@ -5080,11 +5081,12 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } state->OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); } - else if (is_enter || is_ctrl_enter || is_gamepad_validate) + else if (is_enter || is_ctrl_enter || is_shift_enter || is_gamepad_validate) { // Determine if we turn Enter into a \n character bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0; - if (!is_multiline || is_gamepad_validate || (ctrl_enter_for_new_line != is_ctrl_enter)) + bool is_new_line = is_multiline && !is_gamepad_validate && (is_shift_enter || (is_enter && !ctrl_enter_for_new_line) || (is_ctrl_enter && ctrl_enter_for_new_line)); + if (!is_new_line) { validated = true; if (io.ConfigInputTextEnterKeepActive && !is_multiline)