fresh/app/
help_actions.rs1use rust_i18n::t;
8
9use crate::model::event::{BufferId, EventLog};
10use crate::state::EditorState;
11
12use super::help;
13use super::Editor;
14
15impl Editor {
16 pub fn open_help_manual(&mut self) {
20 let existing_buffer = self
22 .buffer_metadata
23 .iter()
24 .find(|(_, m)| m.display_name == help::HELP_MANUAL_BUFFER_NAME)
25 .map(|(id, _)| *id);
26
27 if let Some(buffer_id) = existing_buffer {
28 self.set_active_buffer(buffer_id);
30 return;
31 }
32
33 let buffer_id = self.create_virtual_buffer(
35 help::HELP_MANUAL_BUFFER_NAME.to_string(),
36 "special".to_string(),
37 true,
38 );
39
40 if let Some(state) = self.buffers.get_mut(&buffer_id) {
42 state.buffer.insert(0, help::HELP_MANUAL_CONTENT);
43 state.buffer.clear_modified();
44 state.editing_disabled = true;
45
46 state.margins.configure_for_line_numbers(false);
48 }
49
50 self.set_active_buffer(buffer_id);
51 }
52
53 pub fn open_keyboard_shortcuts(&mut self) {
58 let existing_buffer = self
60 .buffer_metadata
61 .iter()
62 .find(|(_, m)| m.display_name == help::KEYBOARD_SHORTCUTS_BUFFER_NAME)
63 .map(|(id, _)| *id);
64
65 if let Some(buffer_id) = existing_buffer {
66 self.set_active_buffer(buffer_id);
68 return;
69 }
70
71 let bindings = self.keybindings.read().unwrap().get_all_bindings();
73
74 let mut content = String::from("Keyboard Shortcuts\n");
76 content.push_str("==================\n\n");
77 content.push_str("Press 'q' to close this buffer.\n\n");
78
79 let mut current_context = String::new();
81 for (key, action) in &bindings {
82 let (context, action_name) = if let Some(bracket_end) = action.find("] ") {
84 let ctx = &action[1..bracket_end];
85 let name = &action[bracket_end + 2..];
86 (ctx.to_string(), name.to_string())
87 } else {
88 ("Normal".to_string(), action.clone())
89 };
90
91 if context != current_context {
93 if !current_context.is_empty() {
94 content.push('\n');
95 }
96 content.push_str(&format!("── {} Mode ──\n\n", context));
97 current_context = context;
98 }
99
100 content.push_str(&format!(" {:20} {}\n", key, action_name));
102 }
103
104 let buffer_id = self.create_virtual_buffer(
106 help::KEYBOARD_SHORTCUTS_BUFFER_NAME.to_string(),
107 "special".to_string(),
108 true,
109 );
110
111 if let Some(state) = self.buffers.get_mut(&buffer_id) {
113 state.buffer.insert(0, &content);
114 state.buffer.clear_modified();
115 state.editing_disabled = true;
116
117 state.margins.configure_for_line_numbers(false);
119 }
120
121 self.set_active_buffer(buffer_id);
122 }
123}