diff options
author | pommicket <pommicket@gmail.com> | 2024-09-08 14:56:12 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2024-09-08 14:56:12 -0400 |
commit | c4ab62a68f81fda1365bab9e5200f27a6a986bae (patch) | |
tree | 75efd94bc517c1aca84be2d10bb24ef5df642d46 /buffer.c | |
parent | d37fe5d5d27d91a28776baf2593fefc0b749cc85 (diff) |
manual indentation, command palette fixes
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -83,6 +83,8 @@ struct TextBuffer { /// /// this is either set according to the user's settings or according to the autodetected indentation bool indent_with_spaces; + /// true if user has manually specified indentation + bool manual_indentation; /// tab size /// /// this is either set according to the user's settings or according to the autodetected indentation @@ -2980,6 +2982,7 @@ void buffer_paste(TextBuffer *buffer) { } static void buffer_detect_indentation(TextBuffer *buffer) { + if (buffer->manual_indentation) return; const Settings *settings = buffer_settings(buffer); if (settings->autodetect_indentation && buffer->nlines > 1) { bool use_tabs = false; @@ -3164,6 +3167,9 @@ void buffer_reload(TextBuffer *buffer) { BufferPos cursor_pos = buffer->cursor_pos; float x1 = buffer->x1, y1 = buffer->y1, x2 = buffer->x2, y2 = buffer->y2; double scroll_x = buffer->scroll_x; double scroll_y = buffer->scroll_y; + u8 tab_width = buffer->tab_width; + bool indent_with_spaces = buffer->indent_with_spaces; + bool manual_indentation = buffer->manual_indentation; char *path = str_dup(buffer->path); if (buffer_load_file(buffer, path)) { buffer->x1 = x1; buffer->y1 = y1; buffer->x2 = x2; buffer->y2 = y2; @@ -3172,6 +3178,12 @@ void buffer_reload(TextBuffer *buffer) { buffer->scroll_y = scroll_y; buffer_validate_cursor(buffer); buffer_correct_scroll(buffer); + if (manual_indentation) { + // ensure manual indentation is preserved across reload + buffer->manual_indentation = manual_indentation; + buffer->indent_with_spaces = indent_with_spaces; + buffer->tab_width = tab_width; + } } free(path); } @@ -4126,3 +4138,18 @@ void buffer_publish_diagnostics(TextBuffer *buffer, const LSPRequest *request, L } arr_qsort(buffer->diagnostics, diagnostic_cmp); } + +void buffer_set_manual_indent_with_spaces(TextBuffer *buffer) { + buffer->indent_with_spaces = true; + buffer->manual_indentation = true; +} + +void buffer_set_manual_indent_with_tabs(TextBuffer *buffer) { + buffer->indent_with_spaces = false; + buffer->manual_indentation = true; +} + +void buffer_set_manual_tab_width(TextBuffer *buffer, u8 n) { + buffer->tab_width = n; + buffer->manual_indentation = true; +} |