1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use crate::editor::state::{EditorState, Platform, TreeItem};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
pub fn handle_key_event(state: &mut EditorState, key: KeyEvent) {
// If platform menu is open, handle menu navigation
if state.platform_menu_open {
match key.code {
KeyCode::Esc | KeyCode::Char('q') => {
state.close_platform_menu();
}
KeyCode::Up | KeyCode::Char('k') => {
if state.platform_menu_cursor > 0 {
state.platform_menu_cursor -= 1;
}
}
KeyCode::Down | KeyCode::Char('j') => {
let platforms = Platform::all();
if state.platform_menu_cursor < platforms.len() - 1 {
state.platform_menu_cursor += 1;
}
}
KeyCode::Enter => {
state.select_platform_from_menu();
}
_ => {}
}
return;
}
// Normal tree navigation
match key.code {
// Quit
KeyCode::Char('q') | KeyCode::Esc => {
state.should_quit = true;
}
// Write and quit
KeyCode::Char('w') if key.modifiers.contains(KeyModifiers::CONTROL) => {
state.should_write = true;
state.should_quit = true;
}
// Open platform menu with 'p'
KeyCode::Char('p') => {
state.open_platform_menu();
}
// Toggle preset/feature/option with Enter or Space
KeyCode::Enter | KeyCode::Char(' ') => {
if let Some(item) = state.current_item().cloned() {
match item {
TreeItem::Preset(preset_id) => {
state.toggle_preset(&preset_id);
}
TreeItem::Feature(_preset_id, _feature_id) => {
// Features don't have a toggle action, just expand/collapse with arrow keys
}
TreeItem::Option(preset_id, _feature_id, option_id) => {
state.toggle_option(&preset_id, &option_id);
}
}
}
}
// Left - collapse preset/feature
KeyCode::Left | KeyCode::Char('h') => {
if let Some(item) = state.current_item().cloned() {
match item {
TreeItem::Preset(preset_id) => {
if state.expanded_presets.contains(&preset_id) {
state.toggle_preset_expand(&preset_id);
state.update_current_item_description();
}
}
TreeItem::Feature(preset_id, feature_id) => {
let key = (preset_id.clone(), feature_id.clone());
if state.expanded_features.contains(&key) {
state.toggle_feature_expand(&preset_id, &feature_id);
state.update_current_item_description();
} else {
// Feature not expanded, collapse parent preset instead
if state.expanded_presets.contains(&preset_id) {
state.toggle_preset_expand(&preset_id);
// Move cursor to the preset
if let Some(pos) = state.tree_items.iter().position(|item| {
matches!(item, TreeItem::Preset(p) if p == &preset_id)
}) {
state.tree_cursor = pos;
state.update_current_item_description();
}
}
}
}
TreeItem::Option(preset_id, feature_id, _option_id) => {
// If on an option, collapse its parent feature
let key = (preset_id.clone(), feature_id.clone());
if state.expanded_features.contains(&key) {
state.toggle_feature_expand(&preset_id, &feature_id);
// Move cursor to the feature
if let Some(pos) = state.tree_items.iter().position(|item| {
matches!(item, TreeItem::Feature(p, f) if p == &preset_id && f == &feature_id)
}) {
state.tree_cursor = pos;
state.update_current_item_description();
}
}
}
}
}
}
// Right - expand preset/feature
KeyCode::Right | KeyCode::Char('l') => {
if let Some(item) = state.current_item().cloned() {
match item {
TreeItem::Preset(preset_id) => {
if !state.expanded_presets.contains(&preset_id) {
state.toggle_preset_expand(&preset_id);
state.update_current_item_description();
}
}
TreeItem::Feature(preset_id, feature_id) => {
let key = (preset_id.clone(), feature_id.clone());
if !state.expanded_features.contains(&key) {
state.toggle_feature_expand(&preset_id, &feature_id);
state.update_current_item_description();
}
}
TreeItem::Option(_, _, _) => {
// Already at leaf level, do nothing
}
}
}
}
// Navigation - J/K for preview scroll when Shift is held
KeyCode::Char('K') => {
state.scroll_preview_up();
}
KeyCode::Char('J') => {
state.scroll_preview_down();
}
// Navigation - regular up/down and lowercase j/k for tree navigation
KeyCode::Up | KeyCode::Char('k') => {
if state.tree_cursor > 0 {
state.tree_cursor -= 1;
state.update_current_item_description();
}
}
KeyCode::Down | KeyCode::Char('j') => {
if state.tree_cursor < state.tree_items.len().saturating_sub(1) {
state.tree_cursor += 1;
state.update_current_item_description();
}
}
// Tab to cycle platform (alternative to 'p' menu)
KeyCode::Tab => {
state.cycle_platform();
}
_ => {}
}
}