[Bf-blender-cvs] [5dd14a4fad1] temp-text-undo-memcmp: Remove text undo code (in favor of binary diffing the entire buffer)
Campbell Barton
noreply at git.blender.org
Thu Jul 11 08:06:25 CEST 2019
Commit: 5dd14a4fad1492aefa7cb0fbe16a782a7d465df2
Author: Campbell Barton
Date: Thu Jul 11 15:55:53 2019 +1000
Branches: temp-text-undo-memcmp
https://developer.blender.org/rB5dd14a4fad1492aefa7cb0fbe16a782a7d465df2
Remove text undo code (in favor of binary diffing the entire buffer)
===================================================================
M source/blender/blenkernel/BKE_text.h
M source/blender/blenkernel/intern/text.c
M source/blender/editors/include/ED_text.h
M source/blender/editors/interface/interface_ops.c
M source/blender/editors/space_text/text_autocomplete.c
M source/blender/editors/space_text/text_ops.c
M source/blender/editors/space_text/text_undo.c
M source/blender/makesrna/intern/rna_text_api.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index 20322ea0052..03d7e0ca344 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -30,7 +30,6 @@ extern "C" {
struct Main;
struct Text;
struct TextLine;
-struct TextUndoBuf;
void BKE_text_free_lines(struct Text *text);
void BKE_text_free(struct Text *text);
@@ -49,8 +48,8 @@ void BKE_text_copy_data(struct Main *bmain,
const int flag);
struct Text *BKE_text_copy(struct Main *bmain, const struct Text *ta);
void BKE_text_make_local(struct Main *bmain, struct Text *text, const bool lib_local);
-void BKE_text_clear(struct Text *text, struct TextUndoBuf *utxt);
-void BKE_text_write(struct Text *text, struct TextUndoBuf *utxt, const char *str);
+void BKE_text_clear(struct Text *text);
+void BKE_text_write(struct Text *text, const char *str);
void BKE_text_reload_from_buf(struct Text *text, const uchar *buf, int buf_len);
int BKE_text_file_modified_check(struct Text *text);
void BKE_text_file_modified_ignore(struct Text *text);
@@ -78,29 +77,26 @@ void txt_move_eol(struct Text *text, const bool sel);
void txt_move_toline(struct Text *text, unsigned int line, const bool sel);
void txt_move_to(struct Text *text, unsigned int line, unsigned int ch, const bool sel);
void txt_pop_sel(struct Text *text);
-void txt_delete_char(struct Text *text, struct TextUndoBuf *utxt);
-void txt_delete_word(struct Text *text, struct TextUndoBuf *utxt);
-void txt_delete_selected(struct Text *text, struct TextUndoBuf *utxt);
+void txt_delete_char(struct Text *text);
+void txt_delete_word(struct Text *text);
+void txt_delete_selected(struct Text *text);
void txt_sel_all(struct Text *text);
void txt_sel_clear(struct Text *text);
void txt_sel_line(struct Text *text);
char *txt_sel_to_buf(struct Text *text, int *r_buf_strlen);
-void txt_insert_buf(struct Text *text, struct TextUndoBuf *utxt, const char *in_buffer);
-void txt_undo_add_op(struct Text *text, struct TextUndoBuf *utxt, int op);
-void txt_do_undo(struct Text *text, struct TextUndoBuf *utxt);
-void txt_do_redo(struct Text *text, struct TextUndoBuf *utxt);
-void txt_split_curline(struct Text *text, struct TextUndoBuf *utxt);
-void txt_backspace_char(struct Text *text, struct TextUndoBuf *utxt);
-void txt_backspace_word(struct Text *text, struct TextUndoBuf *utxt);
-bool txt_add_char(struct Text *text, struct TextUndoBuf *utxt, unsigned int add);
-bool txt_add_raw_char(struct Text *text, struct TextUndoBuf *utxt, unsigned int add);
-bool txt_replace_char(struct Text *text, struct TextUndoBuf *utxt, unsigned int add);
-void txt_unindent(struct Text *text, struct TextUndoBuf *utxt);
-void txt_comment(struct Text *text, struct TextUndoBuf *utxt);
-void txt_indent(struct Text *text, struct TextUndoBuf *utxt);
-void txt_uncomment(struct Text *text, struct TextUndoBuf *utxt);
-void txt_move_lines(struct Text *text, struct TextUndoBuf *utxt, const int direction);
-void txt_duplicate_line(struct Text *text, struct TextUndoBuf *utxt);
+void txt_insert_buf(struct Text *text, const char *in_buffer);
+void txt_split_curline(struct Text *text);
+void txt_backspace_char(struct Text *text);
+void txt_backspace_word(struct Text *text);
+bool txt_add_char(struct Text *text, unsigned int add);
+bool txt_add_raw_char(struct Text *text, unsigned int add);
+bool txt_replace_char(struct Text *text, unsigned int add);
+void txt_unindent(struct Text *text);
+void txt_comment(struct Text *text);
+void txt_indent(struct Text *text);
+void txt_uncomment(struct Text *text);
+void txt_move_lines(struct Text *text, const int direction);
+void txt_duplicate_line(struct Text *text);
int txt_setcurr_tab_spaces(struct Text *text, int space);
bool txt_cursor_is_line_start(struct Text *text);
bool txt_cursor_is_line_end(struct Text *text);
@@ -126,11 +122,6 @@ enum {
TXT_MOVE_LINE_DOWN = 1,
};
-typedef struct TextUndoBuf {
- char *buf;
- int pos, len;
-} TextUndoBuf;
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index d01cc1c533f..8d9758c94c7 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -107,66 +107,16 @@
* undo position
*/
-/* Undo opcodes */
-
-enum {
- /* 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)) */
- /* 3 - opcode is followed by 3 bytes for utf-8 character and opcode (repeat)) */
- /* 4 - opcode is followed by 4 bytes for unicode character and opcode (repeat)) */
- UNDO_INSERT_1 = 013,
- UNDO_INSERT_2 = 014,
- UNDO_INSERT_3 = 015,
- UNDO_INSERT_4 = 016,
-
- UNDO_BS_1 = 017,
- UNDO_BS_2 = 020,
- UNDO_BS_3 = 021,
- UNDO_BS_4 = 022,
-
- UNDO_DEL_1 = 023,
- UNDO_DEL_2 = 024,
- UNDO_DEL_3 = 025,
- UNDO_DEL_4 = 026,
-
- /* Text block (opcode is followed
- * by 4 character length ID + the text
- * block itself + the 4 character length
- * ID (repeat) and opcode (repeat)) */
- UNDO_DBLOCK = 027, /* Delete block */
- UNDO_IBLOCK = 030, /* Insert block */
-
- /* Misc */
- UNDO_INDENT = 032,
- UNDO_UNINDENT = 033,
- UNDO_COMMENT = 034,
- UNDO_UNCOMMENT = 035,
-
- UNDO_MOVE_LINES_UP = 036,
- UNDO_MOVE_LINES_DOWN = 037,
-
- UNDO_DUPLICATE = 040,
-};
-
/***/
static void txt_pop_first(Text *text);
static void txt_pop_last(Text *text);
-static void txt_undo_add_blockop(Text *text, TextUndoBuf *utxt, int op, const char *buf);
static void txt_delete_line(Text *text, TextLine *line);
-static void txt_delete_sel(Text *text, TextUndoBuf *utxt);
+static void txt_delete_sel(Text *text);
static void txt_make_dirty(Text *text);
/***/
-/**
- * Set to true when undoing (so we don't generate undo steps while undoing).
- *
- * Also use to disable undo entirely.
- */
-static bool undoing;
-
/**
* \note caller must handle `undo_buf` and `compiled` members.
*/
@@ -525,29 +475,17 @@ void BKE_text_make_local(Main *bmain, Text *text, const bool lib_local)
BKE_id_make_local_generic(bmain, &text->id, true, lib_local);
}
-void BKE_text_clear(Text *text, TextUndoBuf *utxt) /* called directly from rna */
+void BKE_text_clear(Text *text) /* called directly from rna */
{
- const bool undoing_orig = undoing;
- undoing = (utxt == NULL);
-
txt_sel_all(text);
- txt_delete_sel(text, utxt);
-
- undoing = undoing_orig;
-
+ txt_delete_sel(text);
txt_make_dirty(text);
}
-void BKE_text_write(Text *text, TextUndoBuf *utxt, const char *str) /* called directly from rna */
+void BKE_text_write(Text *text, const char *str) /* called directly from rna */
{
- const bool undoing_orig = undoing;
- undoing = (utxt == NULL);
-
- txt_insert_buf(text, utxt, str);
+ txt_insert_buf(text, str);
txt_move_eof(text, 0);
-
- undoing = undoing_orig;
-
txt_make_dirty(text);
}
@@ -1279,7 +1217,7 @@ bool txt_has_sel(Text *text)
return ((text->curl != text->sell) || (text->curc != text->selc));
}
-static void txt_delete_sel(Text *text, TextUndoBuf *utxt)
+static void txt_delete_sel(Text *text)
{
TextLine *tmpl;
char *buf;
@@ -1297,12 +1235,6 @@ static void txt_delete_sel(Text *text, TextUndoBuf *utxt)
txt_order_cursors(text, false);
- if (!undoing) {
- buf = txt_sel_to_buf(text, NULL);
- txt_undo_add_blockop(text, utxt, UNDO_DBLOCK, buf);
- MEM_freeN(buf);
- }
-
buf = MEM_mallocN(text->curc + (text->sell->len - text->selc) + 1, "textline_string");
strncpy(buf, text->curl->line, text->curc);
@@ -1584,9 +1516,8 @@ char *txt_sel_to_buf(Text *text, int *r_buf_strlen)
return buf;
}
-void txt_insert_buf(Text *text, TextUndoBuf *utxt, const char *in_buffer)
+void txt_insert_buf(Text *text, const char *in_buffer)
{
- const bool undoing_orig = undoing;
int l = 0, len;
size_t i = 0, j;
TextLine *add;
@@ -1596,24 +1527,19 @@ void txt_insert_buf(Text *text, TextUndoBuf *utxt, const char *in_buffer)
return;
}
- txt_delete_sel(text, utxt);
+ txt_delete_sel(text);
len = strlen(in_buffer);
buffer = BLI_strdupn(in_buffer, len);
len += txt_extended_ascii_as_utf8(&buffer);
- if (!undoing) {
- txt_undo_add_blockop(text, utxt, UNDO_IBLOCK, buffer);
- }
- undoing = true;
-
/* Read the first line (or as close as possible */
while (buffer[i] && buffer[i] != '\n') {
- txt_add_raw_char(text, utxt, BLI_str_utf8_as_unicode_step(buffer, &i));
+ txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &i));
}
if (buffer[i] == '\n') {
- txt_split_curline(text, utxt);
+ txt_split_curline(text);
i++;
while (i < len) {
@@ -1631,7 +1557,7 @@ void txt_insert_buf(Text *text, TextUndoBuf *utxt, const char *in_buffer)
}
else {
for (j = i - l; j < i && j < len;) {
- txt_add_raw_char(text, utxt, BLI_str_utf8_as_unicode_step(buffer, &j));
+ txt_add_raw_char(text, BLI_str_utf8_as_unicode_step(buffer, &j));
}
break;
}
@@ -1639,1046 +1565,13 @@ void txt_insert_buf(Text *text, TextUndoBuf *utxt, const char *in_buffer)
}
MEM_freeN(buffer);
- undoing = undoing_orig;
-}
-
-/******************/
-/* Undo functions */
-/******************/
-
-static bool max_undo_test(TextUndoBuf *utxt, int x)
-{
- /* Normally over-allocating is preferred,
- * however in this case the buffer is small enough and re-allocation
- * fast enough for each undo step that it's not a problem to allocate each time.
- * This also saves on some memory when we have many text buffers
- * that would have an empty undo memory allocated.
- */
-
- /* Add one for the null terminator. */
- utxt->len = utxt->pos + x + 1;
- if (utxt->len > TXT_MAX_UNDO) {
- /* XXX error("Undo limit reached, buffer cleared\n"); */
- MEM_freeN(utxt->buf);
- return false;
- }
- else {
- /* Small reallocations on each undo step is fine. */
- utxt->buf = MEM_recallocN(utxt->buf, utxt->len);
- }
- return true;
-}
-
-static void txt_undo_end(Text *UNUSED(text), TextUndoBuf *utxt)
-{
- int undo_pos_end = utxt->pos + 1;
- BLI_assert(undo_pos_end + 1 == utxt->l
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list