diff options
author | pommicket <pommicket@gmail.com> | 2025-09-30 11:16:09 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-09-30 11:16:09 -0400 |
commit | 8bad65173bac1ff019aa737b6acd4d428b769493 (patch) | |
tree | 1938100280bf05f1e1a0255c38bbe5593806e283 | |
parent | d2fba7af36c6ae76c954da76ed64e3383e0d64f9 (diff) |
Close code action when cursor position changes
-rw-r--r-- | ide-code-action.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ide-code-action.c b/ide-code-action.c index 3f67121..6171d68 100644 --- a/ide-code-action.c +++ b/ide-code-action.c @@ -8,6 +8,10 @@ typedef struct { struct CodeAction { LSPServerRequestID last_request; + // which buffer code action is open for + LSPDocumentID which_buffer; + // cursor position when code action was opened + BufferPos cursor_pos; LSPResponse response; Action *actions; }; @@ -38,6 +42,8 @@ void code_action_open(Ted *ted) { LSP *lsp = buffer_lsp(buffer); if (!lsp) return; autocomplete_close(ted); + c->which_buffer = buffer_lsp_document_id(buffer); + c->cursor_pos = buffer_cursor_pos(buffer); BufferPos range_start = {0}, range_end = {0}; LSPRange range = {0}; if (buffer_selection_pos(buffer, &range_start)) { @@ -155,6 +161,22 @@ void code_action_frame(Ted *ted) { code_action_close(ted); return; } + LSP *lsp = buffer_lsp(buffer); + if (!lsp || lsp_get_id(lsp) != c->last_request.lsp) { + // LSP or active buffer changed + code_action_close(ted); + return; + } + if (buffer_lsp_document_id(buffer) != c->which_buffer) { + // buffer changed + code_action_close(ted); + return; + } + if (!buffer_pos_eq(buffer_cursor_pos(buffer), c->cursor_pos)) { + // cursor moved + code_action_close(ted); + return; + } const Settings *settings = ted_active_settings(ted); vec2 cursor_pos = buffer_pos_to_pixels(buffer, buffer_cursor_pos(buffer)); float x = cursor_pos.x, y = cursor_pos.y; |