Skip to content

InputText widget doesn't take key ownership of ImGuiKey_Delete when active #8048

Closed
@geertbleyen

Description

Version/Branch of Dear ImGui:

Version 1.90.9, Branch: docking

Back-ends:

imgui_impl_osx.mm + imgui_impl_win32.cpp

Compiler, OS:

Windows11, VS2022; MacOS 15.0, Xcode16

Full config/build information:

Dear ImGui 1.90.8 (19080)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201402
define: __APPLE__
define: __GNUC__=4
define: __clang_version__=16.0.0 (clang-1600.0.26.3)
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_osx
io.BackendRendererName: imgui_impl_metal
io.ConfigFlags: 0x00000443
 NavEnableKeyboard
 NavEnableGamepad
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigMacOSXBehaviors
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000140A
 HasMouseCursors
 PlatformHasViewports
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1200.00,720.00
io.DisplayFramebufferScale: 2.00,2.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

We are creating a node editor, where nodes can contain controls inside of them.
To handle deleting of nodes, we use the shortcut on the window in which we draw the node editor.

if(ImGui::Shortcut(ImGuiKey_Delete, ImGuiInputFlags_RouteFocused)) { 
// handle deleting the selected nodes and connections
... 
}

However, we noticed that when we have an active text edit (via InputText for example), selecting text and pressing the delete keyboard button, would not only delete the text, but still trigger the deletion shortcut on the window, even though it is not focused (the focus is in the text edit).

After some debugging, we found that the InputText widget doesn't set key ownership on the delete key when it is active.
This is fixed by adding ImGuiKey_Delete key ownership in InputTextEx like so:

if (g.ActiveId == id)
    {
        // Declare some inputs, the other are registered and polled via Shortcut() routing system.
        ...
        SetKeyOwner(ImGuiKey_Delete, id); // this will fix it
        SetKeyOwner(ImGuiKey_Enter, id);
        SetKeyOwner(ImGuiKey_KeypadEnter, id);
        SetKeyOwner(ImGuiKey_Home, id);
        SetKeyOwner(ImGuiKey_End, id);
        if (is_multiline)
        {
            SetKeyOwner(ImGuiKey_PageUp, id);
            SetKeyOwner(ImGuiKey_PageDown, id);
        }
        ...
    }

Can this key ownership be added, or is there a reason why it wasn't added before?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions