[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43074] trunk/blender/source/blender/ editors/interface/interface_handlers.c: nicer string delimiter handling for Ctrl+Left/Right arrows, py console could use this functon too.

Campbell Barton ideasman42 at gmail.com
Mon Jan 2 16:27:02 CET 2012


Revision: 43074
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43074
Author:   campbellbarton
Date:     2012-01-02 15:27:01 +0000 (Mon, 02 Jan 2012)
Log Message:
-----------
nicer string delimiter handling for Ctrl+Left/Right arrows, py console could use this functon too.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface_handlers.c

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-01-02 13:45:42 UTC (rev 43073)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-01-02 15:27:01 UTC (rev 43074)
@@ -114,6 +114,17 @@
 	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 @@
 /* ************* 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 '.':
+			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 ';':
-		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 @@
 
 	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 @@
 	}
 	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 @@
 			 * 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;



More information about the Bf-blender-cvs mailing list