commit cf5deae5a371952718dae3cd43e0877fbd3a16e0
parent 6d4cbcce478157b67d2ca598c7527cadd0e9b0a5
Author: rexim <reximkut@gmail.com>
Date: Tue, 17 Jan 2023 23:48:19 +0700
editor_recompute_lines() -> editor_retokenize()
Diffstat:
3 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/src/editor.c b/src/editor.c
@@ -20,7 +20,7 @@ void editor_backspace(Editor *e)
);
e->cursor -= 1;
e->data.count -= 1;
- editor_recompute_lines(e);
+ editor_retokenize(e);
}
void editor_delete(Editor *e)
@@ -32,7 +32,7 @@ void editor_delete(Editor *e)
e->data.count - e->cursor - 1
);
e->data.count -= 1;
- editor_recompute_lines(e);
+ editor_retokenize(e);
}
Errno editor_save_as(Editor *e, const char *file_path)
@@ -59,7 +59,7 @@ Errno editor_load_from_file(Editor *e, const char *file_path)
e->cursor = 0;
- editor_recompute_lines(e);
+ editor_retokenize(e);
e->file_path.count = 0;
sb_append_cstr(&e->file_path, file_path);
@@ -129,35 +129,39 @@ void editor_insert_char(Editor *e, char x)
e->data.items[e->cursor] = x;
e->cursor += 1;
- editor_recompute_lines(e);
+ editor_retokenize(e);
}
-void editor_recompute_lines(Editor *e)
+void editor_retokenize(Editor *e)
{
- e->lines.count = 0;
+ // Lines
+ {
+ e->lines.count = 0;
- Line line;
- line.begin = 0;
+ Line line;
+ line.begin = 0;
- for (size_t i = 0; i < e->data.count; ++i) {
- if (e->data.items[i] == '\n') {
- line.end = i;
- da_append(&e->lines, line);
- line.begin = i + 1;
+ for (size_t i = 0; i < e->data.count; ++i) {
+ if (e->data.items[i] == '\n') {
+ line.end = i;
+ da_append(&e->lines, line);
+ line.begin = i + 1;
+ }
}
- }
-
- line.end = e->data.count;
- da_append(&e->lines, line);
- //////////////////////////////
+ line.end = e->data.count;
+ da_append(&e->lines, line);
+ }
- e->tokens.count = 0;
- Lexer l = lexer_new(e->atlas, e->data.items, e->data.count);
- Token t = lexer_next(&l);
- while (t.kind != TOKEN_END) {
- da_append(&e->tokens, t);
- t = lexer_next(&l);
+ // Syntax Highlighting
+ {
+ e->tokens.count = 0;
+ Lexer l = lexer_new(e->atlas, e->data.items, e->data.count);
+ Token t = lexer_next(&l);
+ while (t.kind != TOKEN_END) {
+ da_append(&e->tokens, t);
+ t = lexer_next(&l);
+ }
}
}
diff --git a/src/editor.h b/src/editor.h
@@ -53,7 +53,7 @@ void editor_move_line_down(Editor *e);
void editor_move_char_left(Editor *e);
void editor_move_char_right(Editor *e);
void editor_insert_char(Editor *e, char x);
-void editor_recompute_lines(Editor *e);
+void editor_retokenize(Editor *e);
void editor_render(SDL_Window *window, Free_Glyph_Atlas *atlas, Simple_Renderer *sr, Editor *editor);
void editor_update_selection(Editor *e, bool shift);
diff --git a/src/main.c b/src/main.c
@@ -164,7 +164,7 @@ int main(int argc, char **argv)
free_glyph_atlas_init(&atlas, face);
editor.atlas = &atlas;
- editor_recompute_lines(&editor);
+ editor_retokenize(&editor);
bool quit = false;
bool file_browser = false;