[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52218] trunk/blender/source/blender: Patch [#31006] Text editor undo buffer rework.

Justin Dailey dail8859 at yahoo.com
Thu Nov 15 00:10:21 CET 2012


Revision: 52218
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52218
Author:   dail
Date:     2012-11-14 23:10:19 +0000 (Wed, 14 Nov 2012)
Log Message:
-----------
Patch [#31006] Text editor undo buffer rework.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_text.h
    trunk/blender/source/blender/blenkernel/intern/text.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	2012-11-14 22:45:44 UTC (rev 52217)
+++ trunk/blender/source/blender/blenkernel/BKE_text.h	2012-11-14 23:10:19 UTC (rev 52218)
@@ -83,7 +83,7 @@
 char*	txt_sel_to_buf		(struct Text *text);
 void	txt_insert_buf		(struct Text *text, const char *in_buffer);
 void	txt_print_undo		(struct Text *text);
-void	txt_undo_add_toop	(struct Text *text, int op, unsigned int froml, unsigned short fromc, unsigned int tol, unsigned short toc);
+void	txt_undo_add_op		(struct Text *text, int op);
 void	txt_do_undo			(struct Text *text);
 void	txt_do_redo			(struct Text *text);
 void	txt_split_curline	(struct Text *text);
@@ -123,24 +123,6 @@
 
 /* Undo opcodes */
 
-/* Simple main cursor movement */
-#define UNDO_CLEFT		001
-#define UNDO_CRIGHT		002
-#define UNDO_CUP		003
-#define UNDO_CDOWN		004
-
-/* Simple selection cursor movement */
-#define UNDO_SLEFT		005
-#define UNDO_SRIGHT		006
-#define UNDO_SUP		007
-#define UNDO_SDOWN		010
-
-/* Complex movement (opcode is followed
- * by 4 character line ID + a 2 character
- * position ID and opcode (repeat)) */
-#define UNDO_CTO		011
-#define UNDO_STO		012
-
 /* Complex editing */
 /* 1 - opcode is followed by 1 byte for ascii character and opcode (repeat)) */
 /* 2 - opcode is followed by 2 bytes for utf-8 character and opcode (repeat)) */
@@ -169,8 +151,6 @@
 #define UNDO_IBLOCK     030 /* Insert block */
 
 /* Misc */
-#define UNDO_SWAP       031	/* Swap cursors */
-
 #define UNDO_INDENT     032
 #define UNDO_UNINDENT   033
 #define UNDO_COMMENT    034

Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c	2012-11-14 22:45:44 UTC (rev 52217)
+++ trunk/blender/source/blender/blenkernel/intern/text.c	2012-11-14 23:10:19 UTC (rev 52218)
@@ -136,8 +136,7 @@
 
 static void txt_pop_first(Text *text);
 static void txt_pop_last(Text *text);
-static void txt_undo_add_op(Text *text, int op);
-static void txt_undo_add_block(Text *text, int op, const char *buf);
+static void txt_undo_add_blockop(Text *text, int op, const char *buf);
 static void txt_delete_line(Text *text, TextLine *line);
 static void txt_delete_sel(Text *text);
 static void txt_make_dirty(Text *text);
@@ -785,23 +784,6 @@
 	*linep = &text->sell; *charp = &text->selc;
 }
 
-static void txt_curs_first(Text *text, TextLine **linep, int *charp)
-{
-	if (text->curl == text->sell) {
-		*linep = text->curl;
-		if (text->curc < text->selc) *charp = text->curc;
-		else *charp = text->selc;
-	}
-	else if (txt_get_span(text->lines.first, text->curl) < txt_get_span(text->lines.first, text->sell)) {
-		*linep = text->curl;
-		*charp = text->curc;
-	}
-	else {
-		*linep = text->sell;
-		*charp = text->selc;
-	}
-}
-
 /*****************************/
 /* Cursor movement functions */
 /*****************************/
@@ -843,13 +825,11 @@
 {
 	TextLine **linep;
 	int *charp;
-	/* int old; */ /* UNUSED */
 	
 	if (!text) return;
 	if (sel) txt_curs_sel(text, &linep, &charp);
 	else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); }
 	if (!*linep) return;
