From f440dc13289c068d8968d5d7b2d75f14e519e87f Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Mon, 8 May 2023 13:24:17 -0700 Subject: [PATCH 1/3] UI: Word Boundary Seeking Changes to how we detect boundaries between words when selecting, moving the cursor, deleting, etc. --- source/blender/blenkernel/BKE_text.h | 4 +-- source/blender/blenkernel/intern/text.c | 12 ++++----- .../blender/blenlib/BLI_string_cursor_utf8.h | 6 ++--- .../blenlib/intern/string_cursor_utf8.c | 26 +++++-------------- source/blender/editors/curve/editfont.c | 24 ++++++++++------- .../editors/interface/interface_handlers.cc | 10 ++++--- .../editors/space_console/console_ops.c | 22 +++++++--------- source/blender/editors/space_text/text_ops.c | 13 +++++----- source/blender/editors/util/numinput.c | 4 +-- 9 files changed, 55 insertions(+), 66 deletions(-) diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index a69fee19380..73415c98b61 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -69,8 +69,8 @@ void txt_move_up(struct Text *text, bool sel); void txt_move_down(struct Text *text, bool sel); void txt_move_left(struct Text *text, bool sel); void txt_move_right(struct Text *text, bool sel); -void txt_jump_left(struct Text *text, bool sel, bool use_init_step); -void txt_jump_right(struct Text *text, bool sel, bool use_init_step); +void txt_jump_left(struct Text *text, bool sel); +void txt_jump_right(struct Text *text, bool sel); void txt_move_bof(struct Text *text, bool sel); void txt_move_eof(struct Text *text, bool sel); void txt_move_bol(struct Text *text, bool sel); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 5dc7f0e8a97..95c897a5756 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -949,7 +949,7 @@ void txt_move_right(Text *text, const bool sel) } } -void txt_jump_left(Text *text, const bool sel, const bool use_init_step) +void txt_jump_left(Text *text, const bool sel) { TextLine **linep; int *charp; @@ -966,14 +966,14 @@ void txt_jump_left(Text *text, const bool sel, const bool use_init_step) } BLI_str_cursor_step_utf8( - (*linep)->line, (*linep)->len, charp, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, use_init_step); + (*linep)->line, (*linep)->len, charp, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM); if (!sel) { txt_pop_sel(text); } } -void txt_jump_right(Text *text, const bool sel, const bool use_init_step) +void txt_jump_right(Text *text, const bool sel) { TextLine **linep; int *charp; @@ -990,7 +990,7 @@ void txt_jump_right(Text *text, const bool sel, const bool use_init_step) } BLI_str_cursor_step_utf8( - (*linep)->line, (*linep)->len, charp, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, use_init_step); + (*linep)->line, (*linep)->len, charp, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM); if (!sel) { txt_pop_sel(text); @@ -1798,7 +1798,7 @@ void txt_delete_char(Text *text) void txt_delete_word(Text *text) { - txt_jump_right(text, true, true); + txt_jump_right(text, true); txt_delete_sel(text); txt_make_dirty(text); } @@ -1847,7 +1847,7 @@ void txt_backspace_char(Text *text) void txt_backspace_word(Text *text) { - txt_jump_left(text, true, true); + txt_jump_left(text, true); txt_delete_sel(text); txt_make_dirty(text); } diff --git a/source/blender/blenlib/BLI_string_cursor_utf8.h b/source/blender/blenlib/BLI_string_cursor_utf8.h index 8fa0c4ec83f..81d0f918d4e 100644 --- a/source/blender/blenlib/BLI_string_cursor_utf8.h +++ b/source/blender/blenlib/BLI_string_cursor_utf8.h @@ -32,15 +32,13 @@ void BLI_str_cursor_step_utf8(const char *str, size_t str_maxlen, int *pos, eStrCursorJumpDirection direction, - eStrCursorJumpType jump, - bool use_init_step); + eStrCursorJumpType jump); void BLI_str_cursor_step_utf32(const char32_t *str, size_t str_maxlen, int *pos, eStrCursorJumpDirection direction, - eStrCursorJumpType jump, - bool use_init_step); + eStrCursorJumpType jump); #ifdef __cplusplus } diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index 95442caa655..b416a7a5b5e 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -138,18 +138,14 @@ void BLI_str_cursor_step_utf8(const char *str, size_t str_maxlen, int *pos, eStrCursorJumpDirection direction, - eStrCursorJumpType jump, - bool use_init_step) + eStrCursorJumpType jump) { const int pos_orig = *pos; if (direction == STRCUR_DIR_NEXT) { - if (use_init_step) { + if (jump == STRCUR_JUMP_DELIM && ELEM(str[*pos], ' ', '\n', '\t')) { BLI_str_cursor_step_next_utf8(str, str_maxlen, pos); } - else { - BLI_assert(jump == STRCUR_JUMP_DELIM); - } if (jump != STRCUR_JUMP_NONE) { const eStrCursorDelimType delim_type = (*pos) < str_maxlen ? @@ -175,12 +171,9 @@ void BLI_str_cursor_step_utf8(const char *str, } } else if (direction == STRCUR_DIR_PREV) { - if (use_init_step) { + if (jump == STRCUR_JUMP_DELIM && *pos > 0 && ELEM(str[*pos - 1], ' ', '\n', '\t')) { BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos); } - else { - BLI_assert(jump == STRCUR_JUMP_DELIM); - } if (jump != STRCUR_JUMP_NONE) { const eStrCursorDelimType delim_type = (*pos) > 0 ? cursor_delim_type_utf8( @@ -244,18 +237,14 @@ void BLI_str_cursor_step_utf32(const char32_t *str, size_t str_maxlen, int *pos, eStrCursorJumpDirection direction, - eStrCursorJumpType jump, - bool use_init_step) + eStrCursorJumpType jump) { const int pos_orig = *pos; if (direction == STRCUR_DIR_NEXT) { - if (use_init_step) { + if (jump == STRCUR_JUMP_DELIM && ELEM(str[*pos], U' ', U'\n', U'\t')) { BLI_str_cursor_step_next_utf32(str, str_maxlen, pos); } - else { - BLI_assert(jump == STRCUR_JUMP_DELIM); - } if (jump != STRCUR_JUMP_NONE) { const eStrCursorDelimType delim_type = (*pos) < str_maxlen ? @@ -278,12 +267,9 @@ void BLI_str_cursor_step_utf32(const char32_t *str, } } else if (direction == STRCUR_DIR_PREV) { - if (use_init_step) { + if (jump == STRCUR_JUMP_DELIM && *pos > 0 && ELEM(str[*pos - 1], U' ', U'\n', U'\t')) { BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos); } - else { - BLI_assert(jump == STRCUR_JUMP_DELIM); - } if (jump != STRCUR_JUMP_NONE) { const eStrCursorDelimType delim_type = (*pos) > 0 ? diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index 6d786fedf46..230b78d9b16 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -1203,8 +1203,7 @@ static int move_cursor(bContext *C, int type, const bool select) case PREV_WORD: { int pos = ef->pos; - BLI_str_cursor_step_utf32( - ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); + BLI_str_cursor_step_utf32(ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM); ef->pos = pos; cursmove = FO_CURS; break; @@ -1212,8 +1211,7 @@ static int move_cursor(bContext *C, int type, const bool select) case NEXT_WORD: { int pos = ef->pos; - BLI_str_cursor_step_utf32( - ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true); + BLI_str_cursor_step_utf32(ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM); ef->pos = pos; cursmove = FO_CURS; break; @@ -1578,10 +1576,10 @@ static int delete_exec(bContext *C, wmOperator *op) range[1] = ef->pos; BLI_str_cursor_step_next_utf32(ef->textbuf, ef->len, &range[1]); break; + case DEL_NEXT_WORD: { int pos = ef->pos; - BLI_str_cursor_step_utf32( - ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true); + BLI_str_cursor_step_utf32(ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM); range[0] = ef->pos; range[1] = pos; break; @@ -1589,8 +1587,7 @@ static int delete_exec(bContext *C, wmOperator *op) case DEL_PREV_WORD: { int pos = ef->pos; - BLI_str_cursor_step_utf32( - ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); + BLI_str_cursor_step_utf32(ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM); range[0] = pos; range[1] = ef->pos; ef->pos = pos; @@ -1920,8 +1917,15 @@ void FONT_OT_selection_set(struct wmOperatorType *ot) static int font_select_word_exec(bContext *C, wmOperator *UNUSED(op)) { - move_cursor(C, NEXT_CHAR, false); - move_cursor(C, PREV_WORD, false); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + Object *obedit = CTX_data_edit_object(C); + Curve *cu = obedit->data; + EditFont *ef = cu->editfont; + + if (ef->pos > 0 && !ELEM(ef->textbuf[ef->pos - 1], ' ', '\n', '\t')) { + /* We are at the end or middle of a word, so move back. */ + move_cursor(C, PREV_WORD, false); + } move_cursor(C, NEXT_WORD, true); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/interface/interface_handlers.cc b/source/blender/editors/interface/interface_handlers.cc index 9ba6b3247e7..f0f7cf310ac 100644 --- a/source/blender/editors/interface/interface_handlers.cc +++ b/source/blender/editors/interface/interface_handlers.cc @@ -3210,7 +3210,7 @@ static void ui_textedit_move(uiBut *but, } else { int pos_i = but->pos; - BLI_str_cursor_step_utf8(str, len, &pos_i, direction, jump, true); + BLI_str_cursor_step_utf8(str, len, &pos_i, direction, jump); but->pos = pos_i; if (select) { @@ -3250,7 +3250,7 @@ static bool ui_textedit_delete(uiBut *but, else if (but->pos >= 0 && but->pos < len) { int pos = but->pos; int step; - BLI_str_cursor_step_utf8(str, len, &pos, direction, jump, true); + BLI_str_cursor_step_utf8(str, len, &pos, direction, jump); step = pos - but->pos; memmove(&str[but->pos], &str[but->pos + step], (len + 1) - (but->pos + step)); changed = true; @@ -3265,7 +3265,7 @@ static bool ui_textedit_delete(uiBut *but, int pos = but->pos; int step; - BLI_str_cursor_step_utf8(str, len, &pos, direction, jump, true); + BLI_str_cursor_step_utf8(str, len, &pos, direction, jump); step = but->pos - pos; memmove(&str[but->pos - step], &str[but->pos], (len + 1) - but->pos); but->pos -= step; @@ -3730,7 +3730,9 @@ static void ui_do_but_textedit( /* only select a word in button if there was no selection before */ if (event->val == KM_DBL_CLICK && had_selection == false) { - ui_textedit_move(but, data, STRCUR_DIR_PREV, false, STRCUR_JUMP_DELIM); + if (but->pos > 0 && !ELEM(but->editstr[but->pos - 1], ' ', '\n', '\t')) { + ui_textedit_move(but, data, STRCUR_DIR_PREV, false, STRCUR_JUMP_DELIM); + } ui_textedit_move(but, data, STRCUR_DIR_NEXT, true, STRCUR_JUMP_DELIM); retval = WM_UI_HANDLER_BREAK; changed = true; diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index 489562f0736..fe1aad5d182 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -370,22 +370,22 @@ static int console_move_exec(bContext *C, wmOperator *op) switch (type) { case LINE_BEGIN: pos = ci->cursor; - BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_ALL, true); + BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_ALL); done = console_line_cursor_set(ci, pos); break; case LINE_END: pos = ci->cursor; - BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_ALL, true); + BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_ALL); done = console_line_cursor_set(ci, pos); break; case PREV_CHAR: pos = ci->cursor; - BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_NONE, true); + BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_NONE); done = console_line_cursor_set(ci, pos); break; case NEXT_CHAR: pos = ci->cursor; - BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_NONE, true); + BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_NONE); done = console_line_cursor_set(ci, pos); break; @@ -393,12 +393,12 @@ static int console_move_exec(bContext *C, wmOperator *op) * - when jump over the word */ case PREV_WORD: pos = ci->cursor; - BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); + BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM); done = console_line_cursor_set(ci, pos); break; case NEXT_WORD: pos = ci->cursor; - BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true); + BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM); done = console_line_cursor_set(ci, pos); break; } @@ -687,8 +687,7 @@ static int console_delete_exec(bContext *C, wmOperator *op) ci->len, &pos, STRCUR_DIR_NEXT, - (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, - true); + (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM); stride = pos - ci->cursor; if (stride) { memmove(ci->line + ci->cursor, @@ -708,8 +707,7 @@ static int console_delete_exec(bContext *C, wmOperator *op) ci->len, &pos, STRCUR_DIR_PREV, - (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, - true); + (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM); stride = ci->cursor - pos; if (stride) { ci->cursor -= stride; /* same as above */ @@ -1258,9 +1256,9 @@ static int console_selectword_invoke(bContext *C, wmOperator *UNUSED(op), const if (console_line_column_from_index(sc, pos, &cl, &offset, &n)) { int sel[2] = {n, n}; - BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[0], STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true); + BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[0], STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM); - BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[1], STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); + BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[1], STRCUR_DIR_PREV, STRCUR_JUMP_DELIM); sel[0] = offset - sel[0]; sel[1] = offset - sel[1]; diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 390a83314f0..fd3c6e206d5 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -1577,11 +1577,12 @@ void TEXT_OT_select_line(wmOperatorType *ot) static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op)) { Text *text = CTX_data_edit_text(C); - /* don't advance cursor before stepping */ - const bool use_init_step = false; - txt_jump_left(text, false, use_init_step); - txt_jump_right(text, true, use_init_step); + TextLine *line = text->curl; + if (text->curc > 0 && !ELEM(line->line[text->curc - 1], ' ', '\n', '\t')) { + txt_jump_left(text, false); + } + txt_jump_right(text, true); text_update_cursor_moved(C); text_select_update_primary_clipboard(text); @@ -2202,14 +2203,14 @@ static int text_move_cursor(bContext *C, int type, bool select) if (txt_cursor_is_line_start(text)) { txt_move_left(text, select); } - txt_jump_left(text, select, true); + txt_jump_left(text, select); break; case NEXT_WORD: if (txt_cursor_is_line_end(text)) { txt_move_right(text, select); } - txt_jump_right(text, select, true); + txt_jump_right(text, select); break; case PREV_CHAR: diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c index f535b91ec0e..2b571c55adc 100644 --- a/source/blender/editors/util/numinput.c +++ b/source/blender/editors/util/numinput.c @@ -395,7 +395,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) if (event->modifier & KM_CTRL) { mode = STRCUR_JUMP_DELIM; } - BLI_str_cursor_step_utf8(n->str, strlen(n->str), &t_cur, dir, mode, true); + BLI_str_cursor_step_utf8(n->str, strlen(n->str), &t_cur, dir, mode); if (t_cur != cur) { if (t_cur < cur) { SWAP(int, t_cur, cur); @@ -421,7 +421,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) if (event->modifier & KM_CTRL) { mode = STRCUR_JUMP_DELIM; } - BLI_str_cursor_step_utf8(n->str, strlen(n->str), &cur, dir, mode, true); + BLI_str_cursor_step_utf8(n->str, strlen(n->str), &cur, dir, mode); if (cur != n->str_cur) { n->str_cur = cur; return true; -- 2.30.2 From a7fd8f1ffc532dfd020c04800891e032765f7e63 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Tue, 9 May 2023 16:53:24 -0700 Subject: [PATCH 2/3] Changes suggested by review. --- .../blender/blenlib/BLI_string_cursor_utf8.h | 18 ++ .../blenlib/intern/string_cursor_utf8.c | 196 ++++++++++-------- source/blender/editors/curve/editfont.c | 6 +- .../editors/interface/interface_handlers.cc | 8 +- .../editors/space_console/console_ops.c | 14 +- source/blender/editors/space_text/text_ops.c | 9 +- 6 files changed, 159 insertions(+), 92 deletions(-) diff --git a/source/blender/blenlib/BLI_string_cursor_utf8.h b/source/blender/blenlib/BLI_string_cursor_utf8.h index 81d0f918d4e..ae12fa6df9a 100644 --- a/source/blender/blenlib/BLI_string_cursor_utf8.h +++ b/source/blender/blenlib/BLI_string_cursor_utf8.h @@ -11,6 +11,17 @@ extern "C" { #endif +typedef enum eStrCursorDelimType { + STRCUR_DELIM_NONE, + STRCUR_DELIM_ALPHANUMERIC, + STRCUR_DELIM_PUNCT, + STRCUR_DELIM_BRACE, + STRCUR_DELIM_OPERATOR, + STRCUR_DELIM_QUOTE, + STRCUR_DELIM_WHITESPACE, + STRCUR_DELIM_OTHER, +} eStrCursorDelimType; + typedef enum eStrCursorJumpType { STRCUR_JUMP_NONE, STRCUR_JUMP_DELIM, @@ -22,6 +33,13 @@ typedef enum eStrCursorJumpDirection { STRCUR_DIR_NEXT, } eStrCursorJumpDirection; + +eStrCursorDelimType BLI_str_cursor_delim_type_utf32(const char32_t *ch_utf32); + +eStrCursorDelimType BLI_str_cursor_delim_type_utf8(const char *ch_utf8, + const size_t ch_utf8_len, + const int pos); + bool BLI_str_cursor_step_next_utf8(const char *str, size_t str_maxlen, int *pos); bool BLI_str_cursor_step_prev_utf8(const char *str, size_t str_maxlen, int *pos); diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index b416a7a5b5e..948d00c9c57 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -17,17 +17,6 @@ # pragma GCC diagnostic error "-Wsign-conversion" #endif -typedef enum eStrCursorDelimType { - STRCUR_DELIM_NONE, - STRCUR_DELIM_ALPHANUMERIC, - STRCUR_DELIM_PUNCT, - STRCUR_DELIM_BRACE, - STRCUR_DELIM_OPERATOR, - STRCUR_DELIM_QUOTE, - STRCUR_DELIM_WHITESPACE, - STRCUR_DELIM_OTHER, -} eStrCursorDelimType; - static eStrCursorDelimType cursor_delim_type_unicode(const uint uch) { switch (uch) { @@ -85,9 +74,13 @@ static eStrCursorDelimType cursor_delim_type_unicode(const uint uch) return STRCUR_DELIM_ALPHANUMERIC; /* Not quite true, but ok for now */ } -static eStrCursorDelimType cursor_delim_type_utf8(const char *ch_utf8, - const size_t ch_utf8_len, - const int pos) +eStrCursorDelimType BLI_str_cursor_delim_type_utf32(const char32_t* ch_utf32) { + return cursor_delim_type_unicode(ch_utf32); +} + +eStrCursorDelimType BLI_str_cursor_delim_type_utf8(const char *ch_utf8, + const size_t ch_utf8_len, + const int pos) { /* for full unicode support we really need to have large lookup tables to figure * out what's what in every possible char set - and python, glib both have these. */ @@ -143,61 +136,77 @@ void BLI_str_cursor_step_utf8(const char *str, const int pos_orig = *pos; if (direction == STRCUR_DIR_NEXT) { - if (jump == STRCUR_JUMP_DELIM && ELEM(str[*pos], ' ', '\n', '\t')) { - BLI_str_cursor_step_next_utf8(str, str_maxlen, pos); + + if (jump == STRCUR_JUMP_DELIM) { + /* If on whitespace, skip forward. */ + while (*pos < str_maxlen && + BLI_str_cursor_delim_type_utf8(str, str_maxlen, *pos) == STRCUR_DELIM_WHITESPACE) + { + (*pos)++; + } } - if (jump != STRCUR_JUMP_NONE) { - const eStrCursorDelimType delim_type = (*pos) < str_maxlen ? - cursor_delim_type_utf8(str, str_maxlen, *pos) : - STRCUR_DELIM_NONE; - /* jump between special characters (/,\,_,-, etc.), - * look at function cursor_delim_type() for complete - * list of special character, ctr -> */ - while ((*pos) < str_maxlen) { - if (BLI_str_cursor_step_next_utf8(str, str_maxlen, pos)) { - if (*pos == str_maxlen) { - break; - } - if ((jump != STRCUR_JUMP_ALL) && - (delim_type != cursor_delim_type_utf8(str, str_maxlen, *pos))) { - break; - } + const eStrCursorDelimType delim_type = (*pos) < str_maxlen ? BLI_str_cursor_delim_type_utf8( + str, str_maxlen, *pos) : + STRCUR_DELIM_NONE; + /* jump between special characters (/,\,_,-, etc.), + * look at function cursor_delim_type() for complete + * list of special character, ctr -> */ + while ((*pos) < str_maxlen) { + if (BLI_str_cursor_step_next_utf8(str, str_maxlen, pos)) { + if (*pos == str_maxlen) { + break; } - else { - break; /* unlikely but just in case */ + if (jump == STRCUR_JUMP_NONE) { + break; } + if ((jump == STRCUR_JUMP_DELIM) && + (delim_type != BLI_str_cursor_delim_type_utf8(str, str_maxlen, *pos))) + { + break; + } + } + else { + break; /* unlikely but just in case */ } } } else if (direction == STRCUR_DIR_PREV) { - if (jump == STRCUR_JUMP_DELIM && *pos > 0 && ELEM(str[*pos - 1], ' ', '\n', '\t')) { - BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos); + + if (jump == STRCUR_JUMP_DELIM) { + /* If on whitespace, skip back. */ + while (*pos > 0 && + BLI_str_cursor_delim_type_utf8(str, str_maxlen, *pos - 1) == STRCUR_DELIM_WHITESPACE) + { + (*pos)--; + } } - if (jump != STRCUR_JUMP_NONE) { - const eStrCursorDelimType delim_type = (*pos) > 0 ? cursor_delim_type_utf8( - str, str_maxlen, *pos - 1) : - STRCUR_DELIM_NONE; - /* jump between special characters (/,\,_,-, etc.), - * look at function cursor_delim_type() for complete - * list of special character, ctr -> */ - while ((*pos) > 0) { - const int pos_prev = *pos; - if (BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos)) { - if ((jump != STRCUR_JUMP_ALL) && - (delim_type != cursor_delim_type_utf8(str, str_maxlen, *pos))) { + const eStrCursorDelimType delim_type = (*pos) > 0 ? BLI_str_cursor_delim_type_utf8( + str, str_maxlen, *pos - 1) : + STRCUR_DELIM_NONE; + /* jump between special characters (/,\,_,-, etc.), + * look at function cursor_delim_type() for complete + * list of special character, ctr -> */ + while ((*pos) > 0) { + const int pos_prev = *pos; + if (BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos)) { + if (jump == STRCUR_JUMP_NONE) { + break; + } + if ((jump == STRCUR_JUMP_DELIM) && + (delim_type != BLI_str_cursor_delim_type_utf8(str, str_maxlen, *pos))) + { /* left only: compensate for index/change in direction */ if ((pos_orig - (*pos)) >= 1) { *pos = pos_prev; } break; - } - } - else { - break; } } + else { + break; + } } } else { @@ -242,58 +251,73 @@ void BLI_str_cursor_step_utf32(const char32_t *str, const int pos_orig = *pos; if (direction == STRCUR_DIR_NEXT) { - if (jump == STRCUR_JUMP_DELIM && ELEM(str[*pos], U' ', U'\n', U'\t')) { - BLI_str_cursor_step_next_utf32(str, str_maxlen, pos); + + if (jump == STRCUR_JUMP_DELIM) { + /* If on whitespace, skip forward. */ + while (*pos < str_maxlen && cursor_delim_type_unicode(str[*pos]) == STRCUR_DELIM_WHITESPACE) + { + (*pos)++; + } } - if (jump != STRCUR_JUMP_NONE) { - const eStrCursorDelimType delim_type = (*pos) < str_maxlen ? - cursor_delim_type_unicode((uint)str[*pos]) : - STRCUR_DELIM_NONE; - /* jump between special characters (/,\,_,-, etc.), - * look at function cursor_delim_type_unicode() for complete - * list of special character, ctr -> */ - while ((*pos) < str_maxlen) { - if (BLI_str_cursor_step_next_utf32(str, str_maxlen, pos)) { - if ((jump != STRCUR_JUMP_ALL) && - (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) { + const eStrCursorDelimType delim_type = (*pos) < str_maxlen ? + cursor_delim_type_unicode((uint)str[*pos]) : + STRCUR_DELIM_NONE; + /* jump between special characters (/,\,_,-, etc.), + * look at function cursor_delim_type_unicode() for complete + * list of special character, ctr -> */ + while ((*pos) < str_maxlen) { + if (BLI_str_cursor_step_next_utf32(str, str_maxlen, pos)) { + if (jump == STRCUR_JUMP_NONE) { break; - } } - else { - break; /* unlikely but just in case */ + if ((jump == STRCUR_JUMP_DELIM) && + (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) + { + break; } } + else { + break; /* unlikely but just in case */ + } } } else if (direction == STRCUR_DIR_PREV) { - if (jump == STRCUR_JUMP_DELIM && *pos > 0 && ELEM(str[*pos - 1], U' ', U'\n', U'\t')) { - BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos); + + if (jump == STRCUR_JUMP_DELIM) { + /* If on whitespace, skip back. */ + while (*pos > 0 && cursor_delim_type_unicode(str[*pos - 1]) == STRCUR_DELIM_WHITESPACE) + { + (*pos)--; + } } - if (jump != STRCUR_JUMP_NONE) { - const eStrCursorDelimType delim_type = (*pos) > 0 ? - cursor_delim_type_unicode((uint)str[(*pos) - 1]) : - STRCUR_DELIM_NONE; - /* jump between special characters (/,\,_,-, etc.), - * look at function cursor_delim_type() for complete - * list of special character, ctr -> */ - while ((*pos) > 0) { - const int pos_prev = *pos; - if (BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos)) { - if ((jump != STRCUR_JUMP_ALL) && - (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) { + const eStrCursorDelimType delim_type = (*pos) > 0 ? + cursor_delim_type_unicode((uint)str[(*pos) - 1]) : + STRCUR_DELIM_NONE; + + /* jump between special characters (/,\,_,-, etc.), + * look at function cursor_delim_type() for complete + * list of special character, ctr -> */ + while ((*pos) > 0) { + const int pos_prev = *pos; + if (BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos)) { + if (jump == STRCUR_JUMP_NONE) { + break; + } + if ((jump = STRCUR_JUMP_DELIM) && + (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) + { /* left only: compensate for index/change in direction */ if ((pos_orig - (*pos)) >= 1) { *pos = pos_prev; } break; - } - } - else { - break; } } + else { + break; + } } } else { diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index 230b78d9b16..f943eedeb56 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -1922,7 +1922,11 @@ static int font_select_word_exec(bContext *C, wmOperator *UNUSED(op)) Curve *cu = obedit->data; EditFont *ef = cu->editfont; - if (ef->pos > 0 && !ELEM(ef->textbuf[ef->pos - 1], ' ', '\n', '\t')) { + if (!ef->textbuf[ef->pos] || + (BLI_str_cursor_delim_type_utf32(ef->textbuf[ef->pos]) == STRCUR_DELIM_WHITESPACE) || + (ef->pos > 0 && + BLI_str_cursor_delim_type_utf32(ef->textbuf[ef->pos - 1]) != STRCUR_DELIM_WHITESPACE)) + { /* We are at the end or middle of a word, so move back. */ move_cursor(C, PREV_WORD, false); } diff --git a/source/blender/editors/interface/interface_handlers.cc b/source/blender/editors/interface/interface_handlers.cc index f0f7cf310ac..8809315edb1 100644 --- a/source/blender/editors/interface/interface_handlers.cc +++ b/source/blender/editors/interface/interface_handlers.cc @@ -3730,7 +3730,13 @@ static void ui_do_but_textedit( /* only select a word in button if there was no selection before */ if (event->val == KM_DBL_CLICK && had_selection == false) { - if (but->pos > 0 && !ELEM(but->editstr[but->pos - 1], ' ', '\n', '\t')) { + if (!but->editstr[but->pos] || + (BLI_str_cursor_delim_type_utf8(but->editstr, but->strwidth, but->pos) == + STRCUR_DELIM_WHITESPACE) || + (but->pos > 0 && + BLI_str_cursor_delim_type_utf8(but->editstr, but->strwidth, but->pos - 1) != + STRCUR_DELIM_WHITESPACE)) + { ui_textedit_move(but, data, STRCUR_DIR_PREV, false, STRCUR_JUMP_DELIM); } ui_textedit_move(but, data, STRCUR_DIR_NEXT, true, STRCUR_JUMP_DELIM); diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index fe1aad5d182..390bd4469b8 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -1256,9 +1256,17 @@ static int console_selectword_invoke(bContext *C, wmOperator *UNUSED(op), const if (console_line_column_from_index(sc, pos, &cl, &offset, &n)) { int sel[2] = {n, n}; - BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[0], STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM); - - BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[1], STRCUR_DIR_PREV, STRCUR_JUMP_DELIM); + char c = cl->line[n - 1]; + char d = cl->line[n]; + if (!cl->line[n] || + (BLI_str_cursor_delim_type_utf8(cl->line, cl->len, n) == STRCUR_DELIM_WHITESPACE) || + (n > 0 && + BLI_str_cursor_delim_type_utf8(cl->line, cl->len, n - 1) != STRCUR_DELIM_WHITESPACE)) + { + BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[0], STRCUR_DIR_PREV, STRCUR_JUMP_DELIM); + sel[1] = sel[0]; + } + BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[1], STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM); sel[0] = offset - sel[0]; sel[1] = offset - sel[1]; diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index fd3c6e206d5..ee0cb277a54 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -15,6 +15,7 @@ #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_math_base.h" +#include "BLI_string_cursor_utf8.h" #include "BLT_translation.h" @@ -1579,7 +1580,13 @@ static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op)) Text *text = CTX_data_edit_text(C); TextLine *line = text->curl; - if (text->curc > 0 && !ELEM(line->line[text->curc - 1], ' ', '\n', '\t')) { + if (!line->line[text->curc] || + (BLI_str_cursor_delim_type_utf8(line->line, line->len, text->curc) == + STRCUR_DELIM_WHITESPACE) || + (text->curc > 0 && BLI_str_cursor_delim_type_utf8(line->line, line->len, text->curc - 1) != + STRCUR_DELIM_WHITESPACE)) + { + /* Move left if to left is non-whitespace or if right is whitespace. */ txt_jump_left(text, false); } txt_jump_right(text, true); -- 2.30.2 From e7ab62b8c44c4664a9b5e885311326e6bcd03718 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 10 May 2023 09:22:59 -0700 Subject: [PATCH 3/3] Review changes --- .../blender/blenlib/BLI_string_cursor_utf8.h | 19 +--- .../blenlib/intern/string_cursor_utf8.c | 96 ++++++++++++------- source/blender/editors/curve/editfont.c | 7 +- .../editors/interface/interface_handlers.cc | 8 +- .../editors/space_console/console_ops.c | 8 +- source/blender/editors/space_text/text_ops.c | 9 +- 6 files changed, 71 insertions(+), 76 deletions(-) diff --git a/source/blender/blenlib/BLI_string_cursor_utf8.h b/source/blender/blenlib/BLI_string_cursor_utf8.h index ae12fa6df9a..a3ef72f7f61 100644 --- a/source/blender/blenlib/BLI_string_cursor_utf8.h +++ b/source/blender/blenlib/BLI_string_cursor_utf8.h @@ -11,17 +11,6 @@ extern "C" { #endif -typedef enum eStrCursorDelimType { - STRCUR_DELIM_NONE, - STRCUR_DELIM_ALPHANUMERIC, - STRCUR_DELIM_PUNCT, - STRCUR_DELIM_BRACE, - STRCUR_DELIM_OPERATOR, - STRCUR_DELIM_QUOTE, - STRCUR_DELIM_WHITESPACE, - STRCUR_DELIM_OTHER, -} eStrCursorDelimType; - typedef enum eStrCursorJumpType { STRCUR_JUMP_NONE, STRCUR_JUMP_DELIM, @@ -34,11 +23,11 @@ typedef enum eStrCursorJumpDirection { } eStrCursorJumpDirection; -eStrCursorDelimType BLI_str_cursor_delim_type_utf32(const char32_t *ch_utf32); +bool BLI_str_cursor_at_word_boundary_utf8(const char *str, const size_t str_maxlen, const int pos); -eStrCursorDelimType BLI_str_cursor_delim_type_utf8(const char *ch_utf8, - const size_t ch_utf8_len, - const int pos); +bool BLI_str_cursor_at_word_boundary_utf32(const char32_t *str, + const size_t str_maxlen, + const int pos); bool BLI_str_cursor_step_next_utf8(const char *str, size_t str_maxlen, int *pos); bool BLI_str_cursor_step_prev_utf8(const char *str, size_t str_maxlen, int *pos); diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index 948d00c9c57..d0d6971cbf0 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -17,6 +17,17 @@ # pragma GCC diagnostic error "-Wsign-conversion" #endif +typedef enum eStrCursorDelimType { + STRCUR_DELIM_NONE, + STRCUR_DELIM_ALPHANUMERIC, + STRCUR_DELIM_PUNCT, + STRCUR_DELIM_BRACE, + STRCUR_DELIM_OPERATOR, + STRCUR_DELIM_QUOTE, + STRCUR_DELIM_WHITESPACE, + STRCUR_DELIM_OTHER, +} eStrCursorDelimType; + static eStrCursorDelimType cursor_delim_type_unicode(const uint uch) { switch (uch) { @@ -74,13 +85,9 @@ static eStrCursorDelimType cursor_delim_type_unicode(const uint uch) return STRCUR_DELIM_ALPHANUMERIC; /* Not quite true, but ok for now */ } -eStrCursorDelimType BLI_str_cursor_delim_type_utf32(const char32_t* ch_utf32) { - return cursor_delim_type_unicode(ch_utf32); -} - -eStrCursorDelimType BLI_str_cursor_delim_type_utf8(const char *ch_utf8, - const size_t ch_utf8_len, - const int pos) +static eStrCursorDelimType cursor_delim_type_utf8(const char *ch_utf8, + const size_t ch_utf8_len, + const int pos) { /* for full unicode support we really need to have large lookup tables to figure * out what's what in every possible char set - and python, glib both have these. */ @@ -89,6 +96,30 @@ eStrCursorDelimType BLI_str_cursor_delim_type_utf8(const char *ch_utf8, return cursor_delim_type_unicode(uch); } +bool BLI_str_cursor_at_word_boundary_utf8(const char *str, const size_t str_maxlen, const int pos) +{ + if (!str[pos] || cursor_delim_type_utf8(str, str_maxlen, pos) == STRCUR_DELIM_WHITESPACE) { + return false; + } + if (pos > 0 && cursor_delim_type_utf8(str, str_maxlen, pos - 1) != STRCUR_DELIM_WHITESPACE) { + return false; + } + return true; +} + +bool BLI_str_cursor_at_word_boundary_utf32(const char32_t *str, + const size_t str_maxlen, + const int pos) +{ + if (!str[pos] || cursor_delim_type_unicode(str[pos]) == STRCUR_DELIM_WHITESPACE) { + return false; + } + if (pos > 0 && cursor_delim_type_unicode(str[pos - 1]) != STRCUR_DELIM_WHITESPACE) { + return false; + } + return true; +} + bool BLI_str_cursor_step_next_utf8(const char *str, size_t str_maxlen, int *pos) { /* NOTE: Keep in sync with #BLI_str_cursor_step_next_utf32. */ @@ -140,15 +171,15 @@ void BLI_str_cursor_step_utf8(const char *str, if (jump == STRCUR_JUMP_DELIM) { /* If on whitespace, skip forward. */ while (*pos < str_maxlen && - BLI_str_cursor_delim_type_utf8(str, str_maxlen, *pos) == STRCUR_DELIM_WHITESPACE) + cursor_delim_type_utf8(str, str_maxlen, *pos) == STRCUR_DELIM_WHITESPACE) { (*pos)++; } } - const eStrCursorDelimType delim_type = (*pos) < str_maxlen ? BLI_str_cursor_delim_type_utf8( - str, str_maxlen, *pos) : - STRCUR_DELIM_NONE; + const eStrCursorDelimType delim_type = (*pos) < str_maxlen ? + cursor_delim_type_utf8(str, str_maxlen, *pos) : + STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function cursor_delim_type() for complete * list of special character, ctr -> */ @@ -161,7 +192,7 @@ void BLI_str_cursor_step_utf8(const char *str, break; } if ((jump == STRCUR_JUMP_DELIM) && - (delim_type != BLI_str_cursor_delim_type_utf8(str, str_maxlen, *pos))) + (delim_type != cursor_delim_type_utf8(str, str_maxlen, *pos))) { break; } @@ -176,15 +207,15 @@ void BLI_str_cursor_step_utf8(const char *str, if (jump == STRCUR_JUMP_DELIM) { /* If on whitespace, skip back. */ while (*pos > 0 && - BLI_str_cursor_delim_type_utf8(str, str_maxlen, *pos - 1) == STRCUR_DELIM_WHITESPACE) + cursor_delim_type_utf8(str, str_maxlen, *pos - 1) == STRCUR_DELIM_WHITESPACE) { (*pos)--; } } - const eStrCursorDelimType delim_type = (*pos) > 0 ? BLI_str_cursor_delim_type_utf8( - str, str_maxlen, *pos - 1) : - STRCUR_DELIM_NONE; + const eStrCursorDelimType delim_type = (*pos) > 0 ? + cursor_delim_type_utf8(str, str_maxlen, *pos - 1) : + STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), * look at function cursor_delim_type() for complete * list of special character, ctr -> */ @@ -192,16 +223,16 @@ void BLI_str_cursor_step_utf8(const char *str, const int pos_prev = *pos; if (BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos)) { if (jump == STRCUR_JUMP_NONE) { - break; + break; } if ((jump == STRCUR_JUMP_DELIM) && - (delim_type != BLI_str_cursor_delim_type_utf8(str, str_maxlen, *pos))) + (delim_type != cursor_delim_type_utf8(str, str_maxlen, *pos))) { - /* left only: compensate for index/change in direction */ - if ((pos_orig - (*pos)) >= 1) { - *pos = pos_prev; - } - break; + /* left only: compensate for index/change in direction */ + if ((pos_orig - (*pos)) >= 1) { + *pos = pos_prev; + } + break; } } else { @@ -269,12 +300,12 @@ void BLI_str_cursor_step_utf32(const char32_t *str, while ((*pos) < str_maxlen) { if (BLI_str_cursor_step_next_utf32(str, str_maxlen, pos)) { if (jump == STRCUR_JUMP_NONE) { - break; + break; } if ((jump == STRCUR_JUMP_DELIM) && (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) { - break; + break; } } else { @@ -286,8 +317,7 @@ void BLI_str_cursor_step_utf32(const char32_t *str, if (jump == STRCUR_JUMP_DELIM) { /* If on whitespace, skip back. */ - while (*pos > 0 && cursor_delim_type_unicode(str[*pos - 1]) == STRCUR_DELIM_WHITESPACE) - { + while (*pos > 0 && cursor_delim_type_unicode(str[*pos - 1]) == STRCUR_DELIM_WHITESPACE) { (*pos)--; } } @@ -303,16 +333,16 @@ void BLI_str_cursor_step_utf32(const char32_t *str, const int pos_prev = *pos; if (BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos)) { if (jump == STRCUR_JUMP_NONE) { - break; + break; } if ((jump = STRCUR_JUMP_DELIM) && (delim_type != cursor_delim_type_unicode((uint)str[*pos]))) { - /* left only: compensate for index/change in direction */ - if ((pos_orig - (*pos)) >= 1) { - *pos = pos_prev; - } - break; + /* left only: compensate for index/change in direction */ + if ((pos_orig - (*pos)) >= 1) { + *pos = pos_prev; + } + break; } } else { diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index f943eedeb56..452ee5aa3a2 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -1922,12 +1922,7 @@ static int font_select_word_exec(bContext *C, wmOperator *UNUSED(op)) Curve *cu = obedit->data; EditFont *ef = cu->editfont; - if (!ef->textbuf[ef->pos] || - (BLI_str_cursor_delim_type_utf32(ef->textbuf[ef->pos]) == STRCUR_DELIM_WHITESPACE) || - (ef->pos > 0 && - BLI_str_cursor_delim_type_utf32(ef->textbuf[ef->pos - 1]) != STRCUR_DELIM_WHITESPACE)) - { - /* We are at the end or middle of a word, so move back. */ + if (!BLI_str_cursor_at_word_boundary_utf32(ef->textbuf, ef->len, ef->pos)) { move_cursor(C, PREV_WORD, false); } move_cursor(C, NEXT_WORD, true); diff --git a/source/blender/editors/interface/interface_handlers.cc b/source/blender/editors/interface/interface_handlers.cc index 8809315edb1..0c185c369d4 100644 --- a/source/blender/editors/interface/interface_handlers.cc +++ b/source/blender/editors/interface/interface_handlers.cc @@ -3730,13 +3730,7 @@ static void ui_do_but_textedit( /* only select a word in button if there was no selection before */ if (event->val == KM_DBL_CLICK && had_selection == false) { - if (!but->editstr[but->pos] || - (BLI_str_cursor_delim_type_utf8(but->editstr, but->strwidth, but->pos) == - STRCUR_DELIM_WHITESPACE) || - (but->pos > 0 && - BLI_str_cursor_delim_type_utf8(but->editstr, but->strwidth, but->pos - 1) != - STRCUR_DELIM_WHITESPACE)) - { + if (!BLI_str_cursor_at_word_boundary_utf8(but->editstr, but->strwidth, but->pos)) { ui_textedit_move(but, data, STRCUR_DIR_PREV, false, STRCUR_JUMP_DELIM); } ui_textedit_move(but, data, STRCUR_DIR_NEXT, true, STRCUR_JUMP_DELIM); diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index 390bd4469b8..149df92b0d4 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -1256,13 +1256,7 @@ static int console_selectword_invoke(bContext *C, wmOperator *UNUSED(op), const if (console_line_column_from_index(sc, pos, &cl, &offset, &n)) { int sel[2] = {n, n}; - char c = cl->line[n - 1]; - char d = cl->line[n]; - if (!cl->line[n] || - (BLI_str_cursor_delim_type_utf8(cl->line, cl->len, n) == STRCUR_DELIM_WHITESPACE) || - (n > 0 && - BLI_str_cursor_delim_type_utf8(cl->line, cl->len, n - 1) != STRCUR_DELIM_WHITESPACE)) - { + if (!BLI_str_cursor_at_word_boundary_utf8(cl->line, cl->len, n)) { BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[0], STRCUR_DIR_PREV, STRCUR_JUMP_DELIM); sel[1] = sel[0]; } diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index ee0cb277a54..4d6a9465448 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -1579,14 +1579,7 @@ static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op)) { Text *text = CTX_data_edit_text(C); - TextLine *line = text->curl; - if (!line->line[text->curc] || - (BLI_str_cursor_delim_type_utf8(line->line, line->len, text->curc) == - STRCUR_DELIM_WHITESPACE) || - (text->curc > 0 && BLI_str_cursor_delim_type_utf8(line->line, line->len, text->curc - 1) != - STRCUR_DELIM_WHITESPACE)) - { - /* Move left if to left is non-whitespace or if right is whitespace. */ + if (!BLI_str_cursor_at_word_boundary_utf8(text->curl->line, text->curl->len, text->curc)) { txt_jump_left(text, false); } txt_jump_right(text, true); -- 2.30.2