Skip to content

Commit

Permalink
InputText: added CJK double-width punctuation to list of separators c…
Browse files Browse the repository at this point in the history
…onsidered for CTRL+Arrow.
  • Loading branch information
ocornut committed Sep 5, 2024
1 parent d16cb17 commit a5cf4fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Breaking changes:
Other changes:

- Nav: pressing any keyboard key while holding Alt disable toggling nav layer on Alt release. (#4439)
- InputText: added CJK double-width punctuation to list of separators considered for CTRL+Arrow.

-----------------------------------------------------------------------
VERSION 1.91.1 (Released 2024-09-04)
Expand Down
21 changes: 15 additions & 6 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3894,9 +3894,18 @@ static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, ImGuiInputTextState* ob
r->num_chars = (int)(text_remaining - (text + line_start_idx));
}

static bool is_separator(unsigned int c)
static bool ImCharIsSeparatorW(unsigned int c)
{
return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|' || c=='\n' || c=='\r' || c=='.' || c=='!' || c=='\\' || c=='/';
static const unsigned int separator_list[] =
{
',', 0x3001, '.', 0x3002, ';', 0xFF1B, '(', 0xFF08, ')', 0xFF09, '{', 0xFF5B, '}', 0xFF5D,
'[', 0x300C, ']', 0x300D, '|', 0xFF5C, '!', 0xFF01, '\\', 0xFFE5, '/', 0x30FB, 0xFF0F,
'\n', '\r',
};
for (unsigned int separator : separator_list)
if (c == separator)
return true;
return false;
}

static int is_word_boundary_from_right(ImGuiInputTextState* obj, int idx)
Expand All @@ -3906,9 +3915,9 @@ static int is_word_boundary_from_right(ImGuiInputTextState* obj, int idx)
return 0;

bool prev_white = ImCharIsBlankW(obj->TextW[idx - 1]);
bool prev_separ = is_separator(obj->TextW[idx - 1]);
bool prev_separ = ImCharIsSeparatorW(obj->TextW[idx - 1]);
bool curr_white = ImCharIsBlankW(obj->TextW[idx]);
bool curr_separ = is_separator(obj->TextW[idx]);
bool curr_separ = ImCharIsSeparatorW(obj->TextW[idx]);
return ((prev_white || prev_separ) && !(curr_separ || curr_white)) || (curr_separ && !prev_separ);
}
static int is_word_boundary_from_left(ImGuiInputTextState* obj, int idx)
Expand All @@ -3917,9 +3926,9 @@ static int is_word_boundary_from_left(ImGuiInputTextState* obj, int idx)
return 0;

bool prev_white = ImCharIsBlankW(obj->TextW[idx]);
bool prev_separ = is_separator(obj->TextW[idx]);
bool prev_separ = ImCharIsSeparatorW(obj->TextW[idx]);
bool curr_white = ImCharIsBlankW(obj->TextW[idx - 1]);
bool curr_separ = is_separator(obj->TextW[idx - 1]);
bool curr_separ = ImCharIsSeparatorW(obj->TextW[idx - 1]);
return ((prev_white) && !(curr_separ || curr_white)) || (curr_separ && !prev_separ);
}
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; }
Expand Down

0 comments on commit a5cf4fe

Please sign in to comment.