Compare commits

..

3 Commits

3 changed files with 55 additions and 23 deletions

View File

@@ -6,5 +6,10 @@ A TUI IDE.
# TODO # TODO
- [ ] VERY HIGH PRIORITY: fix bug when moving upwards into wrapped line (cuses random line amongst the wrapped lines to be visually focused while in reality the top is selected), has be somewhere in `ensure_scroll` function. - [ ] Add support for text selection.
- [ ] Add folding support.
- [ ] Add feature where doing enter uses tree-sitter to add newline with indentation.
1. it should also put stuff like `}` on the next line.
- [ ] Add support for brackets/quotes to auto-close.
- [ ] Add scm files for all the supported languages. (2/14) Done.
- [ ] Add support for wide characters with wrapping. - [ ] Add support for wide characters with wrapping.

View File

@@ -347,29 +347,53 @@ void cursor_left(Editor *editor, uint32_t number) {
} }
void ensure_scroll(Editor *editor) { void ensure_scroll(Editor *editor) {
LineIterator *it = begin_l_iter(editor->root, editor->scroll.row); if (editor->cursor.row < editor->scroll.row) {
uint32_t rendered_lines = 0; uint32_t visual_delta = 0;
uint32_t line_index = editor->scroll.row; LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
char *line_content = nullptr; for (uint32_t i = editor->cursor.row; i < editor->scroll.row; i++) {
while (rendered_lines <= editor->size.row) { char *line = next_line(it);
line_content = next_line(it); if (!line)
if (!line_content)
break; break;
char *line_content_t = line_content; uint32_t len = grapheme_strlen(line);
if (rendered_lines == 0) visual_delta += (len + editor->size.col - 1) / editor->size.col;
line_content_t = line_content + editor->scroll.col; free(line);
uint32_t len = grapheme_strlen(line_content_t);
free(line_content);
uint32_t wrapped_lines = (len + editor->size.col - 1) / editor->size.col;
rendered_lines += wrapped_lines;
line_index++;
} }
line_index -= 2;
free(it); free(it);
if (editor->cursor.row >= line_index && line_content) scroll_up(editor, visual_delta);
scroll_down(editor, editor->cursor.row - line_index); return;
if (editor->cursor.row < editor->scroll.row) }
scroll_up(editor, editor->scroll.row - editor->cursor.row); uint32_t current_visual_y = 0;
LineIterator *it = begin_l_iter(editor->root, editor->scroll.row);
uint32_t i = editor->scroll.row;
char *line = nullptr;
bool found_cursor = false;
while ((line = next_line(it)) != nullptr) {
uint32_t lines_in_chunk;
uint32_t offset = (i == editor->scroll.row) ? editor->scroll.col : 0;
if (i == editor->cursor.row) {
uint32_t cursor_sub_row = editor->cursor.col / editor->size.col;
if (i == editor->scroll.row)
cursor_sub_row -= offset / editor->size.col;
current_visual_y += cursor_sub_row;
found_cursor = true;
free(line);
break;
}
uint32_t len = grapheme_strlen(line);
uint32_t visible_len = len - offset;
if (visible_len == 0)
visible_len = 1;
lines_in_chunk = (visible_len + editor->size.col - 1) / editor->size.col;
current_visual_y += lines_in_chunk;
free(line);
i++;
}
free(it);
if (found_cursor)
if (current_visual_y >= editor->size.row) {
uint32_t needed_scroll = current_visual_y - editor->size.row + 1;
scroll_down(editor, needed_scroll);
}
} }
void fold(Editor *editor, uint32_t start_line, uint32_t end_line) { void fold(Editor *editor, uint32_t start_line, uint32_t end_line) {

View File

@@ -172,6 +172,7 @@ static inline Highlight *safe_get(std::vector<Highlight> &vec, size_t index) {
} }
void ts_collect_spans(Editor *editor) { void ts_collect_spans(Editor *editor) {
static int parse_counter = 0;
if (!editor->parser || !editor->root || !editor->query) if (!editor->parser || !editor->root || !editor->query)
return; return;
TSInput tsinput = { TSInput tsinput = {
@@ -194,10 +195,12 @@ void ts_collect_spans(Editor *editor) {
edits.push_back(edit); edits.push_back(edit);
ts_tree_edit(copy, &edits.back()); ts_tree_edit(copy, &edits.back());
}; };
if (copy && edits.empty()) { if (copy && edits.empty() && parse_counter < 64) {
parse_counter++;
ts_tree_delete(copy); ts_tree_delete(copy);
return; return;
} }
parse_counter = 0;
editor->spans.mid_parse = true; editor->spans.mid_parse = true;
// TODO: Remove this lock and replace with an index // TODO: Remove this lock and replace with an index
// modifier based on edits made in the `read_ts` function. // modifier based on edits made in the `read_ts` function.