Skip to content

Commit

Permalink
Include period as delimiter and improve delimiter navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ Weeks committed Jan 10, 2023
1 parent 20e75a0 commit d36153b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3637,9 +3637,23 @@ static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, ImGuiInputTextState* ob
}

// When ImGuiInputTextFlags_Password is set, we don't want actions such as CTRL+Arrow to leak the fact that underlying data are blanks or separators.
static bool is_separator(unsigned int c) { return ImCharIsBlankW(c) || c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|' || c=='\n' || c=='\r'; }
static int is_word_boundary_from_right(ImGuiInputTextState* obj, int idx) { if (obj->Flags & ImGuiInputTextFlags_Password) return 0; return idx > 0 ? (is_separator(obj->TextW[idx - 1]) && !is_separator(obj->TextW[idx]) ) : 1; }
static int is_word_boundary_from_left(ImGuiInputTextState* obj, int idx) { if (obj->Flags & ImGuiInputTextFlags_Password) return 0; return idx > 0 ? (!is_separator(obj->TextW[idx - 1]) && is_separator(obj->TextW[idx])) : 1; }
static bool is_separator(unsigned int c) { return ImCharIsBlankW(c) || c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|' || c=='\n' || c=='\r' || c == '.'; }
static int is_word_boundary_from_right(ImGuiInputTextState* obj, int idx)
{
if ((obj->Flags & ImGuiInputTextFlags_Password) || idx <= 0) return 0;
// Skip through whitespace blocks
if (ImCharIsBlankW(obj->TextW[idx])) return !ImCharIsBlankW(obj->TextW[idx - 1]);
// Stop at all other separators
return is_separator(obj->TextW[idx - 1]) || is_separator(obj->TextW[idx]);
}
static int is_word_boundary_from_left(ImGuiInputTextState* obj, int idx)
{
if ((obj->Flags & ImGuiInputTextFlags_Password) || idx <= 0) return 0;
// Skip through whitespace blocks
if (ImCharIsBlankW(obj->TextW[idx - 1])) return !ImCharIsBlankW(obj->TextW[idx]);
// Stop at all other separators
return is_separator(obj->TextW[idx - 1]) || is_separator(obj->TextW[idx]);
}
static int STB_TEXTEDIT_MOVEWORDLEFT_IMPL(ImGuiInputTextState* obj, int idx) { idx--; while (idx >= 0 && !is_word_boundary_from_right(obj, idx)) idx--; return idx < 0 ? 0 : idx; }
static int STB_TEXTEDIT_MOVEWORDRIGHT_MAC(ImGuiInputTextState* obj, int idx) { idx++; int len = obj->CurLenW; while (idx < len && !is_word_boundary_from_left(obj, idx)) idx++; return idx > len ? len : idx; }
static int STB_TEXTEDIT_MOVEWORDRIGHT_WIN(ImGuiInputTextState* obj, int idx) { idx++; int len = obj->CurLenW; while (idx < len && !is_word_boundary_from_right(obj, idx)) idx++; return idx > len ? len : idx; }
Expand Down

0 comments on commit d36153b

Please sign in to comment.