add keybinds to switch between panels

memory-refactor
Patrick Cleaveliln 2025-07-10 01:56:22 +00:00
parent 1fdbe7ddaf
commit 34b5eb1efc
2 changed files with 54 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import "core:log"
import "vendor:sdl2"
import "../core"
import "../util"
State :: core.State
@ -19,6 +20,31 @@ register_default_go_actions :: proc(input_map: ^core.InputActions) {
}, "move to end of line");
}
register_default_panel_actions :: proc(input_map: ^core.InputActions) {
core.register_key_action(input_map, .H, proc(state: ^State) {
if current_panel, ok := state.current_panel.?; ok {
if prev, ok := util.get_prev(&state.panels, current_panel).?; ok {
state.current_panel = prev
}
}
core.reset_input_map(state)
}, "focus panel to the left");
core.register_key_action(input_map, .L, proc(state: ^State) {
if state.current_buffer < len(state.buffers)-1 {
state.current_buffer += 1
}
if current_panel, ok := state.current_panel.?; ok {
if next, ok := util.get_next(&state.panels, current_panel).?; ok {
state.current_panel = next
}
}
core.reset_input_map(state)
}, "focus panel to the right");
}
register_default_input_actions :: proc(input_map: ^core.InputActions) {
// Cursor Movement
{
@ -80,6 +106,10 @@ register_default_input_actions :: proc(input_map: ^core.InputActions) {
}
}, "Save file")
// Panel Navigation
core.register_ctrl_key_action(input_map, .W, core.new_input_actions(), "Panel Navigation")
register_default_panel_actions(&(&input_map.ctrl_key_actions[.W]).action.(core.InputActions))
core.register_key_action(input_map, .G, core.new_input_actions(), "Go commands");
register_default_go_actions(&(&input_map.key_actions[.G]).action.(core.InputActions));

View File

@ -57,6 +57,30 @@ get_first_active_index :: proc(list: ^StaticList($T)) -> Maybe(int) {
return nil
}
get_prev :: proc(list: ^StaticList($T), index: int) -> Maybe(int) {
if get(list, index) != nil {
for i := index-1; i >= 0; i -= 1 {
if list.data[i].active {
return i
}
}
}
return nil
}
get_next :: proc(list: ^StaticList($T), index: int) -> Maybe(int) {
if get(list, index) != nil {
for i in index+1..<len(list.data) {
if list.data[i].active {
return i
}
}
}
return nil
}
get :: proc{get_static_list_elem}
delete_static_list_elem :: proc(list: ^StaticList($T), index: int) {