diff options
| author | Albert Cervin <albert@acervin.com> | 2023-01-31 15:25:59 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-01-31 15:25:59 +0100 |
| commit | 1cd66cac903151396a7513f8e009f6f654561daf (patch) | |
| tree | 9acd39542c42c59c517cf9321a7faa25929ecb12 /src/buffer.c | |
| parent | 689ceeca3d25cb2f738a6c52776c53912abb797f (diff) | |
| download | dged-1cd66cac903151396a7513f8e009f6f654561daf.tar.gz dged-1cd66cac903151396a7513f8e009f6f654561daf.tar.xz dged-1cd66cac903151396a7513f8e009f6f654561daf.zip | |
Fixes to copy-paste
It would crash on multi-line copy.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/buffer.c b/src/buffer.c index 71d486e..8a86e69 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -16,7 +16,9 @@ #include <unistd.h> #include <wchar.h> -static struct modeline { uint8_t *buffer; } g_modeline = {0}; +struct modeline { + uint8_t *buffer; +}; #define KILL_RING_SZ 64 static struct kill_ring { @@ -88,8 +90,9 @@ struct buffer buffer_create(char *name, bool modeline) { sizeof(bindings) / sizeof(bindings[0])); if (modeline) { - g_modeline.buffer = malloc(1024); - buffer_add_update_hook(&b, buffer_modeline_hook, &g_modeline); + struct modeline *modeline = calloc(1, sizeof(struct modeline)); + modeline->buffer = malloc(1024); + buffer_add_update_hook(&b, buffer_modeline_hook, modeline); } if (modeline) { @@ -108,10 +111,6 @@ void buffer_destroy(struct buffer *buffer) { keymap_destroy(&buffer->keymaps[keymapi]); } free(buffer->keymaps); - - if (g_modeline.buffer != NULL) { - free(g_modeline.buffer); - } } void buffer_clear(struct buffer *buffer) { @@ -194,7 +193,7 @@ struct region to_region(struct buffer_location dot, bool region_has_size(struct buffer *buffer) { return buffer->mark_set && - (labs((int64_t)buffer->mark.line - (int64_t)buffer->dot.line + 1) * + (labs((int64_t)buffer->mark.line - (int64_t)buffer->dot.line) + labs((int64_t)buffer->mark.col - (int64_t)buffer->dot.col)) > 0; } @@ -234,6 +233,7 @@ void buffer_cut(struct buffer *buffer) { text_delete(buffer->text, reg.begin.line, reg.begin.col, reg.end.line, reg.end.col); buffer_clear_mark(buffer); + buffer->dot = reg.begin; } } |
