add keybinds to switch between panels
parent
1fdbe7ddaf
commit
34b5eb1efc
|
@ -5,6 +5,7 @@ import "core:log"
|
||||||
import "vendor:sdl2"
|
import "vendor:sdl2"
|
||||||
|
|
||||||
import "../core"
|
import "../core"
|
||||||
|
import "../util"
|
||||||
|
|
||||||
State :: core.State
|
State :: core.State
|
||||||
|
|
||||||
|
@ -19,6 +20,31 @@ register_default_go_actions :: proc(input_map: ^core.InputActions) {
|
||||||
}, "move to end of line");
|
}, "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) {
|
register_default_input_actions :: proc(input_map: ^core.InputActions) {
|
||||||
// Cursor Movement
|
// Cursor Movement
|
||||||
{
|
{
|
||||||
|
@ -80,6 +106,10 @@ register_default_input_actions :: proc(input_map: ^core.InputActions) {
|
||||||
}
|
}
|
||||||
}, "Save file")
|
}, "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");
|
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));
|
register_default_go_actions(&(&input_map.key_actions[.G]).action.(core.InputActions));
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,30 @@ get_first_active_index :: proc(list: ^StaticList($T)) -> Maybe(int) {
|
||||||
return nil
|
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}
|
get :: proc{get_static_list_elem}
|
||||||
|
|
||||||
delete_static_list_elem :: proc(list: ^StaticList($T), index: int) {
|
delete_static_list_elem :: proc(list: ^StaticList($T), index: int) {
|
||||||
|
|
Loading…
Reference in New Issue