-	/* old = *charp; */ /* UNUSED */
 
 	if ((*linep)->prev) {
 		int index = txt_utf8_offset_to_index((*linep)->line, *charp);
@@ -857,8 +837,6 @@
 		if (index > txt_utf8_len((*linep)->line)) *charp = (*linep)->len;
 		else *charp = txt_utf8_index_to_offset((*linep)->line, index);
 		
-		if (!undoing)
-			txt_undo_add_op(text, sel ? UNDO_SUP : UNDO_CUP);
 	}
 	else {
 		txt_move_bol(text, sel);
@@ -871,22 +849,17 @@
 {
 	TextLine **linep;
 	int *charp;
-	/* int old; */ /* UNUSED */
 	
 	if (!text) return;
 	if (sel) txt_curs_sel(text, &linep, &charp);
 	else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); }
 	if (!*linep) return;
-	/* old = *charp; */ /* UNUSED */
 
 	if ((*linep)->next) {
 		int index = txt_utf8_offset_to_index((*linep)->line, *charp);
 		*linep = (*linep)->next;
 		if (index > txt_utf8_len((*linep)->line)) *charp = (*linep)->len;
 		else *charp = txt_utf8_index_to_offset((*linep)->line, index);
-		
-		if (!undoing)
-			txt_undo_add_op(text, sel ? UNDO_SDOWN : UNDO_CDOWN);
 	}
 	else {
 		txt_move_eol(text, sel);
@@ -898,7 +871,7 @@
 void txt_move_left(Text *text, short sel) 
 {
 	TextLine **linep;
-	int *charp, oundoing = undoing;
+	int *charp;
 	int tabsize = 0, i = 0;
 	
 	if (!text) return;
@@ -906,8 +879,6 @@
 	else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); }
 	if (!*linep) return;
 
-	undoing = 1;
-
 	if (*charp == 0) {
 		if ((*linep)->prev) {
 			txt_move_up(text, sel);
@@ -939,24 +910,19 @@
 		}
 	}
 
-	undoing = oundoing;
-	if (!undoing) txt_undo_add_op(text, sel ? UNDO_SLEFT : UNDO_CLEFT);
-	
 	if (!sel) txt_pop_sel(text);
 }
 
 void txt_move_right(Text *text, short sel) 
 {
 	TextLine **linep;
-	int *charp, oundoing = undoing, do_tab = FALSE, i;
+	int *charp, do_tab = FALSE, i;
 	
 	if (!text) return;
 	if (sel) txt_curs_sel(text, &linep, &charp);
 	else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); }
 	if (!*linep) return;
 
-	undoing = 1;
-
 	if (*charp == (*linep)->len) {
 		if ((*linep)->next) {
 			txt_move_down(text, sel);
@@ -984,124 +950,103 @@
 		else (*charp) += BLI_str_utf8_size((*linep)->line + *charp);
 	}
 	
-	undoing = oundoing;
-	if (!undoing) txt_undo_add_op(text, sel ? UNDO_SRIGHT : UNDO_CRIGHT);
-
 	if (!sel) txt_pop_sel(text);
 }
 
 void txt_jump_left(Text *text, short sel)
 {
 	TextLine **linep;
-	int *charp, oldc;
+	int *charp;
 	
 	if (!text) return;
 	if (sel) txt_curs_sel(text, &linep, &charp);
 	else { txt_pop_first(text); txt_curs_cur(text, &linep, &charp); }
 	if (!*linep) return;
-	oldc = *charp;
 
 	BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len,
 	                         charp, STRCUR_DIR_PREV,
 	                         STRCUR_JUMP_DELIM);
 	
 	if (!sel) txt_pop_sel(text);
