diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-31 19:09:50 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-31 19:09:50 -0500 |
commit | 68b3e3928e1bd05ebbb56810ae8b7a68ff5f12b0 (patch) | |
tree | 72832015fedc7f8230b345e36aa9b0b5efa7cf46 /buffer.c | |
parent | 58444144fae39d38c155d868cf3aebb8e4ef8dba (diff) |
started syntax higlighting (still need to add state to each line)
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -132,6 +132,8 @@ static bool buffer_pos_valid(TextBuffer *buffer, BufferPos p) { // are there any unsaved changes? bool buffer_unsaved_changes(TextBuffer *buffer) { + if (streq(buffer->filename, TED_UNTITLED) && buffer_empty(buffer)) + return false; // don't worry about empty untitled buffers return buffer->modified; } @@ -1969,13 +1971,21 @@ void buffer_render(TextBuffer *buffer, Rect r) { // scroll <= sel - scrolloff text_state.y -= (float)(buffer->scroll_y - start_line) * char_height; - gl_color_rgba(colors[COLOR_TEXT]); + SyntaxState syntax_state = {0}; + // dynamic array of character types, to be filled by syntax_highlight + SyntaxCharType *char_types = NULL; for (u32 line_idx = start_line; line_idx < nlines; ++line_idx) { Line *line = &lines[line_idx]; - for (char32_t *p = line->str, *end = p + line->len; p != end; ++p) { - char32_t c = *p; + if (arr_len(char_types) < line->len) { + arr_set_len(char_types, line->len); + } + syntax_highlight(&syntax_state, LANG_C, line->str, line->len, char_types); + for (u32 i = 0; i < line->len; ++i) { + char32_t c = line->str[i]; + SyntaxCharType type = char_types[i]; + gl_color_rgba(colors[syntax_char_type_to_color(type)]); switch (c) { case '\n': assert(0); break; case '\r': break; // for CRLF line endings @@ -2003,6 +2013,9 @@ void buffer_render(TextBuffer *buffer, Rect r) { column = 0; } + arr_free(char_types); + + text_chars_end(font); |