scroll file open from grep panel into view

memory-refactor
Patrick Cleaveliln 2025-07-12 01:17:08 +00:00
parent 34d56eb47c
commit 22a7d40d30
3 changed files with 25 additions and 6 deletions

View File

@ -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)
}
}

View File

@ -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 {

10
todo.md
View File

@ -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