summaryrefslogtreecommitdiff
path: root/command.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-03-03 20:14:51 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-03-03 20:14:51 -0500
commit6ef4720bba8fcb90bcbdca5d7766b76816fc58c5 (patch)
tree41a0d02884f182193ff41ccb23b7f66adf35404b /command.c
parente3eb333ae2b07467e14dd9e2f845889f75f01a16 (diff)
more autocomplete (already partially working!)
Diffstat (limited to 'command.c')
-rw-r--r--command.c35
1 files changed, 3 insertions, 32 deletions
diff --git a/command.c b/command.c
index f0dd1ec..f246f64 100644
--- a/command.c
+++ b/command.c
@@ -205,38 +205,9 @@ void command_execute(Ted *ted, Command c, i64 argument) {
}
break;
- case CMD_AUTOCOMPLETE: {
- if (buffer && !buffer->view_only && !buffer->is_line_buffer) {
- buffer->selection = false;
- if (is_word(buffer_char_after_cursor(buffer)))
- buffer_cursor_move_right_words(buffer, 1);
- else
- buffer_scroll_to_cursor(buffer);
- char *start = str32_to_utf8_cstr(buffer_word_at_cursor(buffer));
- char *completions[2] = {0};
- size_t ncompletions = tags_beginning_with(ted, start, completions, 2);
- switch (ncompletions) {
- case 0:
- ted->cursor_error_time = time_get_seconds();
- break;
- case 1: {
- char *str = completions[0] + strlen(start);
- buffer_start_edit_chain(buffer); // don't merge with other edits
- buffer_insert_utf8_at_cursor(buffer, str);
- buffer_end_edit_chain(buffer);
- } break;
- case 2:
- // open autocomplete selection menu
- ted->autocomplete = true;
- break;
- default: assert(0); break;
- }
- free(completions[0]);
- free(completions[1]);
- free(start);
- }
- } break;
-
+ case CMD_AUTOCOMPLETE:
+ autocomplete_open(ted);
+ break;
case CMD_UNDO:
if (buffer) buffer_undo(buffer, argument);
break;