diff options
| author | Albert Cervin <albert@acervin.com> | 2024-06-23 22:30:37 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2024-06-23 22:44:05 +0200 |
| commit | e0901a1efb05727111eb88d1b27b7d1a23a87365 (patch) | |
| tree | aac294067c611770a5baa2b2e388c0163174af8f /src/main/cmds.c | |
| parent | 67271d056409ce3727c282968a7186088bf19a28 (diff) | |
| download | dged-e0901a1efb05727111eb88d1b27b7d1a23a87365.tar.gz dged-e0901a1efb05727111eb88d1b27b7d1a23a87365.tar.xz dged-e0901a1efb05727111eb88d1b27b7d1a23a87365.zip | |
Fix buffer list switch and search/replace
Fix the buffer list return key action when buffers have the same name.
Previously, it would pick the first it could find in the buffer list
with the correct buffer name instead of the selected one. Now it uses
text properties to pass the actual buffer pointer along instead.
This however exposed a problem with the clearing of properties and where
in the frame it happens. Search and replace highlighting assumed that
they could color things in their respective command executions. However,
ideally coloring should happen in update functions so now both search
and replace implement the coloring in update hooks for the buffer
they are operating on. For replace, this was already kinda how it
worked and could be adapted with minimal effort. Search on the other
hand needed a bit more rework.
Diffstat (limited to 'src/main/cmds.c')
| -rw-r--r-- | src/main/cmds.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/main/cmds.c b/src/main/cmds.c index 04e42b4..4da8346 100644 --- a/src/main/cmds.c +++ b/src/main/cmds.c @@ -22,6 +22,7 @@ int32_t _abort(struct command_ctx ctx, int argc, const char *argv[]) { abort_replace(); + abort_search(); abort_completion(); disable_completion(minibuffer_buffer()); minibuffer_abort_prompt(); @@ -253,6 +254,12 @@ void buffer_to_list_line(struct buffer *buffer, void *userdata) { .set_fg = true, .fg = Color_Blue, }}); + + buffer_add_text_property( + listbuf, (struct location){.line = begin.line, .col = 0}, + (struct location){.line = begin.line, + .col = buffer_num_chars(listbuf, begin.line)}, + (struct text_property){.type = TextProperty_Data, .userdata = buffer}); } } @@ -261,22 +268,18 @@ int32_t buflist_visit_cmd(struct command_ctx ctx, int argc, struct window *w = ctx.active_window; struct buffer_view *bv = window_buffer_view(w); - struct text_chunk text = buffer_line(bv->buffer, bv->dot.line); - - char *end = (char *)memchr(text.text, ' ', text.nbytes); - - if (end != NULL) { - uint32_t len = end - (char *)text.text; - char *bufname = (char *)malloc(len + 1); - strncpy(bufname, (const char *)text.text, len); - bufname[len] = '\0'; - - struct buffer *target = buffers_find(ctx.buffers, bufname); - free(bufname); - if (target != NULL) { - window_set_buffer(w, target); + struct text_property *props[16] = {0}; + uint32_t nprops; + buffer_get_text_properties(bv->buffer, bv->dot, props, 16, &nprops); + + for (uint32_t propi = 0; propi < nprops; ++propi) { + struct text_property *p = props[propi]; + if (p->type == TextProperty_Data) { + window_set_buffer(w, p->userdata); + return 0; } } + return 0; } @@ -497,6 +500,8 @@ void register_global_commands(struct commands *commands, register_search_replace_commands(commands); } +void teardown_global_commands(void) { cleanup_search_replace(); } + #define BUFFER_VIEW_WRAPCMD(fn) \ static int32_t fn##_cmd(struct command_ctx ctx, int argc, \ const char *argv[]) { \ |
