summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buffer.c6
-rw-r--r--command.c5
-rw-r--r--command.h3
-rw-r--r--ted-internal.h1
4 files changed, 12 insertions, 3 deletions
diff --git a/buffer.c b/buffer.c
index 1081f69..55e2cfe 100644
--- a/buffer.c
+++ b/buffer.c
@@ -834,7 +834,7 @@ static void buffer_edit_print(BufferEdit *edit) {
printf(" => %" PRIu32 " chars.\n", edit->new_len);
}
-static void buffer_print_undo_history(TextBuffer *buffer) {
+void buffer_print_undo_history(TextBuffer *buffer) {
printf("-----------------\n");
arr_foreach_ptr(buffer->undo_history, BufferEdit, e)
buffer_edit_print(e);
@@ -2652,7 +2652,8 @@ void buffer_delete_chars_at_pos(TextBuffer *buffer, BufferPos pos, i64 nchars_)
void buffer_delete_all(TextBuffer *buffer) {
BufferPos start = buffer_pos_start_of_file(buffer);
- buffer_delete_chars_at_pos(buffer, start, I64_MAX / 4);
+ BufferPos end = buffer_pos_end_of_file(buffer);
+ buffer_delete_chars_between(buffer, start, end);
}
// Delete characters between the given buffer positions. Returns number of characters deleted.
@@ -3120,7 +3121,6 @@ Status buffer_load_file(TextBuffer *buffer, const char *path) {
BufferPos start = buffer_pos_start_of_file(buffer);
buffer_insert_utf8_at_pos(buffer, start, (const char *)file_contents);
buffer_end_edit_chain(buffer);
- buffer_print_undo_history(buffer);
buffer->view_only = prev_view_only;
}
}
diff --git a/command.c b/command.c
index 4f8e7ea..d6e7f40 100644
--- a/command.c
+++ b/command.c
@@ -110,6 +110,7 @@ static CommandName command_names[] = {
{"indent-with-spaces", CMD_INDENT_WITH_SPACES},
{"indent-with-tabs", CMD_INDENT_WITH_TABS},
{"set-tab-width", CMD_SET_TAB_WIDTH},
+ {"debug-print-undo-history", CMD_DEBUG_PRINT_UNDO_HISTORY},
};
static_assert_if_possible(arr_count(command_names) == CMD_COUNT)
@@ -735,5 +736,9 @@ void command_execute_ex(Ted *ted, Command c, const CommandArgument *full_argumen
if (argument >= 1 && argument < 256) {
buffer_set_manual_tab_width(buffer, (u8)argument);
}
+ break;
+ case CMD_DEBUG_PRINT_UNDO_HISTORY:
+ buffer_print_undo_history(buffer);
+ break;
}
}
diff --git a/command.h b/command.h
index 076c4ef..400dab1 100644
--- a/command.h
+++ b/command.h
@@ -170,6 +170,9 @@ typedef enum {
/// set tab width/number of spaces to indent with
CMD_SET_TAB_WIDTH,
+ /// print undo history to stdout
+ CMD_DEBUG_PRINT_UNDO_HISTORY,
+
CMD_COUNT
} Command;
diff --git a/ted-internal.h b/ted-internal.h
index dd109ea..466c6c3 100644
--- a/ted-internal.h
+++ b/ted-internal.h
@@ -491,6 +491,7 @@ void buffer_center_cursor_next_frame(TextBuffer *buffer);
/// perform a series of checks to make sure the buffer doesn't have any invalid values
void buffer_check_valid(TextBuffer *buffer);
void buffer_publish_diagnostics(TextBuffer *buffer, const LSPRequest *request, LSPDiagnostic *diagnostics);
+void buffer_print_undo_history(TextBuffer *buffer);
// === build.c ===
void build_frame(Ted *ted, float x1, float y1, float x2, float y2);