[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54543] trunk/blender/source/blender: fix for double clicking in the text editor not working usefully ( double clicking a pair chars would select 3 - one to the left).

Campbell Barton ideasman42 at gmail.com
Thu Feb 14 04:03:14 CET 2013


Revision: 54543
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54543
Author:   campbellbarton
Date:     2013-02-14 03:03:12 +0000 (Thu, 14 Feb 2013)
Log Message:
-----------
fix for double clicking in the text editor not working usefully (double clicking a pair chars would select 3 - one to the left).

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_text.h
    trunk/blender/source/blender/blenkernel/intern/text.c
    trunk/blender/source/blender/blenlib/BLI_string_cursor_utf8.h
    trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/space_console/console_ops.c
    trunk/blender/source/blender/editors/space_text/text_ops.c

Modified: trunk/blender/source/blender/blenkernel/BKE_text.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_text.h	2013-02-14 02:21:12 UTC (rev 54542)
+++ trunk/blender/source/blender/blenkernel/BKE_text.h	2013-02-14 03:03:12 UTC (rev 54543)
@@ -66,8 +66,8 @@
 void	txt_move_down		(struct Text *text, short sel);
 void	txt_move_left		(struct Text *text, short sel);
 void	txt_move_right		(struct Text *text, short sel);
-void	txt_jump_left		(struct Text *text, short sel);
-void	txt_jump_right		(struct Text *text, short sel);
+void	txt_jump_left		(struct Text *text, bool sel, bool use_init_step);
+void	txt_jump_right		(struct Text *text, bool sel, bool use_init_step);
 void	txt_move_bof		(struct Text *text, short sel);
 void	txt_move_eof		(struct Text *text, short sel);
 void	txt_move_bol		(struct Text *text, short sel);

Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c	2013-02-14 02:21:12 UTC (rev 54542)
+++ trunk/blender/source/blender/blenkernel/intern/text.c	2013-02-14 03:03:12 UTC (rev 54543)
@@ -38,12 +38,12 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_utildefines.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
 #include "BLI_string_cursor_utf8.h"
 #include "BLI_string_utf8.h"
 #include "BLI_listbase.h"
-#include "BLI_utildefines.h"
 #include "BLI_fileops.h"
 
 #include "DNA_constraint_types.h"
@@ -936,7 +936,7 @@
 	if (!sel) txt_pop_sel(text);
 }
 
-void txt_jump_left(Text *text, short sel)
+void txt_jump_left(Text *text, bool sel, bool use_init_step)
 {
 	TextLine **linep;
 	int *charp;
@@ -948,12 +948,12 @@
 
 	BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len,
 	                         charp, STRCUR_DIR_PREV,
-	                         STRCUR_JUMP_DELIM);
+	                         STRCUR_JUMP_DELIM, use_init_step);
 	
 	if (!sel) txt_pop_sel(text);
 }
 
-void txt_jump_right(Text *text, short sel)
+void txt_jump_right(Text *text, bool sel, bool use_init_step)
 {
 	TextLine **linep;
 	int *charp;
@@ -965,7 +965,7 @@
 	
 	BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len,
 	                         charp, STRCUR_DIR_NEXT,
-	                         STRCUR_JUMP_DELIM);
+	                         STRCUR_JUMP_DELIM, use_init_step);
 	
 	if (!sel) txt_pop_sel(text);
 }
@@ -2402,7 +2402,7 @@
 
 void txt_delete_word(Text *text)
 {
-	txt_jump_right(text, 1);
+	txt_jump_right(text, true, true);
 	txt_delete_sel(text);
 }
 
@@ -2451,7 +2451,7 @@
 
 void txt_backspace_word(Text *text)
 {
-	txt_jump_left(text, 1);
+	txt_jump_left(text, true, true);
 	txt_delete_sel(text);
 }
 

