From f21307e5c9bac40acab906ed2e8a5ce53e4d137d Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 21 Jan 2026 18:25:38 +0100 Subject: [PATCH] InputText: ImGuiInputTextCallbackData::SelectAll() sets CursorPos. Added SetSelection() helper. Context was for #9174 but not specific to it. --- docs/CHANGELOG.txt | 3 +++ imgui.h | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 023ae0263..ff21dab57 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -154,6 +154,9 @@ Other Changes: - Added ImGuiSliderFlags_ColorMarkers to opt-in adding R/G/B/A color markers next to each components, in multi-components functions. - Added a way to select a specific marker color. +- InputText: + - ImGuiInputTextCallbackData::SelectAll() also sets CursorPos to SelectionEnd. + - Added ImGuiInputTextCallbackData::SetSelection() helper. - Text, InputText: - Reworked word-wrapping logic: - Try to not wrap in the middle of contiguous punctuations. (#8139, #8439, #9094) diff --git a/imgui.h b/imgui.h index 448221dce..6baa6d746 100644 --- a/imgui.h +++ b/imgui.h @@ -2650,9 +2650,10 @@ struct ImGuiInputTextCallbackData IMGUI_API ImGuiInputTextCallbackData(); IMGUI_API void DeleteChars(int pos, int bytes_count); IMGUI_API void InsertChars(int pos, const char* text, const char* text_end = NULL); - void SelectAll() { SelectionStart = 0; SelectionEnd = BufTextLen; } - void ClearSelection() { SelectionStart = SelectionEnd = BufTextLen; } - bool HasSelection() const { return SelectionStart != SelectionEnd; } + void SelectAll() { SelectionStart = 0; CursorPos = SelectionEnd = BufTextLen; } + void SetSelection(int s, int e) { IM_ASSERT(s >= 0 && s <= BufTextLen); IM_ASSERT(e >= 0 && e <= BufTextLen); SelectionStart = s; CursorPos = SelectionEnd = e; } + void ClearSelection() { SelectionStart = SelectionEnd = BufTextLen; } + bool HasSelection() const { return SelectionStart != SelectionEnd; } }; // Resizing callback data to apply custom constraint. As enabled by SetNextWindowSizeConstraints(). Callback is called during the next Begin().