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
diff options
context:
space:
mode:
authorStephen Swaney <sswaney@centurytel.net>2005-04-10 18:01:41 +0400
committerStephen Swaney <sswaney@centurytel.net>2005-04-10 18:01:41 +0400
commite8a6bf6fb9b3acd11e03d318247ce33e53a5b692 (patch)
tree3c5cb2f1e5ece76e23f49ee64a74c4bef7fa061e /source/blender
parent28064baa5c9a86d1ed21f9712efa4082c229f4f7 (diff)
Bugfix for disappearing hilight bug and code re-org for text editor
from Ricki Myers (themyers). Comes with nice juicy commit msg, too! - source/blender/blenkernel/BKE_text.h - Removed indent_paste, uncommen, unindent_lines, comment_paste, uncomment_paste, uncomment, set_tabs. All these functions cut and re-added text (I felt this was unsafe). whicch is was caused the highlight loss. - Now the only functions are Indent, Unindent, comment, uncomment, setcurr_tab. All these functions only take one @parm (struct Text) -indent(struct Text *text) copy's the selected text in a MEM_mallocN line by line added a tab at the begginning - Unindent(struct Text *text) Tests if current line starts with a tab. if TAB remove it - comment(struct Text *text) copy's the selected text in a MEM_mallocN and adding a # at the begginning - Uncomment(struct Text *text) Tests if current line starts with a #. if # remove it - setcurr_tab (Text *text) Checks for Tabs pri. to any text if : is found and not in a comment then Tabs is increased by one if "return", "break", "pass" is found then Tabs is decreased - blender/source/blender/src/header_text.c Changed: txt_cut_sel(text); indent_paste(text); TO: txt_order_cursors(text); indent(text); * no more cutting of the text - source/blender/src/drawtext.c set_tabs(Text *text) just calls setcurr_tab(text);
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_text.h12
-rw-r--r--source/blender/blenkernel/intern/text.c284
-rw-r--r--source/blender/src/drawtext.c42
-rw-r--r--source/blender/src/header_text.c10
4 files changed, 199 insertions, 149 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index 71b8f1a4cc3..c76d6c9231b 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -89,17 +89,11 @@ void run_python_script (struct SpaceText *st);
int jumptoline_interactive (struct SpaceText *st);
void txt_export_to_object (struct Text *text);
void txt_export_to_objects(struct Text *text);
-void indent_paste (struct Text *text);
void unindent (struct Text *text);
void comment (struct Text *text);
-void uncommen (struct Text *text);
-void indent (struct Text *text, char *in_buffer);
-void unindent_lines (struct Text *text, char *in_buffer);
-void comment_paste (struct Text *text, char *in_buffer);
-void uncomment_paste (struct Text *text, char *in_buffer);
-void uncomment (struct Text *text);
-
-void set_tabs (struct Text *text);
+void indent (struct Text *text);
+void uncomment (struct Text *text);
+int setcurr_tab (struct Text *text);
/* Undo opcodes */
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 25ac2b46800..554c6940b84 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -1990,157 +1990,223 @@ int txt_add_char (Text *text, char add) {
return 1;
}
-//Antihc3(rick) used the paste function below
-//used txt_cut_sel, txt_insert_buf modified
-
-void indent_paste(Text *text)
-{
-
- indent(text, txt_cut_buffer);
-}
-
-void indent(Text *text, char *in_buffer)
+void indent(Text *text)
{
- int i=0, len;
-
+ int len, num;
+ char *tmp;
+ char add = '\t';
+
if (!text) return;
if (!text->curl) return;
if (!text->sell) return;
- if (!in_buffer) return;
-
- txt_delete_sel(text); //need to change this to remove the undo
-
- /* Read the first line (or as close as possible */
- len= strlen(in_buffer);
- while ( i < len ) {
- txt_add_char(text, '\t');
- while (in_buffer[i] && in_buffer[i]!='\n') {
- txt_add_char(text, in_buffer[i]);
- i++;
- }
-
- if (in_buffer[i]=='\n') {
- txt_add_char(text, '\n');
+ num = 0;
+ while (TRUE)
+ {
+ tmp= MEM_mallocN(text->curl->len+2, "textline_string");
+ text->curc = 0;
+ if(text->curc) memcpy(tmp, text->curl->line, text->curc);
+ tmp[text->curc]= add;
+
+ len= text->curl->len - text->curc;
+ if(len>0) memcpy(tmp+text->curc+1, text->curl->line+text->curc, len);
+ tmp[text->curl->len+1]=0;
+
+ make_new_line(text->curl, tmp);
+ text->curc++;
+
+ txt_make_dirty(text);
+ txt_clean_text(text);
+
+ if(text->curl == text->sell)
+ {
+ text->selc = text->sell->len;
+ break;
+ } else {
+ text->curl = text->curl->next;
+ num++;
}
- i++;
+ }
+ text->curc = 0;
+ while( num > 0 )
+ {
+ text->curl = text->curl->prev;
+ num--;
}
}
void unindent(Text *text)
{
- unindent_lines(text, txt_cut_buffer);
-}
-
-void unindent_lines(Text *text, char *in_buffer)
-{
- int i=0, len;
-
+ int num = 0;
+
if (!text) return;
if (!text->curl) return;
if (!text->sell) return;
- if (!in_buffer) return;
-
- txt_delete_sel(text);
-
- /* Read the first line (or as close as possible */
- len = strlen(in_buffer);
- while ( i < len ) {
- if (in_buffer[i] != '\t') {
- while (in_buffer[i] && in_buffer[i]!='\n') {
- txt_add_char(text, in_buffer[i]);
+
+ while(TRUE)
+ {
+ int i = 0;
+
+ if (text->curl->line[i] == '\t')
+ {
+ while(i< text->curl->len) {
+ text->curl->line[i]= text->curl->line[i+1];
i++;
}
-
- if (in_buffer[i]=='\n') {
- txt_add_char(text, '\n');
-
- }
- i++;
+ text->curl->len--;
}
- else {
- i++;
- while (in_buffer[i] && in_buffer[i]!='\n') {
- txt_add_char(text, in_buffer[i]);
- i++;
- }
-
- if (in_buffer[i]=='\n') {
- txt_add_char(text, '\n');
-
- }
- i++;
+
+
+ txt_make_dirty(text);
+ txt_clean_text(text);
+
+ if(text->curl == text->sell)
+ {
+ text->selc = text->sell->len;
+ break;
+ } else {
+ text->curl = text->curl->next;
+ num++;
}
+
+ }
+
+ while( num > 0 )
+ {
+ text->curl = text->curl->prev;
+ num--;
}
}
void comment(Text *text)
{
- comment_paste(text, txt_cut_buffer);
+ int len, num;
+ char *tmp;
+ char add = '#';
+
+ if (!text) return;
+ if (!text->curl) return;
+ if (!text->sell) return;
+ num = 0;
+ while (TRUE)
+ {
+ tmp= MEM_mallocN(text->curl->len+2, "textline_string");
+ text->curc = 0;
+ if(text->curc) memcpy(tmp, text->curl->line, text->curc);
+ tmp[text->curc]= add;
+
+ len= text->curl->len - text->curc;
+ if(len>0) memcpy(tmp+text->curc+1, text->curl->line+text->curc, len);
+ tmp[text->curl->len+1]=0;
+
+ make_new_line(text->curl, tmp);
+
+ text->curc++;
+
+ txt_make_dirty(text);
+ txt_clean_text(text);
+
+ if(text->curl == text->sell)
+ {
+ text->selc = text->sell->len;
+ break;
+ } else {
+ text->curl = text->curl->next;
+ num++;
+ }
+ }
+
+ while( num > 0 )
+ {
+ text->curl = text->curl->prev;
+ num--;
+ }
}
-void comment_paste(Text *text, char *in_buffer)
+void uncomment(Text *text)
{
- int i=0, len;
-
+ int num = 0;
+
if (!text) return;
if (!text->curl) return;
if (!text->sell) return;
- if (!in_buffer) return;
-
- txt_delete_sel(text);
-
- /* Read the first line (or as close as possible */
- len= strlen(in_buffer);
- while ( i < len ) {
- txt_add_char(text, '#');
- while (in_buffer[i] && in_buffer[i]!='\n') {
- txt_add_char(text, in_buffer[i]);
+ while(TRUE)
+ {
+ int i = 0;
+
+ if (text->curl->line[i] == '#')
+ {
+ while(i< text->curl->len) {
+ text->curl->line[i]= text->curl->line[i+1];
i++;
}
+ text->curl->len--;
+ }
+
+
+ txt_make_dirty(text);
+ txt_clean_text(text);
- if (in_buffer[i]=='\n') {
- txt_add_char(text, '\n');
-
- }
- i++;
+ if(text->curl == text->sell)
+ {
+ text->selc = text->sell->len;
+ break;
+ } else {
+ text->curl = text->curl->next;
+ num++;
}
+
+ }
+
+ while( num > 0 )
+ {
+ text->curl = text->curl->prev;
+ num--;
+ }
}
-
-void uncomment(Text *text)
-{
- uncomment_paste(text, txt_cut_buffer);
-}
-
-void uncomment_paste(Text *text, char *in_buffer)
+int setcurr_tab (Text *text)
{
-
- int i=0, len;
-
+ int i = 0;
+ int test = 0;
+ char *word = ":";
+ char *comm = "#";
+ char back_words[3][7] = {"return", "break", "pass"};
if (!text) return;
if (!text->curl) return;
- if (!text->sell) return;
-
- if (!in_buffer) return;
+
+ while (text->curl->line[i] == '\t')
+ {
+ //we only count thos tabs that are before any text or before the curs;
+ if (i == text->curc)
+ {
+ return i;
+ } else {
+ i++;
+ }
+ }
+ if(strstr(text->curl->line, word))
+ {
+ //if we find a : then add a tab but not if it is in a comment
+ if(strcspn(text->curl->line, word) < strcspn(text->curl->line, comm))
+ {
+ i++;
+ }
- txt_delete_sel(text);
+ }
- /* Read the first line (or as close as possible */
- len = strlen(in_buffer);
- while ( i < len ) {
- if (in_buffer[i] != '#') {
- while (in_buffer[i] && in_buffer[i]!='\n') {
- txt_add_char(text, in_buffer[i]);
- i++;
+ while(test < 3)
+ {
+ //if there are these 3 key words then remove a tab because we are done with the block
+ if(strstr(text->curl->line, back_words[test]) && i > 0)
+ {
+ if(strcspn(text->curl->line, back_words[test]) < strcspn(text->curl->line, comm))
+ {
+ i--;
}
-
- if (in_buffer[i]=='\n') {
- txt_add_char(text, '\n');
-
- }
}
- i++;
+ test++;
}
+ return i;
}
diff --git a/source/blender/src/drawtext.c b/source/blender/src/drawtext.c
index 94bc4801ede..b8a6d518bb3 100644
--- a/source/blender/src/drawtext.c
+++ b/source/blender/src/drawtext.c
@@ -989,23 +989,10 @@ void run_python_script(SpaceText *st)
}
}
-void set_tabs(Text *text) {
-
- TextLine *line = text->curl;
+void set_tabs(Text *text)
+{
SpaceText *st = curarea->spacedata.first;
- int pos = 0;
- int max;
- max = line->len;
- st->currtab_set = 0;
- while ( pos < max-1) {
- if (line->line[pos] == '\t') {
- st->currtab_set++;
- pos++;
- }
- else {
- pos++;
- }
- }
+ st->currtab_set = setcurr_tab(text);
}
void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
@@ -1357,29 +1344,34 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
case TABKEY:
if (G.qual & LR_SHIFTKEY) {
if (txt_has_sel(text)) {
- txt_cut_sel(text);
+ txt_order_cursors(text);
unindent(text);
}
} else {
if ( txt_has_sel(text)) {
- txt_cut_sel(text);
- indent_paste(text);
+ txt_order_cursors(text);
+ indent(text);
} else {
txt_add_char(text, '\t');
- st->currtab_set++;
}
}
pop_space_text(st);
do_draw= 1;
+ st->currtab_set = setcurr_tab(text);
break;
case RETKEY:
+ //double check tabs before splitting the line
+ st->currtab_set = setcurr_tab(text);
txt_split_curline(text);
{
int a = 0;
- while ( a < st->currtab_set) {
- txt_add_char(text, '\t');
- a++;
+ if (a < st->currtab_set)
+ {
+ while ( a < st->currtab_set) {
+ txt_add_char(text, '\t');
+ a++;
+ }
}
}
do_draw= 1;
@@ -1392,12 +1384,10 @@ void winqreadtextspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
pop_space_text(st);
break;
case DELKEY:
- if ( text->curl->line[text->curc] == '\t') {
- st->currtab_set--;
- }
txt_delete_char(text);
do_draw= 1;
pop_space_text(st);
+ st->currtab_set = setcurr_tab(text);
break;
case DOWNARROWKEY:
txt_move_down(text, G.qual & LR_SHIFTKEY);
diff --git a/source/blender/src/header_text.c b/source/blender/src/header_text.c
index 9478d28f4be..4ecc1afec5b 100644
--- a/source/blender/src/header_text.c
+++ b/source/blender/src/header_text.c
@@ -341,8 +341,8 @@ static void do_text_formatmenu(void *arg, int event)
switch(event) {
case 3:
if (txt_has_sel(text)) {
- txt_cut_sel(text);
- indent_paste(text);
+ txt_order_cursors(text);
+ indent(text);
break;
}
else {
@@ -351,21 +351,21 @@ static void do_text_formatmenu(void *arg, int event)
}
case 4:
if ( txt_has_sel(text)) {
- txt_cut_sel(text);
+ txt_order_cursors(text);
unindent(text);
break;
}
break;
case 5:
if ( txt_has_sel(text)) {
- txt_cut_sel(text);
+ txt_order_cursors(text);
comment(text);
break;
}
break;
case 6:
if ( txt_has_sel(text)) {
- txt_cut_sel(text);
+ txt_order_cursors(text);
uncomment(text);
break;
}