summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-23 11:57:59 -0500
committerpommicket <pommicket@gmail.com>2022-12-23 11:57:59 -0500
commite8ebc051bd606df22622c012d68804e275ef1dd5 (patch)
treeeb98c212f035d5d56dc97cecd6d73a8b7ee6b11e /buffer.c
parent7f98e047cb791b84cc955f534a7e94395fed1ae0 (diff)
close autocomplete on CMD_UP/insert non-word char/etc.
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/buffer.c b/buffer.c
index bdc23d2..949f19e 100644
--- a/buffer.c
+++ b/buffer.c
@@ -1455,11 +1455,25 @@ BufferPos buffer_insert_text_at_pos(TextBuffer *buffer, BufferPos pos, String32
str.str = str_copy;
}
+
if (buffer->is_line_buffer) {
// remove all the newlines from str.
str32_remove_all_instances_of_char(&str, '\n');
}
str32_remove_all_instances_of_char(&str, '\r');
+
+ if (buffer->ted->autocomplete.open) {
+ // close completions if a non-word character is typed
+ bool close_completions = false;
+ for (u32 i = 0; i < str.len; ++i) {
+ if (!is_word(str.str[i])) {
+ close_completions = true;
+ break;
+ }
+ }
+ if (close_completions)
+ autocomplete_close(buffer->ted);
+ }
LSP *lsp = buffer_lsp(buffer);
@@ -1709,6 +1723,30 @@ void buffer_delete_chars_at_pos(TextBuffer *buffer, BufferPos pos, i64 nchars_)
// When generating undo events, we allocate nchars characters of memory (see buffer_edit below).
// Not doing this might also cause other bugs, best to keep it here just in case.
nchars = (u32)buffer_get_text_at_pos(buffer, pos, NULL, nchars);
+
+ if (buffer->ted->autocomplete.open) {
+ // close completions if a non-word character is deleted
+ bool close_completions = false;
+ if (nchars > 256) {
+ // this is a massive deletion
+ // even if it's all word characters, let's close the completion menu anyways
+ close_completions = true;
+ } else {
+ char32_t text[256];
+ size_t n = buffer_get_text_at_pos(buffer, pos, text, nchars);
+ (void)n;
+ assert(n == nchars);
+ for (u32 i = 0; i < nchars; ++i) {
+ if (!is_word(text[i])) {
+ close_completions = true;
+ break;
+ }
+ }
+ }
+ if (close_completions)
+ autocomplete_close(buffer->ted);
+ }
+
LSP *lsp = buffer_lsp(buffer);
if (lsp)