From 22a7d40d3052d6fcc0f524e1eb7fba46ba2bcefc Mon Sep 17 00:00:00 2001 From: Patrick Cleaveliln Date: Sat, 12 Jul 2025 01:17:08 +0000 Subject: [PATCH] scroll file open from grep panel into view --- src/panels/panels.odin | 17 +++++++++++++++-- src/ui/ui.odin | 4 +++- todo.md | 10 +++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/panels/panels.odin b/src/panels/panels.odin index e2b217c..2b1c451 100644 --- a/src/panels/panels.odin +++ b/src/panels/panels.odin @@ -137,8 +137,8 @@ open_file_buffer_in_new_panel :: proc(state: ^core.State, file_path: string, lin buffer.cursor.line = line buffer.cursor.col = col + buffer.top_line = buffer.cursor.line core.update_file_buffer_index_from_cursor(&buffer) - core.update_file_buffer_scroll(&buffer) buffer_index = len(state.buffers) runtime.append(&state.buffers, buffer); @@ -417,12 +417,19 @@ make_grep_panel :: proc(state: ^core.State) -> core.Panel { { if panel_state.query_results != nil { // query results - ui.open_element(s, nil, { + query_result_container := ui.open_element(s, nil, { dir = .TopToBottom, kind = {ui.Grow{}, ui.Grow{}} }) { + container_height := query_result_container.layout.size.y + max_results := container_height / 16 + for result, i in panel_state.query_results { + if i > max_results { + break + } + ui.open_element(s, nil, { dir = .LeftToRight, kind = {ui.Fit{}, ui.Fit{}}, @@ -448,6 +455,12 @@ make_grep_panel :: proc(state: ^core.State) -> core.Panel { // file contents selected_result := &panel_state.query_results[panel_state.selected_result] + + core.update_glyph_buffer_from_bytes( + &panel_state.glyphs, + transmute([]u8)selected_result.file_context, + selected_result.line, + ) render_glyph_buffer(state, s, &panel_state.glyphs) } } diff --git a/src/ui/ui.odin b/src/ui/ui.odin index 40c3188..66ce8d8 100644 --- a/src/ui/ui.odin +++ b/src/ui/ui.odin @@ -66,7 +66,7 @@ UI_Direction :: enum { BottomToTop, } -open_element :: proc(state: ^State, kind: UI_Element_Kind, layout: UI_Layout) { +open_element :: proc(state: ^State, kind: UI_Element_Kind, layout: UI_Layout) -> UI_Element { e := UI_Element { kind = kind, layout = layout, @@ -93,6 +93,8 @@ open_element :: proc(state: ^State, kind: UI_Element_Kind, layout: UI_Layout) { state.curr_elements[state.num_curr] = e state.current_open_element = state.num_curr state.num_curr += 1 + + return e } close_element :: proc(state: ^State, loc := #caller_location) -> UI_Layout { diff --git a/todo.md b/todo.md index 9ec2eb3..970e49f 100644 --- a/todo.md +++ b/todo.md @@ -5,6 +5,8 @@ - Closing the only panel crashes # Planned Features +- [ ] Highlight which panel is currently active +- [ ] Persist end of line cursor position - Testing Harness - [x] Replay user inputs and assert buffer contents/changes - [ ] Finish writing tests for all current user actions @@ -31,7 +33,10 @@ - [x] Query across project - [x] Open file in new buffer - [x] Open file in new buffer at found location - - [ ] Preview file with context (instead of just the single matched line) + - [ ] Preview file with context + - [x] Show Context + - [ ] Properly show lines numbers + - [ ] Don't overlap result list with file preview - [ ] Open Buffer Search - Re-write the UI (again) - [x] New UI @@ -45,7 +50,7 @@ - [x] Yank - [x] Delete - [ ] Change - - [ ] Change + - [x] Change - [ ] Change word - [ ] Change inside delimiter - Virtual Whitespace @@ -53,4 +58,3 @@ - Command Search and Execution - Refactor to remove generics added specifically for plugins - Palette based UI? -- Persist end of line cursor position \ No newline at end of file