Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorStephen Swaney <sswaney@centurytel.net>2005-12-12 21:35:15 +0300
committerStephen Swaney <sswaney@centurytel.net>2005-12-12 21:35:15 +0300
commitd32b100464d3d1778a76ae00354ed5885acd574c (patch)
tree0d40862c60091b86b2fc6d274569be6340a377a4 /source
parentc452e8672cbf374ecdf55d76653424b27af00582 (diff)
bugfix: #3420 Indent/Unindent in text editor not undoable
contributed by Mr. TextEditor - themyers. Thanks!
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_text.h5
-rw-r--r--source/blender/blenkernel/intern/text.c165
2 files changed, 161 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index c76d6c9231b..447a94dd487 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -131,6 +131,11 @@ int setcurr_tab (struct Text *text);
/* Misc */
#define UNDO_SWAP 031 /* Swap cursors */
+#define UNDO_INDENT 032
+#define UNDO_UNINDENT 033
+#define UNDO_COMMENT 034
+#define UNDO_UNCOMMENT 035
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 4557bd0404d..330d46c959f 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -1337,6 +1337,14 @@ void txt_print_undo(Text *text)
ops= "Delete text block";
} else if (op==UNDO_IBLOCK) {
ops= "Insert text block";
+ } else if (op==UNDO_INDENT) {
+ ops= "Indent ";
+ } else if (op==UNDO_UNINDENT) {
+ ops= "Unindent ";
+ } else if (op==UNDO_COMMENT) {
+ ops= "Comment ";
+ } else if (op==UNDO_UNCOMMENT) {
+ ops= "Uncomment ";
} else {
ops= "Unknown";
}
@@ -1388,6 +1396,28 @@ void txt_print_undo(Text *text)
linep= linep+(text->undo_buf[i]<<16); i++;
linep= linep+(text->undo_buf[i]<<24); i++;
printf ("> (%d)", linep);
+ } else if (op==UNDO_INDENT || op==UNDO_UNINDENT) {
+ i++;
+
+ charp= text->undo_buf[i]; i++;
+ charp= charp+(text->undo_buf[i]<<8); i++;
+
+ linep= text->undo_buf[i]; i++;
+ linep= linep+(text->undo_buf[i]<<8); i++;
+ linep= linep+(text->undo_buf[i]<<16); i++;
+ linep= linep+(text->undo_buf[i]<<24); i++;
+
+ printf ("to <%d, %d> ", linep, charp);
+
+ charp= text->undo_buf[i]; i++;
+ charp= charp+(text->undo_buf[i]<<8); i++;
+
+ linep= text->undo_buf[i]; i++;
+ linep= linep+(text->undo_buf[i]<<8); i++;
+ linep= linep+(text->undo_buf[i]<<16); i++;
+ linep= linep+(text->undo_buf[i]<<24); i++;
+
+ printf ("from <%d, %d>", linep, charp);
}
printf (" %d\n", i);
@@ -1660,7 +1690,54 @@ void txt_do_undo(Text *text)
text->undo_pos--;
break;
+ case UNDO_INDENT:
+ case UNDO_UNINDENT:
+ case UNDO_COMMENT:
+ case UNDO_UNCOMMENT:
+ linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ //linep is now the end line of the selection
+
+ charp = text->undo_buf[text->undo_pos]; text->undo_pos--;
+ charp = (charp<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ //charp is the last char selected or text->line->len
+ //set the selcetion for this now
+ text->selc = charp;
+ text->sell = text->lines.first;
+ for (i= 0; i < linep; i++) {
+ text->sell = text->sell->next;
+ }
+
+ linep= text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ linep = (linep<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ //first line to be selected
+
+ charp = text->undo_buf[text->undo_pos]; text->undo_pos--;
+ charp = (charp<<8)+text->undo_buf[text->undo_pos]; text->undo_pos--;
+ //first postion to be selected
+ text->curc = charp;
+ text->curl = text->lines.first;
+ for (i = 0; i < linep; i++) {
+ text->curl = text->curl->next;
+ }
+
+ if (op==UNDO_INDENT) {
+ unindent(text);
+ } else if (op== UNDO_UNINDENT) {
+ indent(text);
+ } else if (op == UNDO_COMMENT) {
+ uncomment(text);
+ } else if (op == UNDO_UNCOMMENT) {
+ comment(text);
+ }
+
+ text->undo_pos--;
+ break;
default:
error("Undo buffer error - resetting");
text->undo_pos= -1;
@@ -1677,6 +1754,7 @@ void txt_do_redo(Text *text)
unsigned int linep;
unsigned short charp;
char *buf;
+ int i;
text->undo_pos++;
op= text->undo_buf[text->undo_pos];
@@ -1687,7 +1765,7 @@ void txt_do_redo(Text *text)
}
undoing= 1;
-
+
switch(op) {
case UNDO_CLEFT:
txt_move_left(text, 0);
@@ -1815,7 +1893,52 @@ void txt_do_redo(Text *text)
linep= linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
break;
+ case UNDO_INDENT:
+ case UNDO_UNINDENT:
+ case UNDO_COMMENT:
+ case UNDO_UNCOMMENT:
+ text->undo_pos++;
+ charp = text->undo_buf[text->undo_pos]; text->undo_pos++;
+ charp = charp+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
+ //charp is the first char selected or 0
+
+ linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
+ linep = linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
+ linep = linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
+ linep = linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
+ //linep is now the first line of the selection
+ //set the selcetion for this now
+ text->curc = charp;
+ text->curl = text->lines.first;
+ for (i= 0; i < linep; i++) {
+ text->curl = text->curl->next;
+ }
+
+ charp = text->undo_buf[text->undo_pos]; text->undo_pos++;
+ charp = charp+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
+ //last postion to be selected
+ linep= text->undo_buf[text->undo_pos]; text->undo_pos++;
+ linep = linep+(text->undo_buf[text->undo_pos]<<8); text->undo_pos++;
+ linep = linep+(text->undo_buf[text->undo_pos]<<16); text->undo_pos++;
+ linep = linep+(text->undo_buf[text->undo_pos]<<24); text->undo_pos++;
+ //Last line to be selected
+
+ text->selc = charp;
+ text->sell = text->lines.first;
+ for (i = 0; i < linep; i++) {
+ text->sell = text->sell->next;
+ }
+ if (op==UNDO_INDENT) {
+ indent(text);
+ } else if (op== UNDO_UNINDENT) {
+ unindent(text);
+ } else if (op == UNDO_COMMENT) {
+ comment(text);
+ } else if (op == UNDO_UNCOMMENT) {
+ uncomment(text);
+ }
+ break;
default:
error("Undo buffer error - resetting");
text->undo_pos= -1;
@@ -2033,6 +2156,7 @@ void indent(Text *text)
if (!text) return;
if (!text->curl) return;
if (!text->sell) return;
+
num = 0;
while (TRUE)
{
@@ -2069,21 +2193,27 @@ void indent(Text *text)
text->curl = text->curl->prev;
num--;
}
+
+ if(!undoing)
+ {
+ txt_undo_add_toop(text, UNDO_INDENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc);
+ }
}
void unindent(Text *text)
{
int num = 0;
+ char remove = '\t';
if (!text) return;
if (!text->curl) return;
if (!text->sell) return;
-
+
while(TRUE)
{
int i = 0;
- if (text->curl->line[i] == '\t')
+ if (text->curl->line[i] == remove)
{
while(i< text->curl->len) {
text->curl->line[i]= text->curl->line[i+1];
@@ -2106,12 +2236,17 @@ void unindent(Text *text)
}
}
-
+ text->curc = 0;
while( num > 0 )
{
text->curl = text->curl->prev;
num--;
}
+
+ if(!undoing)
+ {
+ txt_undo_add_toop(text, UNDO_UNINDENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc);
+ }
}
void comment(Text *text)
@@ -2122,7 +2257,8 @@ void comment(Text *text)
if (!text) return;
if (!text->curl) return;
- if (!text->sell) return;
+ if (!text->sell) return;// Need to change this need to check if only one line is selected ot more then one
+
num = 0;
while (TRUE)
{
@@ -2153,27 +2289,33 @@ void comment(Text *text)
num++;
}
}
-
+ text->curc = 0;
while( num > 0 )
{
text->curl = text->curl->prev;
num--;
}
+
+ if(!undoing)
+ {
+ txt_undo_add_toop(text, UNDO_COMMENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc);
+ }
}
void uncomment(Text *text)
{
int num = 0;
+ char remove = '#';
if (!text) return;
if (!text->curl) return;
if (!text->sell) return;
-
+
while(TRUE)
{
int i = 0;
- if (text->curl->line[i] == '#')
+ if (text->curl->line[i] == remove)
{
while(i< text->curl->len) {
text->curl->line[i]= text->curl->line[i+1];
@@ -2196,12 +2338,17 @@ void uncomment(Text *text)
}
}
-
+ text->curc = 0;
while( num > 0 )
{
text->curl = text->curl->prev;
num--;
}
+
+ if(!undoing)
+ {
+ txt_undo_add_toop(text, UNDO_UNCOMMENT, txt_get_span(text->lines.first, text->curl), text->curc, txt_get_span(text->lines.first, text->sell), text->selc);
+ }
}
int setcurr_tab (Text *text)