diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-01-02 19:27:01 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-01-02 19:27:01 +0400 |
commit | 5c27b34fbf2751716f74acc5c952893e6a57e247 (patch) | |
tree | 7852719110107dfcd0b3f9199b652105ce08b205 /source/blender/editors/interface/interface_handlers.c | |
parent | 9dc085e0cb1a3356c6cb5a43b0ee2e81f1f9adbd (diff) |
nicer string delimiter handling for Ctrl+Left/Right arrows, py console could use this functon too.
Diffstat (limited to 'source/blender/editors/interface/interface_handlers.c')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 83 |
1 files changed, 55 insertions, 28 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 900cbbd5cbf..525b15ac7e3 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -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 '.': + return BUTTON_DELIM_PUNCT; + + case '{': + case '}': + case '[': + case ']': + case '(': + case ')': + return BUTTON_DELIM_BRACE; + + 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 ')': - case '+': - case '=': - case '{': - case '}': - case '[': - case ']': case ':': case ';': - case '\'': - case '\"': // " - an extra closing one for Aligorith's text editor - 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; |