InputText: added CJK double-width punctuation to list of separators considered for CTRL+Arrow.

This commit is contained in:
ocornut 2024-09-05 20:45:07 +02:00
parent d16cb171c6
commit a5cf4fe374
2 changed files with 16 additions and 6 deletions

View File

@ -44,6 +44,7 @@ Breaking changes:
Other changes: Other changes:
- Nav: pressing any keyboard key while holding Alt disable toggling nav layer on Alt release. (#4439) - 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) VERSION 1.91.1 (Released 2024-09-04)

View File

@ -3894,9 +3894,18 @@ static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, ImGuiInputTextState* ob
r->num_chars = (int)(text_remaining - (text + line_start_idx)); 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) static int is_word_boundary_from_right(ImGuiInputTextState* obj, int idx)
@ -3906,9 +3915,9 @@ static int is_word_boundary_from_right(ImGuiInputTextState* obj, int idx)
return 0; return 0;
bool prev_white = ImCharIsBlankW(obj->TextW[idx - 1]); 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_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); return ((prev_white || prev_separ) && !(curr_separ || curr_white)) || (curr_separ && !prev_separ);
} }
static int is_word_boundary_from_left(ImGuiInputTextState* obj, int idx) static int is_word_boundary_from_left(ImGuiInputTextState* obj, int idx)
@ -3917,9 +3926,9 @@ static int is_word_boundary_from_left(ImGuiInputTextState* obj, int idx)
return 0; return 0;
bool prev_white = ImCharIsBlankW(obj->TextW[idx]); 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_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); 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; } 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; }