UI: Word Boundary Seeking #107762
|
@ -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_down(struct Text *text, bool sel);
|
||||||
void txt_move_left(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_move_right(struct Text *text, bool sel);
|
||||||
void txt_jump_left(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, bool use_init_step);
|
void txt_jump_right(struct Text *text, bool sel);
|
||||||
void txt_move_bof(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_eof(struct Text *text, bool sel);
|
||||||
void txt_move_bol(struct Text *text, bool sel);
|
void txt_move_bol(struct Text *text, bool sel);
|
||||||
|
|
|
@ -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;
|
TextLine **linep;
|
||||||
int *charp;
|
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(
|
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) {
|
if (!sel) {
|
||||||
txt_pop_sel(text);
|
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;
|
TextLine **linep;
|
||||||
int *charp;
|
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(
|
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) {
|
if (!sel) {
|
||||||
txt_pop_sel(text);
|
txt_pop_sel(text);
|
||||||
|
@ -1798,7 +1798,7 @@ void txt_delete_char(Text *text)
|
||||||
|
|
||||||
void txt_delete_word(Text *text)
|
void txt_delete_word(Text *text)
|
||||||
{
|
{
|
||||||
txt_jump_right(text, true, true);
|
txt_jump_right(text, true);
|
||||||
txt_delete_sel(text);
|
txt_delete_sel(text);
|
||||||
txt_make_dirty(text);
|
txt_make_dirty(text);
|
||||||
}
|
}
|
||||||
|
@ -1847,7 +1847,7 @@ void txt_backspace_char(Text *text)
|
||||||
|
|
||||||
void txt_backspace_word(Text *text)
|
void txt_backspace_word(Text *text)
|
||||||
{
|
{
|
||||||
txt_jump_left(text, true, true);
|
txt_jump_left(text, true);
|
||||||
txt_delete_sel(text);
|
txt_delete_sel(text);
|
||||||
txt_make_dirty(text);
|
txt_make_dirty(text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,13 @@ typedef enum eStrCursorJumpDirection {
|
||||||
STRCUR_DIR_NEXT,
|
STRCUR_DIR_NEXT,
|
||||||
} eStrCursorJumpDirection;
|
} 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_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);
|
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,
|
size_t str_maxlen,
|
||||||
int *pos,
|
int *pos,
|
||||||
eStrCursorJumpDirection direction,
|
eStrCursorJumpDirection direction,
|
||||||
eStrCursorJumpType jump,
|
eStrCursorJumpType jump);
|
||||||
bool use_init_step);
|
|
||||||
|
|
||||||
void BLI_str_cursor_step_utf32(const char32_t *str,
|
void BLI_str_cursor_step_utf32(const char32_t *str,
|
||||||
size_t str_maxlen,
|
size_t str_maxlen,
|
||||||
int *pos,
|
int *pos,
|
||||||
eStrCursorJumpDirection direction,
|
eStrCursorJumpDirection direction,
|
||||||
eStrCursorJumpType jump,
|
eStrCursorJumpType jump);
|
||||||
bool use_init_step);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,30 @@ static eStrCursorDelimType cursor_delim_type_utf8(const char *ch_utf8,
|
||||||
return cursor_delim_type_unicode(uch);
|
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)
|
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. */
|
/* 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,
|
size_t str_maxlen,
|
||||||
int *pos,
|
int *pos,
|
||||||
eStrCursorJumpDirection direction,
|
eStrCursorJumpDirection direction,
|
||||||
eStrCursorJumpType jump,
|
eStrCursorJumpType jump)
|
||||||
bool use_init_step)
|
|
||||||
{
|
{
|
||||||
const int pos_orig = *pos;
|
const int pos_orig = *pos;
|
||||||
|
|
||||||
if (direction == STRCUR_DIR_NEXT) {
|
if (direction == STRCUR_DIR_NEXT) {
|
||||||
if (use_init_step) {
|
|
||||||
BLI_str_cursor_step_next_utf8(str, str_maxlen, pos);
|
if (jump == STRCUR_JUMP_DELIM) {
|
||||||
}
|
/* If on whitespace, skip forward. */
|
||||||
else {
|
while (*pos < str_maxlen &&
|
||||||
BLI_assert(jump == STRCUR_JUMP_DELIM);
|
cursor_delim_type_utf8(str, str_maxlen, *pos) == STRCUR_DELIM_WHITESPACE)
|
||||||
|
{
|
||||||
|
(*pos)++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jump != STRCUR_JUMP_NONE) {
|
const eStrCursorDelimType delim_type = (*pos) < str_maxlen ?
|
||||||
const eStrCursorDelimType delim_type = (*pos) < str_maxlen ?
|
cursor_delim_type_utf8(str, str_maxlen, *pos) :
|
||||||
cursor_delim_type_utf8(str, str_maxlen, *pos) :
|
STRCUR_DELIM_NONE;
|
||||||
STRCUR_DELIM_NONE;
|
/* jump between special characters (/,\,_,-, etc.),
|
||||||
/* jump between special characters (/,\,_,-, etc.),
|
* look at function cursor_delim_type() for complete
|
||||||
* look at function cursor_delim_type() for complete
|
* list of special character, ctr -> */
|
||||||
* list of special character, ctr -> */
|
while ((*pos) < str_maxlen) {
|
||||||
while ((*pos) < str_maxlen) {
|
if (BLI_str_cursor_step_next_utf8(str, str_maxlen, pos)) {
|
||||||
if (BLI_str_cursor_step_next_utf8(str, str_maxlen, pos)) {
|
if (*pos == str_maxlen) {
|
||||||
if (*pos == str_maxlen) {
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ((jump != STRCUR_JUMP_ALL) &&
|
|
||||||
(delim_type != cursor_delim_type_utf8(str, str_maxlen, *pos))) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
if (jump == STRCUR_JUMP_NONE) {
|
||||||
break; /* unlikely but just in case */
|
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) {
|
else if (direction == STRCUR_DIR_PREV) {
|
||||||
if (use_init_step) {
|
|
||||||
BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos);
|
if (jump == STRCUR_JUMP_DELIM) {
|
||||||
}
|
/* If on whitespace, skip back. */
|
||||||
else {
|
while (*pos > 0 &&
|
||||||
BLI_assert(jump == STRCUR_JUMP_DELIM);
|
cursor_delim_type_utf8(str, str_maxlen, *pos - 1) == STRCUR_DELIM_WHITESPACE)
|
||||||
|
{
|
||||||
|
(*pos)--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jump != STRCUR_JUMP_NONE) {
|
const eStrCursorDelimType delim_type = (*pos) > 0 ?
|
||||||
const eStrCursorDelimType delim_type = (*pos) > 0 ? cursor_delim_type_utf8(
|
cursor_delim_type_utf8(str, str_maxlen, *pos - 1) :
|
||||||
str, str_maxlen, *pos - 1) :
|
STRCUR_DELIM_NONE;
|
||||||
STRCUR_DELIM_NONE;
|
/* jump between special characters (/,\,_,-, etc.),
|
||||||
/* jump between special characters (/,\,_,-, etc.),
|
* look at function cursor_delim_type() for complete
|
||||||
* look at function cursor_delim_type() for complete
|
* list of special character, ctr -> */
|
||||||
* list of special character, ctr -> */
|
while ((*pos) > 0) {
|
||||||
while ((*pos) > 0) {
|
const int pos_prev = *pos;
|
||||||
const int pos_prev = *pos;
|
if (BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos)) {
|
||||||
if (BLI_str_cursor_step_prev_utf8(str, str_maxlen, pos)) {
|
if (jump == STRCUR_JUMP_NONE) {
|
||||||
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 {
|
|
||||||
break;
|
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,
|
size_t str_maxlen,
|
||||||
int *pos,
|
int *pos,
|
||||||
eStrCursorJumpDirection direction,
|
eStrCursorJumpDirection direction,
|
||||||
eStrCursorJumpType jump,
|
eStrCursorJumpType jump)
|
||||||
bool use_init_step)
|
|
||||||
{
|
{
|
||||||
const int pos_orig = *pos;
|
const int pos_orig = *pos;
|
||||||
|
|
||||||
if (direction == STRCUR_DIR_NEXT) {
|
if (direction == STRCUR_DIR_NEXT) {
|
||||||
if (use_init_step) {
|
|
||||||
BLI_str_cursor_step_next_utf32(str, str_maxlen, pos);
|
if (jump == STRCUR_JUMP_DELIM) {
|
||||||
}
|
/* If on whitespace, skip forward. */
|
||||||
else {
|
while (*pos < str_maxlen && cursor_delim_type_unicode(str[*pos]) == STRCUR_DELIM_WHITESPACE)
|
||||||
BLI_assert(jump == STRCUR_JUMP_DELIM);
|
{
|
||||||
|
(*pos)++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jump != STRCUR_JUMP_NONE) {
|
const eStrCursorDelimType delim_type = (*pos) < str_maxlen ?
|
||||||
const eStrCursorDelimType delim_type = (*pos) < str_maxlen ?
|
cursor_delim_type_unicode((uint)str[*pos]) :
|
||||||
cursor_delim_type_unicode((uint)str[*pos]) :
|
STRCUR_DELIM_NONE;
|
||||||
STRCUR_DELIM_NONE;
|
/* jump between special characters (/,\,_,-, etc.),
|
||||||
/* jump between special characters (/,\,_,-, etc.),
|
* look at function cursor_delim_type_unicode() for complete
|
||||||
* look at function cursor_delim_type_unicode() for complete
|
* list of special character, ctr -> */
|
||||||
* list of special character, ctr -> */
|
while ((*pos) < str_maxlen) {
|
||||||
while ((*pos) < str_maxlen) {
|
if (BLI_str_cursor_step_next_utf32(str, str_maxlen, pos)) {
|
||||||
if (BLI_str_cursor_step_next_utf32(str, str_maxlen, pos)) {
|
if (jump == STRCUR_JUMP_NONE) {
|
||||||
if ((jump != STRCUR_JUMP_ALL) &&
|
break;
|
||||||
(delim_type != cursor_delim_type_unicode((uint)str[*pos]))) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
if ((jump == STRCUR_JUMP_DELIM) &&
|
||||||
break; /* unlikely but just in case */
|
(delim_type != cursor_delim_type_unicode((uint)str[*pos])))
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
break; /* unlikely but just in case */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (direction == STRCUR_DIR_PREV) {
|
else if (direction == STRCUR_DIR_PREV) {
|
||||||
if (use_init_step) {
|
|
||||||
BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos);
|
if (jump == STRCUR_JUMP_DELIM) {
|
||||||
}
|
/* If on whitespace, skip back. */
|
||||||
else {
|
while (*pos > 0 && cursor_delim_type_unicode(str[*pos - 1]) == STRCUR_DELIM_WHITESPACE) {
|
||||||
BLI_assert(jump == STRCUR_JUMP_DELIM);
|
(*pos)--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jump != STRCUR_JUMP_NONE) {
|
const eStrCursorDelimType delim_type = (*pos) > 0 ?
|
||||||
const eStrCursorDelimType delim_type = (*pos) > 0 ?
|
cursor_delim_type_unicode((uint)str[(*pos) - 1]) :
|
||||||
cursor_delim_type_unicode((uint)str[(*pos) - 1]) :
|
STRCUR_DELIM_NONE;
|
||||||
STRCUR_DELIM_NONE;
|
|
||||||
/* jump between special characters (/,\,_,-, etc.),
|
/* jump between special characters (/,\,_,-, etc.),
|
||||||
* look at function cursor_delim_type() for complete
|
* look at function cursor_delim_type() for complete
|
||||||
* list of special character, ctr -> */
|
* list of special character, ctr -> */
|
||||||
while ((*pos) > 0) {
|
while ((*pos) > 0) {
|
||||||
const int pos_prev = *pos;
|
const int pos_prev = *pos;
|
||||||
if (BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos)) {
|
if (BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos)) {
|
||||||
if ((jump != STRCUR_JUMP_ALL) &&
|
if (jump == STRCUR_JUMP_NONE) {
|
||||||
(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;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1203,8 +1203,7 @@ static int move_cursor(bContext *C, int type, const bool select)
|
||||||
|
|
||||||
case PREV_WORD: {
|
case PREV_WORD: {
|
||||||
int pos = ef->pos;
|
int pos = ef->pos;
|
||||||
BLI_str_cursor_step_utf32(
|
BLI_str_cursor_step_utf32(ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM);
|
||||||
ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true);
|
|
||||||
ef->pos = pos;
|
ef->pos = pos;
|
||||||
cursmove = FO_CURS;
|
cursmove = FO_CURS;
|
||||||
break;
|
break;
|
||||||
|
@ -1212,8 +1211,7 @@ static int move_cursor(bContext *C, int type, const bool select)
|
||||||
|
|
||||||
case NEXT_WORD: {
|
case NEXT_WORD: {
|
||||||
int pos = ef->pos;
|
int pos = ef->pos;
|
||||||
BLI_str_cursor_step_utf32(
|
BLI_str_cursor_step_utf32(ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM);
|
||||||
ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true);
|
|
||||||
ef->pos = pos;
|
ef->pos = pos;
|
||||||
cursmove = FO_CURS;
|
cursmove = FO_CURS;
|
||||||
break;
|
break;
|
||||||
|
@ -1578,10 +1576,10 @@ static int delete_exec(bContext *C, wmOperator *op)
|
||||||
range[1] = ef->pos;
|
range[1] = ef->pos;
|
||||||
BLI_str_cursor_step_next_utf32(ef->textbuf, ef->len, &range[1]);
|
BLI_str_cursor_step_next_utf32(ef->textbuf, ef->len, &range[1]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DEL_NEXT_WORD: {
|
case DEL_NEXT_WORD: {
|
||||||
int pos = ef->pos;
|
int pos = ef->pos;
|
||||||
BLI_str_cursor_step_utf32(
|
BLI_str_cursor_step_utf32(ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM);
|
||||||
ef->textbuf, ef->len, &pos, STRCUR_DIR_NEXT, STRCUR_JUMP_DELIM, true);
|
|
||||||
range[0] = ef->pos;
|
range[0] = ef->pos;
|
||||||
range[1] = pos;
|
range[1] = pos;
|
||||||
break;
|
break;
|
||||||
|
@ -1589,8 +1587,7 @@ static int delete_exec(bContext *C, wmOperator *op)
|
||||||
|
|
||||||
case DEL_PREV_WORD: {
|
case DEL_PREV_WORD: {
|
||||||
int pos = ef->pos;
|
int pos = ef->pos;
|
||||||
BLI_str_cursor_step_utf32(
|
BLI_str_cursor_step_utf32(ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM);
|
||||||
ef->textbuf, ef->len, &pos, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true);
|
|
||||||
range[0] = pos;
|
range[0] = pos;
|
||||||
range[1] = ef->pos;
|
range[1] = ef->pos;
|
||||||
ef->pos = 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))
|
static int font_select_word_exec(bContext *C, wmOperator *UNUSED(op))
|
||||||
{
|
{
|
||||||
move_cursor(C, NEXT_CHAR, false);
|
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
|
||||||
move_cursor(C, PREV_WORD, false);
|
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);
|
move_cursor(C, NEXT_WORD, true);
|
||||||
return OPERATOR_FINISHED;
|
return OPERATOR_FINISHED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3210,7 +3210,7 @@ static void ui_textedit_move(uiBut *but,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int pos_i = but->pos;
|
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;
|
but->pos = pos_i;
|
||||||
|
|
||||||
if (select) {
|
if (select) {
|
||||||
|
@ -3250,7 +3250,7 @@ static bool ui_textedit_delete(uiBut *but,
|
||||||
else if (but->pos >= 0 && but->pos < len) {
|
else if (but->pos >= 0 && but->pos < len) {
|
||||||
int pos = but->pos;
|
int pos = but->pos;
|
||||||
int step;
|
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;
|
step = pos - but->pos;
|
||||||
memmove(&str[but->pos], &str[but->pos + step], (len + 1) - (but->pos + step));
|
memmove(&str[but->pos], &str[but->pos + step], (len + 1) - (but->pos + step));
|
||||||
changed = true;
|
changed = true;
|
||||||
|
@ -3265,7 +3265,7 @@ static bool ui_textedit_delete(uiBut *but,
|
||||||
int pos = but->pos;
|
int pos = but->pos;
|
||||||
int step;
|
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;
|
step = but->pos - pos;
|
||||||
memmove(&str[but->pos - step], &str[but->pos], (len + 1) - but->pos);
|
memmove(&str[but->pos - step], &str[but->pos], (len + 1) - but->pos);
|
||||||
but->pos -= step;
|
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 */
|
/* only select a word in button if there was no selection before */
|
||||||
if (event->val == KM_DBL_CLICK && had_selection == false) {
|
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);
|
ui_textedit_move(but, data, STRCUR_DIR_NEXT, true, STRCUR_JUMP_DELIM);
|
||||||
retval = WM_UI_HANDLER_BREAK;
|
retval = WM_UI_HANDLER_BREAK;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
|
@ -370,22 +370,22 @@ static int console_move_exec(bContext *C, wmOperator *op)
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LINE_BEGIN:
|
case LINE_BEGIN:
|
||||||
pos = ci->cursor;
|
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);
|
done = console_line_cursor_set(ci, pos);
|
||||||
break;
|
break;
|
||||||
case LINE_END:
|
case LINE_END:
|
||||||
pos = ci->cursor;
|
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);
|
done = console_line_cursor_set(ci, pos);
|
||||||
break;
|
break;
|
||||||
case PREV_CHAR:
|
case PREV_CHAR:
|
||||||
pos = ci->cursor;
|
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);
|
done = console_line_cursor_set(ci, pos);
|
||||||
break;
|
break;
|
||||||
case NEXT_CHAR:
|
case NEXT_CHAR:
|
||||||
pos = ci->cursor;
|
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);
|
done = console_line_cursor_set(ci, pos);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -393,12 +393,12 @@ static int console_move_exec(bContext *C, wmOperator *op)
|
||||||
* - when jump over the word */
|
* - when jump over the word */
|
||||||
case PREV_WORD:
|
case PREV_WORD:
|
||||||
pos = ci->cursor;
|
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);
|
done = console_line_cursor_set(ci, pos);
|
||||||
break;
|
break;
|
||||||
case NEXT_WORD:
|
case NEXT_WORD:
|
||||||
pos = ci->cursor;
|
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);
|
done = console_line_cursor_set(ci, pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -687,8 +687,7 @@ static int console_delete_exec(bContext *C, wmOperator *op)
|
||||||
ci->len,
|
ci->len,
|
||||||
&pos,
|
&pos,
|
||||||
STRCUR_DIR_NEXT,
|
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;
|
stride = pos - ci->cursor;
|
||||||
if (stride) {
|
if (stride) {
|
||||||
memmove(ci->line + ci->cursor,
|
memmove(ci->line + ci->cursor,
|
||||||
|
@ -708,8 +707,7 @@ static int console_delete_exec(bContext *C, wmOperator *op)
|
||||||
ci->len,
|
ci->len,
|
||||||
&pos,
|
&pos,
|
||||||
STRCUR_DIR_PREV,
|
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;
|
stride = ci->cursor - pos;
|
||||||
if (stride) {
|
if (stride) {
|
||||||
ci->cursor -= stride; /* same as above */
|
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)) {
|
if (console_line_column_from_index(sc, pos, &cl, &offset, &n)) {
|
||||||
int sel[2] = {n, n};
|
int sel[2] = {n, n};
|
||||||
|
|
||||||
BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[0], STRCUR_DIR_NEXT, 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);
|
||||||
BLI_str_cursor_step_utf8(cl->line, cl->len, &sel[1], STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, true);
|
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[0] = offset - sel[0];
|
||||||
sel[1] = offset - sel[1];
|
sel[1] = offset - sel[1];
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "BLI_blenlib.h"
|
#include "BLI_blenlib.h"
|
||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
#include "BLI_math_base.h"
|
#include "BLI_math_base.h"
|
||||||
|
#include "BLI_string_cursor_utf8.h"
|
||||||
|
|
||||||
#include "BLT_translation.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))
|
static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op))
|
||||||
{
|
{
|
||||||
Text *text = CTX_data_edit_text(C);
|
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);
|
if (!BLI_str_cursor_at_word_boundary_utf8(text->curl->line, text->curl->len, text->curc)) {
|
||||||
txt_jump_right(text, true, use_init_step);
|
txt_jump_left(text, false);
|
||||||
|
}
|
||||||
|
txt_jump_right(text, true);
|
||||||
|
|
||||||
text_update_cursor_moved(C);
|
text_update_cursor_moved(C);
|
||||||
text_select_update_primary_clipboard(text);
|
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)) {
|
if (txt_cursor_is_line_start(text)) {
|
||||||
txt_move_left(text, select);
|
txt_move_left(text, select);
|
||||||
}
|
}
|
||||||
txt_jump_left(text, select, true);
|
txt_jump_left(text, select);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NEXT_WORD:
|
case NEXT_WORD:
|
||||||
if (txt_cursor_is_line_end(text)) {
|
if (txt_cursor_is_line_end(text)) {
|
||||||
txt_move_right(text, select);
|
txt_move_right(text, select);
|
||||||
}
|
}
|
||||||
txt_jump_right(text, select, true);
|
txt_jump_right(text, select);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PREV_CHAR:
|
case PREV_CHAR:
|
||||||
|
|
|
@ -395,7 +395,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
|
||||||
if (event->modifier & KM_CTRL) {
|
if (event->modifier & KM_CTRL) {
|
||||||
mode = STRCUR_JUMP_DELIM;
|
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) {
|
||||||
if (t_cur < cur) {
|
if (t_cur < cur) {
|
||||||
SWAP(int, 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) {
|
if (event->modifier & KM_CTRL) {
|
||||||
mode = STRCUR_JUMP_DELIM;
|
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) {
|
if (cur != n->str_cur) {
|
||||||
n->str_cur = cur;
|
n->str_cur = cur;
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue