fresh/app/
help_actions.rs1use super::help;
11use crate::app::window::Window;
12
13impl Window {
14 pub fn open_help_manual(&mut self) {
19 let existing_buffer = self
21 .buffer_metadata
22 .iter()
23 .find(|(_, m)| m.display_name == help::HELP_MANUAL_BUFFER_NAME)
24 .map(|(id, _)| *id);
25
26 if let Some(buffer_id) = existing_buffer {
27 self.set_active_buffer(buffer_id);
28 return;
29 }
30
31 let buffer_id = self.create_virtual_buffer(
33 help::HELP_MANUAL_BUFFER_NAME.to_string(),
34 "special".to_string(),
35 true,
36 );
37
38 if let Some(state) = self.buffers.get_mut(&buffer_id) {
39 state.buffer.insert(0, help::HELP_MANUAL_CONTENT);
40 state.buffer.clear_modified();
41 state.editing_disabled = true;
42 state.margins.configure_for_line_numbers(false);
43 }
44
45 self.set_active_buffer(buffer_id);
46 }
47
48 pub fn open_keyboard_shortcuts(&mut self) {
54 let existing_buffer = self
55 .buffer_metadata
56 .iter()
57 .find(|(_, m)| m.display_name == help::KEYBOARD_SHORTCUTS_BUFFER_NAME)
58 .map(|(id, _)| *id);
59
60 if let Some(buffer_id) = existing_buffer {
61 self.set_active_buffer(buffer_id);
62 return;
63 }
64
65 let bindings = self
67 .resources
68 .keybindings
69 .read()
70 .unwrap()
71 .get_all_bindings();
72
73 let mut content = String::from("Keyboard Shortcuts\n");
75 content.push_str("==================\n\n");
76 content.push_str("Press 'q' to close this buffer.\n\n");
77
78 let mut current_context = String::new();
79 for (key, action) in &bindings {
80 let (context, action_name) = if let Some(bracket_end) = action.find("] ") {
81 let ctx = &action[1..bracket_end];
82 let name = &action[bracket_end + 2..];
83 (ctx.to_string(), name.to_string())
84 } else {
85 ("Normal".to_string(), action.clone())
86 };
87
88 if context != current_context {
89 if !current_context.is_empty() {
90 content.push('\n');
91 }
92 content.push_str(&format!("── {} Mode ──\n\n", context));
93 current_context = context;
94 }
95
96 content.push_str(&format!(" {:20} {}\n", key, action_name));
97 }
98
99 let buffer_id = self.create_virtual_buffer(
100 help::KEYBOARD_SHORTCUTS_BUFFER_NAME.to_string(),
101 "special".to_string(),
102 true,
103 );
104
105 if let Some(state) = self.buffers.get_mut(&buffer_id) {
106 state.buffer.insert(0, &content);
107 state.buffer.clear_modified();
108 state.editing_disabled = true;
109 state.margins.configure_for_line_numbers(false);
110 }
111
112 self.set_active_buffer(buffer_id);
113 }
114}