From 9e5dc7de01f63827706e8a7ed83629801d60af53 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 10 Dec 2012 02:06:26 +0000 Subject: revert most of r52820 (patch to fix [#33452]), this caused a regression in text stepping when ctrl is held. This adds back the problem that double-clicking on a single char wont select it. Double click selection may need its own logic. --- source/blender/blenlib/intern/string_cursor_utf8.c | 41 ++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'source/blender/blenlib/intern/string_cursor_utf8.c') diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index c364d22b75b..65763f21b0f 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -141,43 +141,48 @@ void BLI_str_cursor_step_utf8(const char *str, size_t maxlen, int *pos, strCursorJumpDirection direction, strCursorJumpType jump) { + const int pos_prev = *pos; + if (direction == STRCUR_DIR_NEXT) { 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) - 1]) : STRCUR_DELIM_NONE; + const strCursorDelimType delim_type = (*pos) < maxlen ? cursor_delim_type(&str[*pos]) : STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), - * look at function test_special_char() for complete + * look at function cursor_delim_type() for complete * list of special character, ctr -> */ - while (TRUE) { - if ((jump != STRCUR_JUMP_ALL) && (delim_type != cursor_delim_type(&str[*pos]))) { + while ((*pos) < maxlen) { + if (BLI_str_cursor_step_next_utf8(str, maxlen, pos)) { + if ((jump != STRCUR_JUMP_ALL) && (delim_type != cursor_delim_type(&str[*pos]))) break; } - else if ((*pos) >= maxlen) { - break; + else { + break; /* unlikely but just in case */ } - BLI_str_cursor_step_next_utf8(str, maxlen, pos); } } } else if (direction == STRCUR_DIR_PREV) { BLI_str_cursor_step_prev_utf8(str, maxlen, pos); + if (jump != STRCUR_JUMP_NONE) { - const strCursorDelimType delim_type = (*pos) > 0 ? cursor_delim_type(&str[(*pos)]) : STRCUR_DELIM_NONE; + const strCursorDelimType delim_type = (*pos) > 1 ? cursor_delim_type(&str[(*pos) - 1]) : STRCUR_DELIM_NONE; /* jump between special characters (/,\,_,-, etc.), - * look at function test_special_char() for complete + * look at function cursor_delim_type() for complete * list of special character, ctr -> */ - while (TRUE) { - if ((jump != STRCUR_JUMP_ALL) && (delim_type != cursor_delim_type(&str[*pos]))) { - /* left only: compensate for index/change in direction */ - if (delim_type != STRCUR_DELIM_NONE) { - BLI_str_cursor_step_next_utf8(str, maxlen, pos); - } - break; + while ((*pos) > 0) { + if (BLI_str_cursor_step_prev_utf8(str, maxlen, pos)) { + if ((jump != STRCUR_JUMP_ALL) && (delim_type != cursor_delim_type(&str[*pos]))) + break; } - else if ((*pos) <= 0) { + else { break; } - BLI_str_cursor_step_prev_utf8(str, maxlen, pos); + } + + /* left only: compensate for index/change in direction */ + if (((*pos) != 0) && ABS(pos_prev - (*pos)) >= 1) { + BLI_str_cursor_step_next_utf8(str, maxlen, pos); } } } -- cgit v1.2.3