Modified: trunk/blender/source/blender/blenlib/BLI_string_cursor_utf8.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_string_cursor_utf8.h	2013-02-14 02:21:12 UTC (rev 54542)
+++ trunk/blender/source/blender/blenlib/BLI_string_cursor_utf8.h	2013-02-14 03:03:12 UTC (rev 54543)
@@ -46,6 +46,6 @@
 
 void BLI_str_cursor_step_utf8(const char *str, size_t maxlen,
                               int *pos, strCursorJumpDirection direction,
-                              strCursorJumpType jump);
+                              strCursorJumpType jump, bool use_init_step);
 
 #endif /* __BLI_STRING_CURSOR_UTF8_H__ */

Modified: trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c	2013-02-14 02:21:12 UTC (rev 54542)
+++ trunk/blender/source/blender/blenlib/intern/string_cursor_utf8.c	2013-02-14 03:03:12 UTC (rev 54543)
@@ -139,12 +139,15 @@
 
 void BLI_str_cursor_step_utf8(const char *str, size_t maxlen,
                               int *pos, strCursorJumpDirection direction,
-                              strCursorJumpType jump)
+                              strCursorJumpType jump, bool use_init_step)
 {
 	const int pos_prev = *pos;
 
 	if (direction == STRCUR_DIR_NEXT) {
-		BLI_str_cursor_step_next_utf8(str, maxlen, pos);
+		if (use_init_step) {
+			BLI_assert(jump == STRCUR_JUMP_DELIM);
+			BLI_str_cursor_step_next_utf8(str, maxlen, pos);
+		}
 
 		if (jump != STRCUR_JUMP_NONE) {
 			const strCursorDelimType delim_type = (*pos) < maxlen ? cursor_delim_type(&str[*pos]) : STRCUR_DELIM_NONE;
@@ -163,7 +166,10 @@
 		}
 	}
 	else if (direction == STRCUR_DIR_PREV) {
-		BLI_str_cursor_step_prev_utf8(str, maxlen, pos);
+		if (use_init_step) {
+			BLI_assert(jump == STRCUR_JUMP_DELIM);
+			BLI_str_cursor_step_prev_utf8(str, maxlen, pos);
+		}
 
 		if (jump != STRCUR_JUMP_NONE) {
 			const strCursorDelimType delim_type = (*pos) > 1 ? cursor_delim_type(&str[(*pos) - 1]) : STRCUR_DELIM_NONE;

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2013-02-14 02:21:12 UTC (rev 54542)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2013-02-14 03:03:12 UTC (rev 54543)
@@ -1610,7 +1610,7 @@
 	}
 	else {
 		int pos_i = but->pos;
-		BLI_str_cursor_step_utf8(str, len, &pos_i, direction, jump);
+		BLI_str_cursor_step_utf8(str, len, &pos_i, direction, jump, true);
 		but->pos = pos_i;
 
 		if (select) {
@@ -1679,7 +1679,7 @@
 		else if (but->pos >= 0 && but->pos < len) {
 			int pos = but->pos;
 			int step;
-			BLI_str_cursor_step_utf8(str, len, &pos, direction, jump);
+			BLI_str_cursor_step_utf8(str, len, &pos, direction, jump, true);
 			step = pos - but->pos;
 			memmove(&str[but->pos], &str[but->pos + step], (len + 1) - but->pos);
 			changed = 1;
@@ -1694,7 +1694,7 @@
 				int pos = but->pos;
 				int step;
 
-				BLI_str_cursor_step_utf8(str, len, &pos, direction, jump);
+				BLI_str_cursor_step_utf8(str, len, &pos, direction, jump, true);
 				step = but->pos - pos;
 				memmove(&str[but->pos - step], &str[but->pos], (len + 1) - but->pos);
 				but->pos -= step;

Modified: trunk/blender/source/blender/editors/space_console/console_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/console_ops.c	2013-02-14 02:21:12 UTC (rev 54542)
+++ trunk/blender/source/blender/editors/space_console/console_ops.c	2013-02-14 03:03:12 UTC (rev 54543)
@@ -34,12 +34,12 @@
 
 #include "DNA_userdef_types.h"
 
+#include "BLI_utildefines.h"
 #include "BLI_listbase.h"
 #include "BLI_string_cursor_utf8.h"
 #include "BLI_string_utf8.h"
 #include "BLI_string.h"
 #include "BLI_dynstr.h"
-#include "BLI_utildefines.h"
 #include "BLI_math.h"
 
 #include "BKE_context.h"
@@ -284,28 +284,28 @@
 			pos = ci->cursor;
 			BLI_str_cursor_step_utf8(ci->line, ci->len,
 			                         &pos, STRCUR_DIR_PREV,
-			                         STRCUR_JUMP_ALL);
+			                         STRCUR_JUMP_ALL, true);
 			done = console_line_cursor_set(ci, pos);
 			break;
 		case LINE_END:
 			pos = ci->cursor;
 			BLI_str_cursor_step_utf8(ci->line, ci->len,
 			                         &pos, STRCUR_DIR_NEXT,
-			                         STRCUR_JUMP_ALL);
+			                         STRCUR_JUMP_ALL, true);
 			done = console_line_cursor_set(ci, pos);
 			break;
 		case PREV_CHAR:
 			pos = ci->cursor;
 			BLI_str_cursor_step_utf8(ci->line, ci->len,
 			                         &pos, STRCUR_DIR_PREV,
-			                         STRCUR_JUMP_NONE);
+			                         STRCUR_JUMP_NONE, true);
 			done = console_line_cursor_set(ci, pos);
 			break;
 		case NEXT_CHAR:
 			pos = ci->cursor;
 			BLI_str_cursor_step_utf8(ci->line, ci->len,
 			                         &pos, STRCUR_DIR_NEXT,
-			                         STRCUR_JUMP_NONE);
+			                         STRCUR_JUMP_NONE, true);
 			done = console_line_cursor_set(ci, pos);
 			break;
 
@@ -315,14 +315,14 @@
 			pos = ci->cursor;
 			BLI_str_cursor_step_utf8(ci->line, ci->len,
 			                         &pos, STRCUR_DIR_PREV,
-			                         STRCUR_JUMP_DELIM);
+			                         STRCUR_JUMP_DELIM, true);
 			done = console_line_cursor_set(ci, pos);
 			break;
 		case NEXT_WORD:
 			pos = ci->cursor;
 			BLI_str_cursor_step_utf8(ci->line, ci->len,
 			                         &pos, STRCUR_DIR_NEXT,
-			                         STRCUR_JUMP_DELIM);
+			                         STRCUR_JUMP_DELIM, true);
 			done = console_line_cursor_set(ci, pos);
 			break;
 	}
