diff options
-rw-r--r-- | buffer.c | 12 | ||||
-rw-r--r-- | command.c | 9 | ||||
-rw-r--r-- | command.h | 2 | ||||
-rw-r--r-- | config.c | 2 |
4 files changed, 21 insertions, 4 deletions
@@ -276,15 +276,21 @@ Language buffer_language(TextBuffer *buffer) { static long context_score(const char *path, Language lang, const SettingsContext *context) { long score = 0; - if (lang == context->language) { - score += 10000; + if (context->language) { + if (lang == context->language) { + score += 10000; + } else { + // dont use this. it's language-specific and for the wrong language. + return INT_MIN; + } } if (context->path) { if (path && str_has_prefix(path, context->path)) { score += (long)strlen(context->path); } else { - score -= 100000; + // dont use this. it's path-specific and for the wrong path. + return INT_MIN; } } @@ -111,7 +111,14 @@ void command_execute(Ted *ted, Command c, i64 argument) { case CMD_SELECT_ALL: if (buffer) buffer_select_all(buffer); break; - + + case CMD_INSERT_TEXT: { + const char *str = arg_get_string(ted, argument); + if (str) { + buffer_insert_utf8_at_cursor(buffer, str); + } + } + break; case CMD_TAB: if (ted->replace && buffer == &ted->find_buffer) { ted_switch_to_buffer(ted, &ted->replace_buffer); @@ -30,6 +30,7 @@ ENUM_U16 { CMD_SELECT_PAGE_DOWN, // insertion + CMD_INSERT_TEXT, // insert text CMD_TAB, // insert '\t' CMD_BACKTAB, CMD_NEWLINE, // insert '\n' + autoindent -- also used to submit line buffers @@ -134,6 +135,7 @@ static CommandName const command_names[] = { {"page-down", CMD_PAGE_DOWN}, {"tab", CMD_TAB}, {"backtab", CMD_BACKTAB}, + {"insert-text", CMD_INSERT_TEXT}, {"newline", CMD_NEWLINE}, {"newline-back", CMD_NEWLINE_BACK}, {"comment-selection", CMD_COMMENT_SELECTION}, @@ -787,7 +787,9 @@ void config_free(Ted *ted) { } for (u32 i = 0; i < ted->nstrings; ++i) { free(ted->strings[i]); + ted->strings[i] = NULL; } + ted->nstrings = 0; arr_clear(ted->all_settings); ted->default_settings = NULL; } |