From 6c7f8efe1ec35d8b216c12901d9f6a5d2a8a5e77 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 11 Dec 2015 22:37:47 +0000 Subject: [PATCH] InputText: update mouse drag on mouse move only & key input reposition selection bounds (better fix for #429) --- imgui.cpp | 3 +-- stb_textedit.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index fe6ab3413..dbe4a6df6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7046,7 +7046,6 @@ void ImGuiTextEditState::OnKeyPressed(int key) { stb_textedit_key(this, &StbState, key); CursorFollow = true; - SelectedAllMouseLock = true; CursorAnimReset(); } @@ -7310,7 +7309,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2 stb_textedit_click(&edit_state, &edit_state.StbState, mouse_x, mouse_y); edit_state.CursorAnimReset(); } - else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock) + else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock && (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f)) { stb_textedit_drag(&edit_state, &edit_state.StbState, mouse_x, mouse_y); edit_state.CursorAnimReset(); diff --git a/stb_textedit.h b/stb_textedit.h index 3972c0f43..5473dd19b 100644 --- a/stb_textedit.h +++ b/stb_textedit.h @@ -437,6 +437,8 @@ static void stb_textedit_click(STB_TEXTEDIT_STRING *str, STB_TexteditState *stat static void stb_textedit_drag(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, float x, float y) { int p = stb_text_locate_coord(str, x, y); + if (state->select_start == state->select_end) + state->select_start = state->cursor; state->cursor = state->select_end = p; }