InputText(): Added io.DoubleClickSelectsWord option for OS X compatible behavior (#473)

This commit is contained in:
ocornut 2016-04-02 18:57:50 +02:00
parent 587fc60f25
commit aa7a29cdbf
2 changed files with 9 additions and 1 deletions

View File

@ -792,6 +792,7 @@ ImGuiIO::ImGuiIO()
#ifdef __APPLE__ #ifdef __APPLE__
WordMovementUsesAltKey = true; // Text editing cursor movement using Alt instead of Ctrl WordMovementUsesAltKey = true; // Text editing cursor movement using Alt instead of Ctrl
ShortcutsUseSuperKey = true; // Shortcuts using Cmd/Super instead of Ctrl ShortcutsUseSuperKey = true; // Shortcuts using Cmd/Super instead of Ctrl
DoubleClickSelectsWord = true; // Double click selects by word instead of selecting whole text
#endif #endif
} }
@ -7414,11 +7415,17 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
const float mouse_x = (g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x) + edit_state.ScrollX; const float mouse_x = (g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x) + edit_state.ScrollX;
const float mouse_y = (is_multiline ? (g.IO.MousePos.y - draw_window->DC.CursorPos.y - style.FramePadding.y) : (g.FontSize*0.5f)); const float mouse_y = (is_multiline ? (g.IO.MousePos.y - draw_window->DC.CursorPos.y - style.FramePadding.y) : (g.FontSize*0.5f));
if (select_all || (hovered && io.MouseDoubleClicked[0])) if (select_all || (hovered && !io.DoubleClickSelectsWord && io.MouseDoubleClicked[0]))
{ {
edit_state.SelectAll(); edit_state.SelectAll();
edit_state.SelectedAllMouseLock = true; edit_state.SelectedAllMouseLock = true;
} }
else if (hovered && io.DoubleClickSelectsWord && io.MouseDoubleClicked[0])
{
// Select a word only, OS X style (by simulating keystrokes)
edit_state.OnKeyPressed(STB_TEXTEDIT_K_WORDLEFT);
edit_state.OnKeyPressed(STB_TEXTEDIT_K_WORDRIGHT | STB_TEXTEDIT_K_SHIFT);
}
else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock) else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock)
{ {
stb_textedit_click(&edit_state, &edit_state.StbState, mouse_x, mouse_y); stb_textedit_click(&edit_state, &edit_state.StbState, mouse_x, mouse_y);

View File

@ -711,6 +711,7 @@ struct ImGuiIO
// Advanced/subtle behaviors // Advanced/subtle behaviors
bool WordMovementUsesAltKey; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl bool WordMovementUsesAltKey; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl
bool ShortcutsUseSuperKey; // = defined(__APPLE__) // OS X style: Shortcuts using Cmd/Super instead of Ctrl bool ShortcutsUseSuperKey; // = defined(__APPLE__) // OS X style: Shortcuts using Cmd/Super instead of Ctrl
bool DoubleClickSelectsWord; // = defined(__APPLE__) // OS X style: Double click selects by word instead of selecting whole text
//------------------------------------------------------------------ //------------------------------------------------------------------
// User Functions // User Functions