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:
authorCampbell Barton <ideasman42@gmail.com>2018-04-05 16:22:33 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-04-05 16:22:33 +0300
commitad1ea9a427e3543a43ca2589f87f0c94b9be03ca (patch)
tree267fcc16524cd1336d2a55d08a497025a552d825 /source/blender/editors/space_text/text_ops.c
parent79c3c5689416014afd4fe417fac404c34b7a6cf0 (diff)
Undo: split text undo steps out of the data-block
This moves undo storage into a separate struct which is passed in from the undo system.
Diffstat (limited to 'source/blender/editors/space_text/text_ops.c')
-rw-r--r--source/blender/editors/space_text/text_ops.c73
1 files changed, 48 insertions, 25 deletions
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index 7580f22321b..223a3031f3b 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -731,7 +731,8 @@ static int text_paste_exec(bContext *C, wmOperator *op)
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
- txt_insert_buf(text, buf);
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+ txt_insert_buf(text, utxt, buf);
text_update_edited(text);
MEM_freeN(buf);
@@ -769,9 +770,11 @@ void TEXT_OT_paste(wmOperatorType *ot)
static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op))
{
Text *text = CTX_data_edit_text(C);
-
- txt_duplicate_line(text);
-
+
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+
+ txt_duplicate_line(text, utxt);
+
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
/* run the script while editing, evil but useful */
@@ -844,7 +847,9 @@ static int text_cut_exec(bContext *C, wmOperator *UNUSED(op))
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
txt_copy_clipboard(text);
- txt_delete_selected(text);
+
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+ txt_delete_selected(text, utxt);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
@@ -879,12 +884,15 @@ static int text_indent_exec(bContext *C, wmOperator *UNUSED(op))
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+
if (txt_has_sel(text)) {
txt_order_cursors(text, false);
- txt_indent(text);
+ txt_indent(text, utxt);
+ }
+ else {
+ txt_add_char(text, utxt, '\t');
}
- else
- txt_add_char(text, '\t');
text_update_edited(text);
@@ -917,8 +925,10 @@ static int text_unindent_exec(bContext *C, wmOperator *UNUSED(op))
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+
txt_order_cursors(text, false);
- txt_unindent(text);
+ txt_unindent(text, utxt);
text_update_edited(text);
@@ -956,14 +966,15 @@ static int text_line_break_exec(bContext *C, wmOperator *UNUSED(op))
// double check tabs/spaces before splitting the line
curts = txt_setcurr_tab_spaces(text, space);
- txt_split_curline(text);
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+ txt_split_curline(text, utxt);
for (a = 0; a < curts; a++) {
if (text->flags & TXT_TABSTOSPACES) {
- txt_add_char(text, ' ');
+ txt_add_char(text, utxt, ' ');
}
else {
- txt_add_char(text, '\t');
+ txt_add_char(text, utxt, '\t');
}
}
@@ -1003,8 +1014,10 @@ static int text_comment_exec(bContext *C, wmOperator *UNUSED(op))
if (txt_has_sel(text)) {
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+
txt_order_cursors(text, false);
- txt_comment(text);
+ txt_comment(text, utxt);
text_update_edited(text);
text_update_cursor_moved(C);
@@ -1039,8 +1052,10 @@ static int text_uncomment_exec(bContext *C, wmOperator *UNUSED(op))
if (txt_has_sel(text)) {
text_drawcache_tag_update(CTX_wm_space_text(C), 0);
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+
txt_order_cursors(text, false);
- txt_uncomment(text);
+ txt_uncomment(text, utxt);
text_update_edited(text);
text_update_cursor_moved(C);
@@ -1292,8 +1307,10 @@ static int move_lines_exec(bContext *C, wmOperator *op)
{
Text *text = CTX_data_edit_text(C);
const int direction = RNA_enum_get(op->ptr, "direction");
-
- txt_move_lines(text, direction);
+
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+
+ txt_move_lines(text, utxt, direction);
text_update_cursor_moved(C);
WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
@@ -1966,6 +1983,7 @@ static int text_delete_exec(bContext *C, wmOperator *op)
Text *text = CTX_data_edit_text(C);
int type = RNA_enum_get(op->ptr, "type");
+
text_drawcache_tag_update(st, 0);
/* behavior could be changed here,
@@ -1975,11 +1993,13 @@ static int text_delete_exec(bContext *C, wmOperator *op)
else if (type == DEL_NEXT_WORD) type = DEL_NEXT_CHAR;
}
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+
if (type == DEL_PREV_WORD) {
if (txt_cursor_is_line_start(text)) {
- txt_backspace_char(text);
+ txt_backspace_char(text, utxt);
}
- txt_backspace_word(text);
+ txt_backspace_word(text, utxt);
}
else if (type == DEL_PREV_CHAR) {
@@ -1995,13 +2015,13 @@ static int text_delete_exec(bContext *C, wmOperator *op)
}
}
- txt_backspace_char(text);
+ txt_backspace_char(text, utxt);
}
else if (type == DEL_NEXT_WORD) {
if (txt_cursor_is_line_end(text)) {
- txt_delete_char(text);
+ txt_delete_char(text, utxt);
}
- txt_delete_word(text);
+ txt_delete_word(text, utxt);
}
else if (type == DEL_NEXT_CHAR) {
@@ -2017,7 +2037,7 @@ static int text_delete_exec(bContext *C, wmOperator *op)
}
}
- txt_delete_char(text);
+ txt_delete_char(text, utxt);
}
text_update_line_edited(text->curl);
@@ -2870,16 +2890,18 @@ static int text_insert_exec(bContext *C, wmOperator *op)
str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+
if (st && st->overwrite) {
while (str[i]) {
code = BLI_str_utf8_as_unicode_step(str, &i);
- done |= txt_replace_char(text, code);
+ done |= txt_replace_char(text, utxt, code);
}
}
else {
while (str[i]) {
code = BLI_str_utf8_as_unicode_step(str, &i);
- done |= txt_add_char(text, code);
+ done |= txt_add_char(text, utxt, code);
}
}
@@ -2988,7 +3010,8 @@ static int text_find_and_replace(bContext *C, wmOperator *op, short mode)
if (found) {
if (mode == TEXT_REPLACE) {
- txt_insert_buf(text, st->replacestr);
+ TextUndoBuf *utxt = ED_text_undo_push_init(C);
+ txt_insert_buf(text, utxt, st->replacestr);
if (text->curl && text->curl->format) {
MEM_freeN(text->curl->format);
text->curl->format = NULL;