summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-06-16 15:06:49 -0400
committerpommicket <pommicket@gmail.com>2025-06-16 15:06:49 -0400
commit439be25e27f614a28301c291794c3664c634b21c (patch)
treea64eb996aadff116bf0bf62aa5330cb21a06e175
parent55b42079488e0c3e8aaf85828ad028491934f9d3 (diff)
block edit chaining after reload
-rw-r--r--buffer.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/buffer.c b/buffer.c
index fd16181..3f1aac1 100644
--- a/buffer.c
+++ b/buffer.c
@@ -27,6 +27,7 @@ struct Line {
// This refers to replacing prev_len characters (found in prev_text) at pos with new_len characters
struct BufferEdit {
bool chain; // should this + the next edit be treated as one?
+ bool block_chaining; // stop this edit from being chained to the next one.
BufferPos pos;
u32 new_len;
u32 prev_len;
@@ -901,7 +902,7 @@ static bool buffer_edit_does_anything(TextBuffer *buffer, BufferEdit *edit) {
// is_deletion should be set to true if the edit involves any deletion.
static bool buffer_edit_split(TextBuffer *buffer, bool is_deletion) {
BufferEdit *last_edit = arr_lastp(buffer->undo_history);
- if (!last_edit) return true;
+ if (!last_edit || last_edit->block_chaining) return true;
if (buffer->will_chain_edits) return true;
if (buffer->chaining_edits) return false;
double curr_time = buffer->ted->frame_time;
@@ -2872,6 +2873,7 @@ static Status buffer_undo_edit(TextBuffer *buffer, BufferEdit const *edit, Buffe
// create inverse edit
if (buffer_edit_create(buffer, inverse, edit->pos, edit->new_len, edit->prev_len)) {
+ inverse->block_chaining = edit->block_chaining;
buffer_delete_chars_at_pos(buffer, edit->pos, (i64)edit->new_len);
String32 str = {edit->prev_text, edit->prev_len};
buffer_insert_text_at_pos(buffer, edit->pos, str);
@@ -2954,6 +2956,8 @@ void buffer_start_edit_chain(TextBuffer *buffer) {
void buffer_end_edit_chain(TextBuffer *buffer) {
buffer->chaining_edits = buffer->will_chain_edits = false;
+ BufferEdit *last_edit = arr_lastp(buffer->undo_history);
+ if (last_edit) last_edit->block_chaining = true;
}
static void buffer_copy_or_cut(TextBuffer *buffer, bool cut) {