From ad02f4757de4ad87ce852152223bad12622fe077 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Mon, 1 May 2023 14:55:44 -0700 Subject: [PATCH 1/2] VFONT: Text Object Word Selection Corrections to allow better cursor keyboard movement and selection by word and mouse word selection by double-clicking. --- source/blender/editors/curve/editfont.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index 99a146c84d0..fc53b6d6269 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -1204,6 +1204,10 @@ static int move_cursor(bContext *C, int type, const bool select) int pos = ef->pos; BLI_str_cursor_step_utf32( ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); + if (ELEM(ef->textbuf[pos], ' ', '\n', '\t')) { + /* Correction for moving too far if from first character or one-letter word. */ + BLI_str_cursor_step_next_utf32(ef->textbuf, ef->len, &pos); + } ef->pos = pos; cursmove = FO_CURS; break; @@ -1213,6 +1217,10 @@ static int move_cursor(bContext *C, int type, const bool select) int pos = ef->pos; BLI_str_cursor_step_utf32( ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true); + if (pos > 0 && ELEM(ef->textbuf[pos - 1], ' ', '\n', '\t')) { + /* Correction for moving too far if from last character or one-letter word. */ + BLI_str_cursor_step_prev_utf32(ef->textbuf, ef->len, &pos); + } ef->pos = pos; cursmove = FO_CURS; break; @@ -1921,9 +1929,20 @@ 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); - move_cursor(C, NEXT_WORD, true); + 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')) { + /* Currently next to white space so just select forward */ + move_cursor(C, NEXT_WORD, true); + } + else { + move_cursor(C, PREV_WORD, false); + move_cursor(C, NEXT_WORD, true); + } + return OPERATOR_FINISHED; } -- 2.30.2 From 5d1adb4c764e37c3d1e404e80d6dfb81144452c7 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Sun, 7 May 2023 14:34:01 -0700 Subject: [PATCH 2/2] Updated to incorporate changes suggested by review --- source/blender/editors/curve/editfont.c | 26 ++++++++++--------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index fc53b6d6269..8045ca4be11 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -1202,12 +1202,10 @@ static int move_cursor(bContext *C, int type, const bool select) case PREV_WORD: { int pos = ef->pos; + /* Only use_init_step if there is space to the left. */ + bool space_left = pos > 0 && ELEM(ef->textbuf[pos - 1], ' ', '\n', '\t'); BLI_str_cursor_step_utf32( - ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true); - if (ELEM(ef->textbuf[pos], ' ', '\n', '\t')) { - /* Correction for moving too far if from first character or one-letter word. */ - BLI_str_cursor_step_next_utf32(ef->textbuf, ef->len, &pos); - } + ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, space_left); ef->pos = pos; cursmove = FO_CURS; break; @@ -1215,12 +1213,10 @@ static int move_cursor(bContext *C, int type, const bool select) case NEXT_WORD: { int pos = ef->pos; + /* Only use_init_step if there is space to the right. */ + bool space_right = ELEM(ef->textbuf[pos], ' ', '\n', '\t'); BLI_str_cursor_step_utf32( - ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true); - if (pos > 0 && ELEM(ef->textbuf[pos - 1], ' ', '\n', '\t')) { - /* Correction for moving too far if from last character or one-letter word. */ - BLI_str_cursor_step_prev_utf32(ef->textbuf, ef->len, &pos); - } + ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, space_right); ef->pos = pos; cursmove = FO_CURS; break; @@ -1934,15 +1930,13 @@ 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')) { - /* Currently next to white space so just select forward */ - move_cursor(C, NEXT_WORD, true); - } - else { + 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); } + move_cursor(C, NEXT_WORD, true); + return OPERATOR_FINISHED; } -- 2.30.2