forked from bartvdbraak/blender
nicer string delimiter handling for Ctrl+Left/Right arrows, py console could use this functon too.
This commit is contained in:
parent
9dc085e0cb
commit
5c27b34fbf
@ -114,6 +114,17 @@ typedef enum uiButtonJumpType {
|
||||
BUTTON_EDIT_JUMP_ALL
|
||||
} uiButtonJumpType;
|
||||
|
||||
typedef enum uiButtonDelimType {
|
||||
BUTTON_DELIM_NONE,
|
||||
BUTTON_DELIM_ALPHA,
|
||||
BUTTON_DELIM_PUNCT,
|
||||
BUTTON_DELIM_BRACE,
|
||||
BUTTON_DELIM_OPERATOR,
|
||||
BUTTON_DELIM_QUOTE,
|
||||
BUTTON_DELIM_WHITESPACE,
|
||||
BUTTON_DELIM_OTHER
|
||||
} uiButtonDelimType;
|
||||
|
||||
typedef struct uiHandleButtonData {
|
||||
wmWindowManager *wm;
|
||||
wmWindow *window;
|
||||
@ -1230,46 +1241,60 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data,
|
||||
/* ************* in-button text selection/editing ************* */
|
||||
|
||||
/* return 1 if char ch is special character, otherwise return 0 */
|
||||
static short test_special_char(char ch)
|
||||
static uiButtonDelimType test_special_char(const char ch)
|
||||
{
|
||||
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
|
||||
return BUTTON_DELIM_ALPHA;
|
||||
}
|
||||
|
||||
switch(ch) {
|
||||
case '\\':
|
||||
case '/':
|
||||
case '~':
|
||||
case '!':
|
||||
case '@':
|
||||
case '#':
|
||||
case '$':
|
||||
case '%':
|
||||
case '^':
|
||||
case '&':
|
||||
case '*':
|
||||
case '(':
|
||||
case ')':
|
||||
case '+':
|
||||
case '=':
|
||||
case ',':
|
||||
case '.':
|
||||
return BUTTON_DELIM_PUNCT;
|
||||
|
||||
case '{':
|
||||
case '}':
|
||||
case '[':
|
||||
case ']':
|
||||
case ':':
|
||||
case ';':
|
||||
case '\'':
|
||||
case '\"': // " - an extra closing one for Aligorith's text editor
|
||||
case '(':
|
||||
case ')':
|
||||
return BUTTON_DELIM_BRACE;
|
||||
|
||||
case '+':
|
||||
case '-':
|
||||
case '=':
|
||||
case '~':
|
||||
case '%':
|
||||
case '/':
|
||||
case '<':
|
||||
case '>':
|
||||
case ',':
|
||||
case '.':
|
||||
case '^':
|
||||
case '*':
|
||||
case '&':
|
||||
return BUTTON_DELIM_OPERATOR;
|
||||
|
||||
case '\'':
|
||||
case '\"': // " - an extra closing one for Aligorith's text editor
|
||||
return BUTTON_DELIM_QUOTE;
|
||||
|
||||
case ' ':
|
||||
return BUTTON_DELIM_WHITESPACE;
|
||||
|
||||
case '\\':
|
||||
case '!':
|
||||
case '@':
|
||||
case '#':
|
||||
case '$':
|
||||
case ':':
|
||||
case ';':
|
||||
case '?':
|
||||
case '_':
|
||||
case '-':
|
||||
case ' ':
|
||||
return 1;
|
||||
break;
|
||||
return BUTTON_DELIM_OTHER;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
return BUTTON_DELIM_NONE;
|
||||
}
|
||||
|
||||
static int ui_textedit_step_next_utf8(const char *str, size_t maxlen, short *pos)
|
||||
@ -1308,12 +1333,13 @@ static void ui_textedit_step_utf8(const char *str, size_t maxlen,
|
||||
|
||||
if(direction) { /* right*/
|
||||
if(jump != BUTTON_EDIT_JUMP_NONE) {
|
||||
const uiButtonDelimType is_special= (*pos) < maxlen ? test_special_char(str[(*pos)]) : BUTTON_DELIM_NONE;
|
||||
/* jump between special characters (/,\,_,-, etc.),
|
||||
* look at function test_special_char() for complete
|
||||
* list of special character, ctr -> */
|
||||
while((*pos) < maxlen) {
|
||||
if (ui_textedit_step_next_utf8(str, maxlen, pos)) {
|
||||
if((jump != BUTTON_EDIT_JUMP_ALL) && test_special_char(str[(*pos)])) break;
|
||||
if((jump != BUTTON_EDIT_JUMP_ALL) && (is_special != test_special_char(str[(*pos)]))) break;
|
||||
}
|
||||
else {
|
||||
break; /* unlikely but just incase */
|
||||
@ -1326,6 +1352,7 @@ static void ui_textedit_step_utf8(const char *str, size_t maxlen,
|
||||
}
|
||||
else { /* left */
|
||||
if(jump != BUTTON_EDIT_JUMP_NONE) {
|
||||
const uiButtonDelimType is_special= (*pos) > 1 ? test_special_char(str[(*pos) - 1]) : BUTTON_DELIM_NONE;
|
||||
/* left only: compensate for index/change in direction */
|
||||
ui_textedit_step_prev_utf8(str, maxlen, pos);
|
||||
|
||||
@ -1334,7 +1361,7 @@ static void ui_textedit_step_utf8(const char *str, size_t maxlen,
|
||||
* list of special character, ctr -> */
|
||||
while ((*pos) > 0) {
|
||||
if (ui_textedit_step_prev_utf8(str, maxlen, pos)) {
|
||||
if((jump != BUTTON_EDIT_JUMP_ALL) && test_special_char(str[(*pos)])) break;
|
||||
if((jump != BUTTON_EDIT_JUMP_ALL) && (is_special != test_special_char(str[(*pos)]))) break;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user