From f4ef420c011dbb80626d103e40424f7697cda88d Mon Sep 17 00:00:00 2001 From: AJ Weeks Date: Tue, 10 Jan 2023 16:20:20 +0100 Subject: [PATCH] InputText: Added support for Ctrl+Delete to delete up to end of word. (#6067) --- docs/CHANGELOG.txt | 2 ++ imgui_widgets.cpp | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index df9f554e..9a9cdd5c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -47,6 +47,8 @@ All changes: is scaled. Scaling wasn't taken into account, leading to ellipsis character straying slightly out of its expected boundaries. (#2775) - Text: Tweaked rendering of three-dots "..." ellipsis variant. (#2775, #4269) +- InputText: Added support for Ctrl+Delete to delete up to end-of-word. (#6067) [@ajweeks] + (Not adding Super+Delete to delete to up to end-of-line on OSX, as OSX doesn't have it) - Menus: Fixed layout of MenuItem()/BeginMenu() when label contains a '\n'. (#6116) [@imkcy9] - PlotHistogram, PlotLines: Passing negative sizes honor alignment like other widgets. - ImDrawList: Added missing early-out in AddPolyline() and AddConvexPolyFilled() when diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index d2d0c00d..041c141d 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -4317,7 +4317,16 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ else if (IsKeyPressed(ImGuiKey_PageDown) && is_multiline) { state->OnKeyPressed(STB_TEXTEDIT_K_PGDOWN | k_mask); scroll_y += row_count_per_page * g.FontSize; } else if (IsKeyPressed(ImGuiKey_Home)) { state->OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); } else if (IsKeyPressed(ImGuiKey_End)) { state->OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); } - else if (IsKeyPressed(ImGuiKey_Delete) && !is_readonly && !is_cut) { state->OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); } + else if (IsKeyPressed(ImGuiKey_Delete) && !is_readonly && !is_cut) + { + if (!state->HasSelection()) + { + // OSX doesn't seem to have Super+Delete to delete until end-of-line, so we don't emulate that (as opposed to Super+Backspace) + if (is_wordmove_key_down) + state->OnKeyPressed(STB_TEXTEDIT_K_WORDRIGHT | STB_TEXTEDIT_K_SHIFT); + } + state->OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); + } else if (IsKeyPressed(ImGuiKey_Backspace) && !is_readonly) { if (!state->HasSelection())