1use crate::app::AppState;
2use crate::app::InputMode;
3
4impl AppState<'_> {
5 pub fn show_help(&mut self) {
6 self.help_scroll = 0;
7
8 self.help_text = "FILE OPERATIONS:\n\
9 :w - Save file\n\
10 :wq, :x - Save and quit\n\
11 :q - Quit (will warn if unsaved changes)\n\
12 :q! - Force quit without saving\n\n\
13 NAVIGATION:\n\
14 :[cell] - Jump to cell (e.g., :B10)\n\
15 hjkl - Move cursor (left, down, up, right)\n\
16 0 - Jump to first column\n\
17 ^ - Jump to first non-empty column\n\
18 $ - Jump to last column\n\
19 gg - Jump to first row\n\
20 G - Jump to last row\n\
21 Ctrl+arrows - Jump to next non-empty cell\n\
22 [ - Switch to previous sheet\n\
23 ] - Switch to next sheet\n\
24 :sheet [name/number] - Switch to sheet by name or index\n\n\
25 EDITING:\n\
26 i - Edit current cell\n\
27 :y - Copy current cell\n\
28 :d - Cut current cell\n\
29 :put, :pu - Paste to current cell\n\
30 u - Undo last operation\n\
31 Ctrl+r - Redo last undone operation\n\n\
32 SEARCH:\n\
33 / - Search forward\n\
34 ? - Search backward\n\
35 n - Jump to next search result\n\
36 N - Jump to previous search result\n\
37 :nohlsearch, :noh - Disable search highlighting\n\n\
38 COLUMN OPERATIONS:\n\
39 :cw fit - Adjust width of current column to fit its content\n\
40 :cw fit all - Adjust width of all columns to fit their content\n\
41 :cw min - Set current column width to minimum (5 characters)\n\
42 :cw min all - Set all columns width to minimum\n\
43 :cw [number] - Set current column width to specific number of characters\n\
44 :dc - Delete current column\n\
45 :dc [col] - Delete specific column (e.g., :dc A or :dc 1)\n\
46 :dc [start] [end] - Delete columns from start to end (e.g., :dc A C)\n\n\
47 ROW OPERATIONS:\n\
48 :dr - Delete current row\n\
49 :dr [row] - Delete specific row\n\
50 :dr [start] [end] - Delete rows from start to end\n\n\
51 EXPORT:\n\
52 :ej [h|v] [rows] - Export current sheet to JSON\n\
53 :eja [h|v] [rows] - Export all sheets to a single JSON file\n\
54 h=horizontal (default), v=vertical\n\
55 [rows]=number of header rows (default: 1)\n\n\
56 SHEET OPERATIONS:\n\
57 :delsheet - Delete the current sheet\n\n\
58 UI ADJUSTMENTS:\n\
59 +/= - Increase info panel height\n\
60 - - Decrease info panel height"
61 .to_string();
62
63 self.input_mode = InputMode::Help;
64 }
65
66 pub fn save_and_exit(&mut self) {
67 if !self.workbook.is_modified() {
68 self.add_notification("No changes to save".to_string());
69 self.should_quit = true;
70 return;
71 }
72
73 match self.workbook.save() {
74 Ok(_) => {
75 self.undo_history.clear();
76 self.add_notification("File saved".to_string());
77 self.should_quit = true;
78 }
79 Err(e) => {
80 self.add_notification(format!("Save failed: {}", e));
81 self.input_mode = InputMode::Normal;
82 }
83 }
84 }
85
86 pub fn save(&mut self) -> Result<(), anyhow::Error> {
87 if !self.workbook.is_modified() {
88 self.add_notification("No changes to save".to_string());
89 return Ok(());
90 }
91
92 match self.workbook.save() {
93 Ok(_) => {
94 self.undo_history.clear();
95 self.add_notification("File saved".to_string());
96 }
97 Err(e) => {
98 self.add_notification(format!("Save failed: {}", e));
99 }
100 }
101 Ok(())
102 }
103
104 pub fn exit_without_saving(&mut self) {
105 self.should_quit = true;
106 }
107}