[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45357] trunk/blender/source/blender/ editors/space_console: partial fix [#30777] python console utf-8 problem

Campbell Barton ideasman42 at gmail.com
Tue Apr 3 05:17:50 CEST 2012


Revision: 45357
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45357
Author:   campbellbarton
Date:     2012-04-03 03:17:49 +0000 (Tue, 03 Apr 2012)
Log Message:
-----------
partial fix [#30777] python console utf-8 problem

backspace/del now doesn't split up multi-byte characters.
Ctlr+Backspace/Del now work for deleting whole words.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_console/console_intern.h
    trunk/blender/source/blender/editors/space_console/console_ops.c
    trunk/blender/source/blender/editors/space_console/space_console.c

Modified: trunk/blender/source/blender/editors/space_console/console_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_console/console_intern.h	2012-04-03 02:52:34 UTC (rev 45356)
+++ trunk/blender/source/blender/editors/space_console/console_intern.h	2012-04-03 03:17:49 UTC (rev 45357)
@@ -64,6 +64,6 @@
 void CONSOLE_OT_select_set(struct wmOperatorType *ot);
 
 enum { LINE_BEGIN, LINE_END, PREV_CHAR, NEXT_CHAR, PREV_WORD, NEXT_WORD };
-enum { DEL_ALL, DEL_NEXT_CHAR, DEL_PREV_CHAR, DEL_SELECTION, DEL_NEXT_SEL, DEL_PREV_SEL };
+enum { DEL_ALL, DEL_NEXT_CHAR, DEL_PREV_CHAR, DEL_NEXT_WORD, DEL_PREV_WORD, DEL_SELECTION, DEL_NEXT_SEL, DEL_PREV_SEL };
 
 #endif /* __CONSOLE_INTERN_H__ */

Modified: trunk/blender/source/blender/editors/space_console/console_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/console_ops.c	2012-04-03 02:52:34 UTC (rev 45356)
+++ trunk/blender/source/blender/editors/space_console/console_ops.c	2012-04-03 03:17:49 UTC (rev 45357)
@@ -434,8 +434,8 @@
 static EnumPropertyItem console_delete_type_items[] = {
 	{DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
 	{DEL_PREV_CHAR, "PREVIOUS_CHARACTER", 0, "Previous Character", ""},
-//	{DEL_NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
-//	{DEL_PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
+	{DEL_NEXT_WORD, "NEXT_WORD", 0, "Next Word", ""},
+	{DEL_PREV_WORD, "PREVIOUS_WORD", 0, "Previous Word", ""},
 	{0, NULL, 0, NULL, NULL}
 };
 
@@ -444,6 +444,8 @@
 	SpaceConsole *sc = CTX_wm_space_console(C);
 	ARegion *ar = CTX_wm_region(C);
 	ConsoleLine *ci = console_history_verify(C);
+	int pos;
+	int stride;
 
 	const short type = RNA_enum_get(op->ptr, "type");
 	int done = 0;
@@ -454,22 +456,38 @@
 	
 	switch (type) {
 		case DEL_NEXT_CHAR:
+		case DEL_NEXT_WORD:
 			if (ci->cursor < ci->len) {
-				memmove(ci->line + ci->cursor, ci->line + ci->cursor + 1, (ci->len - ci->cursor) + 1);
-				ci->len--;
-				done = 1;
+				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);
+				stride = pos - ci->cursor;
+				if (stride) {
+					memmove(ci->line + ci->cursor, ci->line + ci->cursor + stride, (ci->len - ci->cursor) + 1);
+					ci->len -= stride;
+					done = 1;
+				}
 			}
 			break;
 		case DEL_PREV_CHAR:
+		case DEL_PREV_WORD:
 			if (ci->cursor > 0) {
-				ci->cursor--; /* same as above */
-				memmove(ci->line + ci->cursor, ci->line + ci->cursor + 1, (ci->len - ci->cursor) + 1);
-				ci->len--;
-				done = 1;
+				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);
+				stride = ci->cursor - pos;
+				if (stride) {
+					ci->cursor -= stride; /* same as above */
+					memmove(ci->line + ci->cursor, ci->line + ci->cursor + stride, (ci->len - ci->cursor) + 1);
+					ci->len -= stride;
+					done = 1;
+				}
 			}
 			break;
 	}
-	
+
 	if (!done) {
 		return OPERATOR_CANCELLED;
 	}

Modified: trunk/blender/source/blender/editors/space_console/space_console.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/space_console.c	2012-04-03 02:52:34 UTC (rev 45356)
+++ trunk/blender/source/blender/editors/space_console/space_console.c	2012-04-03 03:17:49 UTC (rev 45357)
@@ -303,19 +303,15 @@
 	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_move", DOWNARROWKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_LINE);
 	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_move", PAGEUPKEY, KM_PRESS, 0, 0)->ptr, "type", PREV_PAGE);
 	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_move", PAGEDOWNKEY, KM_PRESS, 0, 0)->ptr, "type", NEXT_PAGE);
-
-
-	//RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_CHAR);
-	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", DKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_CHAR);
-	//RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", BACKSPACEKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_PREV_CHAR);
-	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", DELKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_WORD);
-	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", BACKSPACEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_PREV_WORD);
 #endif
 	
 	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_CHAR);
 	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", BACKSPACEKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_PREV_CHAR);
 	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", BACKSPACEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", DEL_PREV_CHAR);  /* same as above [#26623] */
 
+	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", DELKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_WORD);
+	RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", BACKSPACEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_PREV_WORD);
+
 #ifdef WITH_PYTHON
 	WM_keymap_add_item(keymap, "CONSOLE_OT_execute", RETKEY, KM_PRESS, 0, 0); /* python operator - space_text.py */
 	WM_keymap_add_item(keymap, "CONSOLE_OT_execute", PADENTER, KM_PRESS, 0, 0);




More information about the Bf-blender-cvs mailing list