Compare commits
3 Commits
303f008b6f
...
646c6e9026
| Author | SHA1 | Date | |
|---|---|---|---|
|
646c6e9026
|
|||
|
260867e225
|
|||
|
3927899428
|
@@ -6,5 +6,10 @@ A TUI IDE.
|
||||
|
||||
# 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.
|
||||
|
||||
@@ -347,29 +347,53 @@ void cursor_left(Editor *editor, uint32_t number) {
|
||||
}
|
||||
|
||||
void ensure_scroll(Editor *editor) {
|
||||
LineIterator *it = begin_l_iter(editor->root, editor->scroll.row);
|
||||
uint32_t rendered_lines = 0;
|
||||
uint32_t line_index = editor->scroll.row;
|
||||
char *line_content = nullptr;
|
||||
while (rendered_lines <= editor->size.row) {
|
||||
line_content = next_line(it);
|
||||
if (!line_content)
|
||||
break;
|
||||
char *line_content_t = line_content;
|
||||
if (rendered_lines == 0)
|
||||
line_content_t = line_content + editor->scroll.col;
|
||||
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++;
|
||||
if (editor->cursor.row < editor->scroll.row) {
|
||||
uint32_t visual_delta = 0;
|
||||
LineIterator *it = begin_l_iter(editor->root, editor->cursor.row);
|
||||
for (uint32_t i = editor->cursor.row; i < editor->scroll.row; i++) {
|
||||
char *line = next_line(it);
|
||||
if (!line)
|
||||
break;
|
||||
uint32_t len = grapheme_strlen(line);
|
||||
visual_delta += (len + editor->size.col - 1) / editor->size.col;
|
||||
free(line);
|
||||
}
|
||||
free(it);
|
||||
scroll_up(editor, visual_delta);
|
||||
return;
|
||||
}
|
||||
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++;
|
||||
}
|
||||
line_index -= 2;
|
||||
free(it);
|
||||
if (editor->cursor.row >= line_index && line_content)
|
||||
scroll_down(editor, editor->cursor.row - line_index);
|
||||
if (editor->cursor.row < editor->scroll.row)
|
||||
scroll_up(editor, editor->scroll.row - editor->cursor.row);
|
||||
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) {
|
||||
|
||||
@@ -172,6 +172,7 @@ static inline Highlight *safe_get(std::vector<Highlight> &vec, size_t index) {
|
||||
}
|
||||
|
||||
void ts_collect_spans(Editor *editor) {
|
||||
static int parse_counter = 0;
|
||||
if (!editor->parser || !editor->root || !editor->query)
|
||||
return;
|
||||
TSInput tsinput = {
|
||||
@@ -194,10 +195,12 @@ void ts_collect_spans(Editor *editor) {
|
||||
edits.push_back(edit);
|
||||
ts_tree_edit(copy, &edits.back());
|
||||
};
|
||||
if (copy && edits.empty()) {
|
||||
if (copy && edits.empty() && parse_counter < 64) {
|
||||
parse_counter++;
|
||||
ts_tree_delete(copy);
|
||||
return;
|
||||
}
|
||||
parse_counter = 0;
|
||||
editor->spans.mid_parse = true;
|
||||
// TODO: Remove this lock and replace with an index
|
||||
// modifier based on edits made in the `read_ts` function.
|
||||
|
||||
Reference in New Issue
Block a user