From 34b5eb1efc1daf7809a41171672756b16150afb9 Mon Sep 17 00:00:00 2001 From: Patrick Cleaveliln Date: Thu, 10 Jul 2025 01:56:22 +0000 Subject: [PATCH] add keybinds to switch between panels --- src/input/input.odin | 30 ++++++++++++++++++++++++++++++ src/util/list.odin | 24 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/input/input.odin b/src/input/input.odin index cee2b1c..4e1468b 100644 --- a/src/input/input.odin +++ b/src/input/input.odin @@ -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)); diff --git a/src/util/list.odin b/src/util/list.odin index 2775b2a..301cfe4 100644 --- a/src/util/list.odin +++ b/src/util/list.odin @@ -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..