don't reparse buffer on every keystroke

main
Patrick Cleaveliln 2025-07-25 06:05:41 +00:00
parent ad5e4f85fd
commit a70da837fa
6 changed files with 59 additions and 36 deletions

View File

@ -188,7 +188,7 @@ yank_selection :: proc(state: ^State, buffer: ^FileBuffer) {
} }
paste_register :: proc(state: ^State, register: Register, buffer: ^FileBuffer) { paste_register :: proc(state: ^State, register: Register, buffer: ^FileBuffer) {
insert_content(buffer, register.data) insert_content(buffer, register.data, reparse_buffer = true)
move_cursor_left(buffer) move_cursor_left(buffer)
} }

View File

@ -982,7 +982,7 @@ scroll_file_buffer :: proc(buffer: ^FileBuffer, dir: ScrollDir, cursor: Maybe(^C
} }
} }
insert_content :: proc(buffer: ^FileBuffer, to_be_inserted: []u8) { insert_content :: proc(buffer: ^FileBuffer, to_be_inserted: []u8, reparse_buffer: bool = false) {
if len(to_be_inserted) == 0 { if len(to_be_inserted) == 0 {
return; return;
} }
@ -995,10 +995,12 @@ insert_content :: proc(buffer: ^FileBuffer, to_be_inserted: []u8) {
update_file_buffer_index_from_cursor(buffer); update_file_buffer_index_from_cursor(buffer);
move_cursor_right(buffer, false, amt = len(to_be_inserted)); move_cursor_right(buffer, false, amt = len(to_be_inserted));
ts.parse_buffer(&buffer.tree, tree_sitter_file_buffer_input(buffer)) if reparse_buffer {
ts.parse_buffer(&buffer.tree, tree_sitter_file_buffer_input(buffer))
}
} }
delete_content_from_buffer_cursor :: proc(buffer: ^FileBuffer, amount: int) { delete_content_from_buffer_cursor :: proc(buffer: ^FileBuffer, amount: int, reparse_buffer: bool = false) {
buffer.flags += { .UnsavedChanges } buffer.flags += { .UnsavedChanges }
// Calculate proper line/col values // Calculate proper line/col values
@ -1010,10 +1012,12 @@ delete_content_from_buffer_cursor :: proc(buffer: ^FileBuffer, amount: int) {
buffer.history.cursor.line = it.cursor.line buffer.history.cursor.line = it.cursor.line
buffer.history.cursor.col = it.cursor.col buffer.history.cursor.col = it.cursor.col
ts.parse_buffer(&buffer.tree, tree_sitter_file_buffer_input(buffer)) if reparse_buffer {
ts.parse_buffer(&buffer.tree, tree_sitter_file_buffer_input(buffer))
}
} }
delete_content_from_selection :: proc(buffer: ^FileBuffer, selection: ^Selection) { delete_content_from_selection :: proc(buffer: ^FileBuffer, selection: ^Selection, reparse_buffer: bool = false) {
buffer.flags += { .UnsavedChanges } buffer.flags += { .UnsavedChanges }
selection^ = swap_selections(selection^) selection^ = swap_selections(selection^)
@ -1028,7 +1032,9 @@ delete_content_from_selection :: proc(buffer: ^FileBuffer, selection: ^Selection
move_cursor_left(buffer) move_cursor_left(buffer)
} }
ts.parse_buffer(&buffer.tree, tree_sitter_file_buffer_input(buffer)) if reparse_buffer {
ts.parse_buffer(&buffer.tree, tree_sitter_file_buffer_input(buffer))
}
} }
delete_content :: proc{delete_content_from_buffer_cursor, delete_content_from_selection}; delete_content :: proc{delete_content_from_buffer_cursor, delete_content_from_selection};
@ -1043,10 +1049,11 @@ get_buffer_indent :: proc(buffer: ^FileBuffer, cursor: Maybe(Cursor) = nil) -> i
ptr_cursor := &cursor.? ptr_cursor := &cursor.?
move_cursor_start_of_line(buffer, ptr_cursor) move_cursor_start_of_line(buffer, ptr_cursor)
move_cursor_forward_end_of_word(buffer, ptr_cursor)
move_cursor_backward_start_of_word(buffer, ptr_cursor)
return cursor.?.col it := new_file_buffer_iter_with_cursor(buffer, ptr_cursor^);
iterate_file_buffer_until(&it, until_non_whitespace)
return it.cursor.col
} }
buffer_to_string :: proc(buffer: ^FileBuffer, allocator := context.allocator) -> string { buffer_to_string :: proc(buffer: ^FileBuffer, allocator := context.allocator) -> string {

View File

@ -431,6 +431,8 @@ main :: proc() {
core.move_cursor_left(buffer) core.move_cursor_left(buffer)
sdl2.StopTextInput(); sdl2.StopTextInput();
ts.parse_buffer(&buffer.tree, core.tree_sitter_file_buffer_input(buffer))
} }
case .TAB: { case .TAB: {
// TODO: change this to insert a tab character // TODO: change this to insert a tab character

View File

@ -200,7 +200,7 @@ file_buffer_delete_actions :: proc(input_map: ^core.InputActions) {
core.move_cursor_start_of_line(buffer, cursor = &sel_cur.start); core.move_cursor_start_of_line(buffer, cursor = &sel_cur.start);
core.move_cursor_end_of_line(buffer, cursor = &sel_cur.end, stop_at_end = false); core.move_cursor_end_of_line(buffer, cursor = &sel_cur.end, stop_at_end = false);
core.delete_content_from_selection(buffer, sel_cur) core.delete_content_from_selection(buffer, sel_cur, reparse_buffer = true)
buffer.selection = nil; buffer.selection = nil;
core.reset_input_map(state) core.reset_input_map(state)
@ -451,7 +451,7 @@ file_buffer_visual_actions :: proc(input_map: ^core.InputActions) {
if state.yank_register.whole_line { if state.yank_register.whole_line {
core.insert_content(buffer, []u8{'\n'}); core.insert_content(buffer, []u8{'\n'});
core.paste_register(state, state.yank_register, buffer) core.paste_register(state, state.yank_register, buffer)
core.insert_content(buffer, []u8{'\n'}); core.insert_content(buffer, []u8{'\n'}, reparse_buffer = true);
} else { } else {
core.paste_register(state, state.yank_register, buffer) core.paste_register(state, state.yank_register, buffer)
} }

View File

@ -183,7 +183,7 @@ make_grep_panel :: proc() -> core.Panel {
max_results := container_height / 16 max_results := container_height / 16
for result, i in panel_state.query_results { for result, i in panel_state.query_results {
if i > max_results { if i >= max_results {
break break
} }
@ -204,8 +204,14 @@ make_grep_panel :: proc() -> core.Panel {
style.background_color = .Background2 style.background_color = .Background2
} }
ui.open_element(s, result.file_path[len(state.directory):], {}, style) if len(result.file_path) > 0 {
ui.close_element(s) ui.open_element(s, result.file_path[len(state.directory):], {}, style)
ui.close_element(s)
} else {
style.background_color = .BrightRed
ui.open_element(s, "BAD FILE DIRECTORY", {}, style)
ui.close_element(s)
}
} }
} }
} }

50
todo.md
View File

@ -1,12 +1,13 @@
# Bugs # Bugs
- Fix jumping forward a word jumping past consecutive brackets - Fix jumping forward a word jumping past consecutive brackets
- Odd scrolling behavior on small screen heights - Scrolling past end/beginning of grep results panics
- Scrolling past end/beginning of results panics - "change selection" not pushing snapshot
- Don't allow panel navigation in grep panel
# Visual QOL # Visual QOL
- Split grep search results into a table to avoid funky unaligned text - Split grep search results into a table to avoid funky unaligned text
# Planned Features # TODO
- [ ] Jump List - [ ] Jump List
- [x] Use grouped lifetimes exclusively for memory allocation/freeing - [x] Use grouped lifetimes exclusively for memory allocation/freeing
- [ ] Highlight which panel is currently active - [ ] Highlight which panel is currently active
@ -16,7 +17,6 @@
- [ ] Finish writing tests for all current user actions - [ ] Finish writing tests for all current user actions
- Vim-like Macro replays - Vim-like Macro replays
- [ ] Simple File Search (vim /) - [ ] Simple File Search (vim /)
- [ ] Auto-indent
- Modify input system to allow for keybinds that take input - Modify input system to allow for keybinds that take input
- Vim's f and F movement commands - Vim's f and F movement commands
- Vim's r command - Vim's r command
@ -29,26 +29,34 @@
- [ ] In-line errors - [ ] In-line errors
- [ ] Go-to Definition/ - [ ] Go-to Definition/
- [ ] Find references - [ ] Find references
- Re-implement lost features from Plugins - [ ] Integrate tree-sitter
- [ ] Integrate tree-sitter - [x] Syntax Highlighting
- [x] Syntax Highlighting - [ ] Auto Setup Parsers
- [ ] Auto Setup Parsers - [ ] Download parser
- [ ] Download parser - [ ] Compile/"Install"
- [ ] Compile/"Install" - [ ] Auto-indent
- [ ] Auto-indent? - [x] Infer indent with similar lines
- [ ] Bootleg Telescope - [x] Infer indent with C-style scopes (languages using '{')
- [ ] Grepping Files - [ ] Infer indent inside multi-line function calls (again C-style)
- [x] Query across project - [ ] Somehow use tree-sitter to be language agnostic (not sure this is even possible with TS)
- [x] Open file in new buffer - [ ] Bootleg Telescope
- [x] Open file in new buffer at found location - [ ] Grepping Files
- [ ] Preview file with context - [x] Query across project
- [x] Show Context - [x] Open file in new buffer
- [ ] Properly show lines numbers - [x] Open file in new buffer at found location
- [ ] Don't overlap result list with file preview - [ ] Preview file with context
- [ ] Open Buffer Search - [x] Show Context
- [ ] Properly show lines numbers
- [ ] Don't overlap result list with file preview
- [ ] Open Buffer Search
- [ ] Workspace file search
- Re-write the UI (again) - Re-write the UI (again)
- [x] New UI - [x] New UI
- [ ] Styling - [ ] Styling
- [x] Background colors
- [x] Borders + Border Color
- [ ] Rounded corners?
- [ ] Gradients?
- Undo/Redo - Undo/Redo
- [x] Basic/Naive Undo/Redo - [x] Basic/Naive Undo/Redo
- [ ] Interface for undo-able actions - [ ] Interface for undo-able actions