@@ -562,7 +562,7 @@
 				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);
+				                         (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true);
 				stride = pos - ci->cursor;
 				if (stride) {
 					memmove(ci->line + ci->cursor, ci->line + ci->cursor + stride, (ci->len - ci->cursor) + 1);
@@ -578,7 +578,7 @@
 				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);
+				                         (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true);
 				stride = ci->cursor - pos;
 				if (stride) {
 					ci->cursor -= stride; /* same as above */

Modified: trunk/blender/source/blender/editors/space_text/text_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_ops.c	2013-02-14 02:21:12 UTC (rev 54542)
+++ trunk/blender/source/blender/editors/space_text/text_ops.c	2013-02-14 03:03:12 UTC (rev 54543)
@@ -1312,9 +1312,11 @@
 static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Text *text = CTX_data_edit_text(C);
+	/* don't advance cursor before stepping */
+	const bool use_init_step = false;
 
-	txt_jump_left(text, 0);
-	txt_jump_right(text, 1);
+	txt_jump_left(text, false, use_init_step);
+	txt_jump_right(text, true, use_init_step);
 
 	text_update_cursor_moved(C);
 	WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
@@ -1816,11 +1818,11 @@
 			break;
 
 		case PREV_WORD:
-			txt_jump_left(text, select);
+			txt_jump_left(text, select, true);
 			break;
 
 		case NEXT_WORD:

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list