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..a3ef72f7f61 100644 --- a/source/blender/blenlib/BLI_string_cursor_utf8.h +++ b/source/blender/blenlib/BLI_string_cursor_utf8.h @@ -22,6 +22,13 @@ typedef enum eStrCursorJumpDirection { STRCUR_DIR_NEXT, } eStrCursorJumpDirection; + +bool BLI_str_cursor_at_word_boundary_utf8(const char *str, const size_t str_maxlen, 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); @@ -32,15 +39,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..d0d6971cbf0 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -96,6 +96,30 @@ static eStrCursorDelimType 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. */ @@ -138,72 +162,81 @@ 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) { - BLI_str_cursor_step_next_utf8(str, str_maxlen, pos); - } - else { - BLI_assert(jump == STRCUR_JUMP_DELIM); + + if (jump == STRCUR_JUMP_DELIM) { + /* If on whitespace, skip forward. */ + while (*pos < str_maxlen && + 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 ? + 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 != cursor_delim_type_utf8(str, str_maxlen, *pos))) + { + break; + } + } + else { + break; /* unlikely but just in case */ } } } else if (direction == STRCUR_DIR_PREV) { - if (use_init_step) { - BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos); - } - else { - BLI_assert(jump == STRCUR_JUMP_DELIM); + + if (jump == STRCUR_JUMP_DELIM) { + /* If on whitespace, skip back. */ + while (*pos > 0 && + 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))) { - /* left only: compensate for index/change in direction */ - if ((pos_orig - (*pos)) >= 1) { - *pos = pos_prev; - } - break; - } - } - else { + 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_NONE) { break; } + if ((jump == STRCUR_JUMP_DELIM) && + (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; + } + } + else { + break; } } } @@ -244,69 +277,76 @@ 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) { - BLI_str_cursor_step_next_utf32(str, str_maxlen, pos); - } - else { - BLI_assert(jump == STRCUR_JUMP_DELIM); + + 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]))) { - break; - } + 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 (use_init_step) { - BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos); - } - else { - BLI_assert(jump == STRCUR_JUMP_DELIM); + + 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]))) { - /* left only: compensate for index/change in direction */ - if ((pos_orig - (*pos)) >= 1) { - *pos = pos_prev; - } - break; - } - } - else { + 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; } } } diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index 6d786fedf46..452ee5aa3a2 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,14 @@ 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 (!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); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/interface/interface_handlers.cc b/source/blender/editors/interface/interface_handlers.cc index 9ba6b3247e7..0c185c369d4 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 (!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); 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..149df92b0d4 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,11 @@ 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[1], STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); + 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]; + } + 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 390a83314f0..4d6a9465448 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" @@ -1577,11 +1578,11 @@ 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); + 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); 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;