diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 14 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_string_cursor_utf8.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string_cursor_utf8.c | 12 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_console/console_ops.c | 18 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 10 |
7 files changed, 37 insertions, 29 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index dc84bc67647..3e882a048eb 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -66,8 +66,8 @@ void txt_move_up (struct Text *text, short sel); void txt_move_down (struct Text *text, short sel); void txt_move_left (struct Text *text, short sel); void txt_move_right (struct Text *text, short sel); -void txt_jump_left (struct Text *text, short sel); -void txt_jump_right (struct Text *text, short 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_move_bof (struct Text *text, short sel); void txt_move_eof (struct Text *text, short sel); void txt_move_bol (struct Text *text, short sel); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 3be9097ce82..86e7a152a4a 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -38,12 +38,12 @@ #include "MEM_guardedalloc.h" +#include "BLI_utildefines.h" #include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_string_cursor_utf8.h" #include "BLI_string_utf8.h" #include "BLI_listbase.h" -#include "BLI_utildefines.h" #include "BLI_fileops.h" #include "DNA_constraint_types.h" @@ -936,7 +936,7 @@ void txt_move_right(Text *text, short sel) if (!sel) txt_pop_sel(text); } -void txt_jump_left(Text *text, short sel) +void txt_jump_left(Text *text, bool sel, bool use_init_step) { TextLine **linep; int *charp; @@ -948,12 +948,12 @@ void txt_jump_left(Text *text, short sel) BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len, charp, STRCUR_DIR_PREV, - STRCUR_JUMP_DELIM); + STRCUR_JUMP_DELIM, use_init_step); if (!sel) txt_pop_sel(text); } -void txt_jump_right(Text *text, short sel) +void txt_jump_right(Text *text, bool sel, bool use_init_step) { TextLine **linep; int *charp; @@ -965,7 +965,7 @@ void txt_jump_right(Text *text, short sel) BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len, charp, STRCUR_DIR_NEXT, - STRCUR_JUMP_DELIM); + STRCUR_JUMP_DELIM, use_init_step); if (!sel) txt_pop_sel(text); } @@ -2402,7 +2402,7 @@ void txt_delete_char(Text *text) void txt_delete_word(Text *text) { - txt_jump_right(text, 1); + txt_jump_right(text, true, true); txt_delete_sel(text); } @@ -2451,7 +2451,7 @@ void txt_backspace_char(Text *text) void txt_backspace_word(Text *text) { - txt_jump_left(text, 1); + txt_jump_left(text, true, true); txt_delete_sel(text); } diff --git a/source/blender/blenlib/BLI_string_cursor_utf8.h b/source/blender/blenlib/BLI_string_cursor_utf8.h index 3c38c0380e0..04d9df2abda 100644 --- a/source/blender/blenlib/BLI_string_cursor_utf8.h +++ b/source/blender/blenlib/BLI_string_cursor_utf8.h @@ -46,6 +46,6 @@ int BLI_str_cursor_step_prev_utf8(const char *str, size_t maxlen, int *pos); void BLI_str_cursor_step_utf8(const char *str, size_t maxlen, int *pos, strCursorJumpDirection direction, - strCursorJumpType jump); + strCursorJumpType jump, bool use_init_step); #endif /* __BLI_STRING_CURSOR_UTF8_H__ */ diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index 65763f21b0f..b8797855f17 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -139,12 +139,15 @@ int BLI_str_cursor_step_prev_utf8(const char *str, size_t UNUSED(maxlen), int *p void BLI_str_cursor_step_utf8(const char *str, size_t maxlen, int *pos, strCursorJumpDirection direction, - strCursorJumpType jump) + strCursorJumpType jump, bool use_init_step) { const int pos_prev = *pos; if (direction == STRCUR_DIR_NEXT) { - BLI_str_cursor_step_next_utf8(str, maxlen, pos); + if (use_init_step) { + BLI_assert(jump == STRCUR_JUMP_DELIM); + BLI_str_cursor_step_next_utf8(str, maxlen, pos); + } if (jump != STRCUR_JUMP_NONE) { const strCursorDelimType delim_type = (*pos) < maxlen ? cursor_delim_type(&str[*pos]) : STRCUR_DELIM_NONE; @@ -163,7 +166,10 @@ void BLI_str_cursor_step_utf8(const char *str, size_t maxlen, } } else if (direction == STRCUR_DIR_PREV) { - BLI_str_cursor_step_prev_utf8(str, maxlen, pos); + if (use_init_step) { + BLI_assert(jump == STRCUR_JUMP_DELIM); + BLI_str_cursor_step_prev_utf8(str, maxlen, pos); + } if (jump != STRCUR_JUMP_NONE) { const strCursorDelimType delim_type = (*pos) > 1 ? cursor_delim_type(&str[(*pos) - 1]) : STRCUR_DELIM_NONE; diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index edd5b901ca1..b166e532f84 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1610,7 +1610,7 @@ static void ui_textedit_move(uiBut *but, uiHandleButtonData *data, strCursorJump } else { int pos_i = but->pos; - BLI_str_cursor_step_utf8(str, len, &pos_i, direction, jump); + BLI_str_cursor_step_utf8(str, len, &pos_i, direction, jump, true); but->pos = pos_i; if (select) { @@ -1679,7 +1679,7 @@ static int ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int directio else if (but->pos >= 0 && but->pos < len) { int pos = but->pos; int step; - BLI_str_cursor_step_utf8(str, len, &pos, direction, jump); + BLI_str_cursor_step_utf8(str, len, &pos, direction, jump, true); step = pos - but->pos; memmove(&str[but->pos], &str[but->pos + step], (len + 1) - but->pos); changed = 1; @@ -1694,7 +1694,7 @@ static int ui_textedit_delete(uiBut *but, uiHandleButtonData *data, int directio int pos = but->pos; int step; - BLI_str_cursor_step_utf8(str, len, &pos, direction, jump); + BLI_str_cursor_step_utf8(str, len, &pos, direction, jump, true); step = but->pos - pos; memmove(&str[but->pos - step], &str[but->pos], (len + 1) - but->pos); but->pos -= step; diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index 5eed39a120e..1242d123a41 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -34,12 +34,12 @@ #include "DNA_userdef_types.h" +#include "BLI_utildefines.h" #include "BLI_listbase.h" #include "BLI_string_cursor_utf8.h" #include "BLI_string_utf8.h" #include "BLI_string.h" #include "BLI_dynstr.h" -#include "BLI_utildefines.h" #include "BLI_math.h" #include "BKE_context.h" @@ -284,28 +284,28 @@ static int console_move_exec(bContext *C, wmOperator *op) pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, - STRCUR_JUMP_ALL); + STRCUR_JUMP_ALL, true); 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); + STRCUR_JUMP_ALL, true); 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); + STRCUR_JUMP_NONE, true); 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); + STRCUR_JUMP_NONE, true); done = console_line_cursor_set(ci, pos); break; @@ -315,14 +315,14 @@ static int console_move_exec(bContext *C, wmOperator *op) pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, - STRCUR_JUMP_DELIM); + STRCUR_JUMP_DELIM, true); 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); + STRCUR_JUMP_DELIM, true); done = console_line_cursor_set(ci, pos); break; } @@ -562,7 +562,7 @@ static int console_delete_exec(bContext *C, wmOperator *op) pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_NEXT, - (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM); + (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true); stride = pos - ci->cursor; if (stride) { memmove(ci->line + ci->cursor, ci->line + ci->cursor + stride, (ci->len - ci->cursor) + 1); @@ -578,7 +578,7 @@ static int console_delete_exec(bContext *C, wmOperator *op) pos = ci->cursor; BLI_str_cursor_step_utf8(ci->line, ci->len, &pos, STRCUR_DIR_PREV, - (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM); + (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true); stride = ci->cursor - pos; if (stride) { ci->cursor -= stride; /* same as above */ diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 1f209f90007..b60528bcee8 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -1312,9 +1312,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, 0); - txt_jump_right(text, 1); + txt_jump_left(text, false, use_init_step); + txt_jump_right(text, true, use_init_step); text_update_cursor_moved(C); WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); @@ -1816,11 +1818,11 @@ static int text_move_cursor(bContext *C, int type, int select) break; case PREV_WORD: - txt_jump_left(text, select); + txt_jump_left(text, select, true); break; case NEXT_WORD: - txt_jump_right(text, select); + txt_jump_right(text, select, true); break; case PREV_CHAR: |