diff options
| author | Albert Cervin <albert@acervin.com> | 2023-02-25 21:37:48 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-02-25 21:38:59 +0100 |
| commit | 40db61eb7a2019ced97f09a9687139f35749f4e0 (patch) | |
| tree | 9291e44eb82721732d04146b5042545e1b9e91f9 /src/buffer.c | |
| parent | 44fd8cde61e3e89e5f83c98900a403e922073727 (diff) | |
| download | dged-40db61eb7a2019ced97f09a9687139f35749f4e0.tar.gz dged-40db61eb7a2019ced97f09a9687139f35749f4e0.tar.xz dged-40db61eb7a2019ced97f09a9687139f35749f4e0.zip | |
Introduce vec and hashmap
Convenience macros for a hashmap and a growable vector.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/buffer.c b/src/buffer.c index 2decdea..e6c3552 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -185,14 +185,13 @@ void delete_with_undo(struct buffer *buffer, struct buffer_location start, struct text_chunk txt = text_get_region(buffer->text, start.line, start.col, end.line, end.col); - undo_push_boundary(&buffer->undo, - (struct undo_boundary){.save_point = false}); - undo_push_delete( &buffer->undo, (struct undo_delete){.data = txt.text, .nbytes = txt.nbytes, .pos = {.row = start.line, .col = start.col}}); + undo_push_boundary(&buffer->undo, + (struct undo_boundary){.save_point = false}); text_delete(buffer->text, start.line, start.col, end.line, end.col); buffer->modified = true; @@ -522,6 +521,11 @@ void buffer_to_file(struct buffer *buffer) { return; } + if (!buffer->modified) { + minibuffer_echo_timeout(4, "buffer already saved"); + return; + } + FILE *file = fopen(buffer->filename, "w"); if (file == NULL) { minibuffer_echo("failed to open file %s for writing: %s", buffer->filename, @@ -538,6 +542,7 @@ void buffer_to_file(struct buffer *buffer) { buffer->filename); fclose(file); + buffer->modified = false; undo_push_boundary(&buffer->undo, (struct undo_boundary){.save_point = true}); } @@ -574,15 +579,16 @@ int buffer_add_text(struct buffer *buffer, uint8_t *text, uint32_t nbytes) { moveh(buffer, cols_added); struct buffer_location final = buffer->dot; - if (lines_added > 0) { - undo_push_boundary(&buffer->undo, - (struct undo_boundary){.save_point = false}); - } undo_push_add( &buffer->undo, (struct undo_add){.begin = {.row = initial.line, .col = initial.col}, .end = {.row = final.line, .col = final.col}}); + if (lines_added > 0) { + undo_push_boundary(&buffer->undo, + (struct undo_boundary){.save_point = false}); + } + buffer->modified = true; return lines_added; } @@ -679,6 +685,7 @@ void buffer_undo(struct buffer *buffer) { } } } + undo_push_boundary(undo, (struct undo_boundary){.save_point = false}); free(records); undo_end(undo); |