-	if (!undoing) {
-		int span = txt_get_span(text->lines.first, *linep);
-		txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, span, oldc, span, (unsigned short)*charp);
-	}
 }
 
 void txt_jump_right(Text *text, short sel)
 {
 	TextLine **linep;
-	int *charp, oldc;
+	int *charp;
 	
 	if (!text) return;
 	if (sel) txt_curs_sel(text, &linep, &charp);
 	else { txt_pop_last(text); txt_curs_cur(text, &linep, &charp); }
 	if (!*linep) return;
-	oldc = *charp;
 	
 	BLI_str_cursor_step_utf8((*linep)->line, (*linep)->len,
 	                         charp, STRCUR_DIR_NEXT,
 	                         STRCUR_JUMP_DELIM);
 	
 	if (!sel) txt_pop_sel(text);
-	if (!undoing) {
-		int span = txt_get_span(text->lines.first, *linep);
-		txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, span, oldc, span, (unsigned short)*charp);
-	}
 }
 
 void txt_move_bol(Text *text, short sel)
 {
 	TextLine **linep;
-	int *charp, old;
+	int *charp;
 	
 	if (!text) return;
 	if (sel) txt_curs_sel(text, &linep, &charp);
 	else txt_curs_cur(text, &linep, &charp);
 	if (!*linep) return;
-	old = *charp;
 	
 	*charp = 0;
 
 	if (!sel) txt_pop_sel(text);
-	if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
 }
 
 void txt_move_eol(Text *text, short sel)
 {
 	TextLine **linep;
-	int *charp, old;
+	int *charp;
 	
 	if (!text) return;
 	if (sel) txt_curs_sel(text, &linep, &charp);
 	else txt_curs_cur(text, &linep, &charp);
 	if (!*linep) return;
-	old = *charp;
-		
+
 	*charp = (*linep)->len;
 
 	if (!sel) txt_pop_sel(text);
-	if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
 }
 
 void txt_move_bof(Text *text, short sel)
 {
 	TextLine **linep;
-	int *charp, old;
+	int *charp;
 	
 	if (!text) return;
 	if (sel) txt_curs_sel(text, &linep, &charp);
 	else txt_curs_cur(text, &linep, &charp);
 	if (!*linep) return;
-	old = *charp;
 
 	*linep = text->lines.first;
 	*charp = 0;
 
 	if (!sel) txt_pop_sel(text);
-	if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
 }
 
 void txt_move_eof(Text *text, short sel)
 {
 	TextLine **linep;
-	int *charp, old;
+	int *charp;
 	
 	if (!text) return;
 	if (sel) txt_curs_sel(text, &linep, &charp);
 	else txt_curs_cur(text, &linep, &charp);
 	if (!*linep) return;
-	old = *charp;
 
 	*linep = text->lines.last;
 	*charp = (*linep)->len;
 
 	if (!sel) txt_pop_sel(text);
-	if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, *linep), old, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
 }
 
 void txt_move_toline(Text *text, unsigned int line, short sel)
@@ -1112,16 +1057,14 @@
 /* Moves to a certain byte in a line, not a certain utf8-character! */
 void txt_move_to(Text *text, unsigned int line, unsigned int ch, short sel)
 {
-	TextLine **linep, *oldl;
-	int *charp, oldc;
+	TextLine **linep;
+	int *charp;
 	unsigned int i;
 	
 	if (!text) return;
 	if (sel) txt_curs_sel(text, &linep, &charp);
 	else txt_curs_cur(text, &linep, &charp);
 	if (!*linep) return;
-	oldc = *charp;
-	oldl = *linep;
 	
 	*linep = text->lines.first;
 	for (i = 0; i < line; i++) {
@@ -1133,7 +1076,6 @@
 	*charp = ch;
 	
 	if (!sel) txt_pop_sel(text);
-	if (!undoing) txt_undo_add_toop(text, sel ? UNDO_STO : UNDO_CTO, txt_get_span(text->lines.first, oldl), oldc, txt_get_span(text->lines.first, *linep), (unsigned short)*charp);
 }
 
 /****************************/
@@ -1152,8 +1094,6 @@
 	tmpc = text->curc;
 	text->curc = text->selc;
 	text->selc = tmpc;
-	
-	if (!undoing) txt_undo_add_op(text, UNDO_SWAP);
 }
 
 static void txt_pop_first(Text *text)
@@ -1164,12 +1104,6 @@
 	{
 		txt_curs_swap(text);
 	}
-
-	if (!undoing) txt_undo_add_toop(text, UNDO_STO,
-		                            txt_get_span(text->lines.first, text->sell),
-		                            text->selc,
-		                            txt_get_span(text->lines.first, text->curl),
-		                            text->curc);
 	
 	txt_pop_sel(text);
 }
@@ -1181,12 +1115,6 @@
 	{
 		txt_curs_swap(text);
 	}
-
-	if (!undoing) txt_undo_add_toop(text, UNDO_STO,
-		                            txt_get_span(text->lines.first, text->sell),
-		                            text->selc,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list