fix for double clicking in the text editor not working usefully (double clicking a pair chars would select 3 - one to the left).

This commit is contained in:
Campbell Barton 2013-02-14 03:03:12 +00:00
parent 12f6d3ad90
commit ab7ca2dc44
7 changed files with 37 additions and 29 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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__ */

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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: