diff --git a/src/core/core.odin b/src/core/core.odin index d2f6a64..bffb2a1 100644 --- a/src/core/core.odin +++ b/src/core/core.odin @@ -208,13 +208,14 @@ EditorAction :: proc(state: ^State, user_data: rawptr); InputActions :: struct { key_actions: map[Key]Action, ctrl_key_actions: map[Key]Action, + show_help: bool, } Action :: struct { action: InputGroup, description: string, } -new_input_map :: proc(allocator := context.allocator) -> InputMap { +new_input_map :: proc(show_help: bool = false, allocator := context.allocator) -> InputMap { context.allocator = allocator input_map := InputMap { @@ -228,15 +229,19 @@ new_input_map :: proc(allocator := context.allocator) -> InputMap { } } + normal_actions := &input_map.mode[.Normal] + normal_actions.show_help = show_help + return input_map; } -new_input_actions :: proc(allocator := context.allocator) -> InputActions { +new_input_actions :: proc(show_help: bool = false, allocator := context.allocator) -> InputActions { context.allocator = allocator input_actions := InputActions { key_actions = make(map[Key]Action), ctrl_key_actions = make(map[Key]Action), + show_help = show_help, } return input_actions; diff --git a/src/main.odin b/src/main.odin index 9a6b0b7..21a0257 100644 --- a/src/main.odin +++ b/src/main.odin @@ -100,8 +100,7 @@ draw :: proc(state: ^State) { ui.compute_layout(new_ui) ui.draw(new_ui, state) - // TODO: figure out when to not show the input help menu - if false && state.mode != .Insert { // && state.current_input_map != &state.input_map.mode[state.mode] { + if state.mode != .Insert && state.current_input_map.show_help { longest_description := 0; for key, action in state.current_input_map.key_actions { if len(action.description) > longest_description { diff --git a/src/panels/file_buffer.odin b/src/panels/file_buffer.odin index 915eb29..5ceadcd 100644 --- a/src/panels/file_buffer.odin +++ b/src/panels/file_buffer.odin @@ -46,13 +46,14 @@ make_file_buffer_panel :: proc(file_path: string, line: int = 0, col: int = 0) - panel_state.buffer = buffer } - leader_actions := core.new_input_actions() + leader_actions := core.new_input_actions(show_help = true) register_default_leader_actions(&leader_actions); file_buffer_leader_actions(&leader_actions); core.register_key_action(&panel.input_map.mode[.Normal], .SPACE, leader_actions, "leader commands"); - core.register_ctrl_key_action(&panel.input_map.mode[.Normal], .W, core.new_input_actions(), "Panel Navigation") - register_default_panel_actions(&(&panel.input_map.mode[.Normal].ctrl_key_actions[.W]).action.(core.InputActions)) + panel_actions := core.new_input_actions(show_help = true) + register_default_panel_actions(&panel_actions) + core.register_ctrl_key_action(&panel.input_map.mode[.Normal], .W, panel_actions, "Panel Navigation") file_buffer_input_actions(&panel.input_map.mode[.Normal]); file_buffer_visual_actions(&panel.input_map.mode[.Visual]); diff --git a/src/panels/grep.odin b/src/panels/grep.odin index a3b9806..b800c17 100644 --- a/src/panels/grep.odin +++ b/src/panels/grep.odin @@ -66,12 +66,13 @@ make_grep_panel :: proc() -> core.Panel { } mem.arena_init(&panel_state.query_arena, arena_bytes) - panel.input_map = core.new_input_map() + panel.input_map = core.new_input_map(show_help = true) panel_state.glyphs = core.make_glyph_buffer(256,256) panel_state.buffer = core.new_virtual_file_buffer() - core.register_ctrl_key_action(&panel.input_map.mode[.Normal], .W, core.new_input_actions(), "Panel Navigation") - register_default_panel_actions(&(&panel.input_map.mode[.Normal].ctrl_key_actions[.W]).action.(core.InputActions)) + panel_actions := core.new_input_actions(show_help = true) + register_default_panel_actions(&panel_actions) + core.register_ctrl_key_action(&panel.input_map.mode[.Normal], .W, panel_actions, "Panel Navigation") core.register_key_action(&panel.input_map.mode[.Normal], .ENTER, proc(state: ^core.State, user_data: rawptr) { this_panel := transmute(^core.Panel)user_data