on master help sign in
Show infobox with register contents
bf773dbGokul Soumya
helix-core/src/register.rs+4
@@ -68,4 +68,8 @@ impl Registers {
68 pub fn read(&self, name: char) -> Option<&[String]> {
68 pub fn read(&self, name: char) -> Option<&[String]> {
69 self.get(name).map(|reg| reg.read())
69 self.get(name).map(|reg| reg.read())
70 }
70 }
71+
72+ pub fn inner(&self) -> &HashMap<char, Register> {
73+ &self.inner
74+ }
71}
75}
helix-term/src/commands.rs+3
@@ -20,6 +20,7 @@ use helix_view::{
20 clipboard::ClipboardType,
20 clipboard::ClipboardType,
21 document::{Mode, SCRATCH_BUFFER_NAME},
21 document::{Mode, SCRATCH_BUFFER_NAME},
22 editor::{Action, Motion},
22 editor::{Action, Motion},
23+ info::Info,
23 input::KeyEvent,
24 input::KeyEvent,
24 keyboard::KeyCode,
25 keyboard::KeyCode,
25 view::View,
26 view::View,
@@ -5745,8 +5746,10 @@ fn wonly(cx: &mut Context) {
5745}
5746}
5746
5747
5747fn select_register(cx: &mut Context) {
5748fn select_register(cx: &mut Context) {
5749+ cx.editor.autoinfo = Some(Info::from_registers(&cx.editor.registers));
5748 cx.on_next_key(move |cx, event| {
5750 cx.on_next_key(move |cx, event| {
5749 if let Some(ch) = event.char() {
5751 if let Some(ch) = event.char() {
5752+ cx.editor.autoinfo = None;
5750 cx.editor.selected_register = Some(ch);
5753 cx.editor.selected_register = Some(ch);
5751 }
5754 }
5752 })
5755 })
helix-term/src/keymap.rs+1−2
@@ -222,9 +222,8 @@ impl KeyTrieNode {
222 .map(|(desc, keys)| (desc.strip_prefix(&prefix).unwrap(), keys))
222 .map(|(desc, keys)| (desc.strip_prefix(&prefix).unwrap(), keys))
223 .collect();
223 .collect();
224 }
224 }
225− Info::new(self.name(), body)
225+ Info::from_keymap(self.name(), body)
226 }
226 }
227−
228 /// Get a reference to the key trie node's order.
227 /// Get a reference to the key trie node's order.
229 pub fn order(&self) -> &[KeyEvent] {
228 pub fn order(&self) -> &[KeyEvent] {
230 self.order.as_slice()
229 self.order.as_slice()
helix-term/src/ui/editor.rs+5−7
@@ -21,7 +21,6 @@ use helix_view::{
21 document::{Mode, SCRATCH_BUFFER_NAME},
21 document::{Mode, SCRATCH_BUFFER_NAME},
22 editor::CursorShapeConfig,
22 editor::CursorShapeConfig,
23 graphics::{CursorKind, Modifier, Rect, Style},
23 graphics::{CursorKind, Modifier, Rect, Style},
24− info::Info,
25 input::KeyEvent,
24 input::KeyEvent,
26 keyboard::{KeyCode, KeyModifiers},
25 keyboard::{KeyCode, KeyModifiers},
27 Document, Editor, Theme, View,
26 Document, Editor, Theme, View,
@@ -37,7 +36,6 @@ pub struct EditorView {
37 last_insert: (commands::MappableCommand, Vec<KeyEvent>),
36 last_insert: (commands::MappableCommand, Vec<KeyEvent>),
38 pub(crate) completion: Option<Completion>,
37 pub(crate) completion: Option<Completion>,
39 spinners: ProgressSpinners,
38 spinners: ProgressSpinners,
40− autoinfo: Option<Info>,
41}
39}
42
40
43impl Default for EditorView {
41impl Default for EditorView {
@@ -54,7 +52,6 @@ impl EditorView {
54 last_insert: (commands::MappableCommand::normal_mode, Vec::new()),
52 last_insert: (commands::MappableCommand::normal_mode, Vec::new()),
55 completion: None,
53 completion: None,
56 spinners: ProgressSpinners::default(),
54 spinners: ProgressSpinners::default(),
57− autoinfo: None,
58 }
55 }
59 }
56 }
60
57
@@ -678,13 +675,13 @@ impl EditorView {
678 cxt: &mut commands::Context,
675 cxt: &mut commands::Context,
679 event: KeyEvent,
676 event: KeyEvent,
680 ) -> Option<KeymapResult> {
677 ) -> Option<KeymapResult> {
681− self.autoinfo = None;
678+ cxt.editor.autoinfo = None;
682 let key_result = self.keymaps.get_mut(&mode).unwrap().get(event);
679 let key_result = self.keymaps.get_mut(&mode).unwrap().get(event);
683− self.autoinfo = key_result.sticky.map(|node| node.infobox());
680+ cxt.editor.autoinfo = key_result.sticky.map(|node| node.infobox());
684
681
685 match &key_result.kind {
682 match &key_result.kind {
686 KeymapResultKind::Matched(command) => command.execute(cxt),
683 KeymapResultKind::Matched(command) => command.execute(cxt),
687− KeymapResultKind::Pending(node) => self.autoinfo = Some(node.infobox()),
684+ KeymapResultKind::Pending(node) => cxt.editor.autoinfo = Some(node.infobox()),
688 KeymapResultKind::MatchedSequence(commands) => {
685 KeymapResultKind::MatchedSequence(commands) => {
689 for command in commands {
686 for command in commands {
690 command.execute(cxt);
687 command.execute(cxt);
@@ -1093,8 +1090,9 @@ impl Component for EditorView {
1093 }
1090 }
1094
1091
1095 if cx.editor.config.auto_info {
1092 if cx.editor.config.auto_info {
1096− if let Some(ref mut info) = self.autoinfo {
1093+ if let Some(mut info) = cx.editor.autoinfo.take() {
1097 info.render(area, surface, cx);
1094 info.render(area, surface, cx);
1095+ cx.editor.autoinfo = Some(info)
1098 }
1096 }
1099 }
1097 }
1100
1098
helix-view/src/editor.rs+3
@@ -2,6 +2,7 @@ use crate::{
2 clipboard::{get_clipboard_provider, ClipboardProvider},
2 clipboard::{get_clipboard_provider, ClipboardProvider},
3 document::{Mode, SCRATCH_BUFFER_NAME},
3 document::{Mode, SCRATCH_BUFFER_NAME},
4 graphics::{CursorKind, Rect},
4 graphics::{CursorKind, Rect},
5+ info::Info,
5 input::KeyEvent,
6 input::KeyEvent,
6 theme::{self, Theme},
7 theme::{self, Theme},
7 tree::{self, Tree},
8 tree::{self, Tree},
@@ -243,6 +244,7 @@ pub struct Editor {
243 pub theme_loader: Arc<theme::Loader>,
244 pub theme_loader: Arc<theme::Loader>,
244
245
245 pub status_msg: Option<(String, Severity)>,
246 pub status_msg: Option<(String, Severity)>,
247+ pub autoinfo: Option<Info>,
246
248
247 pub config: Config,
249 pub config: Config,
248
250
@@ -286,6 +288,7 @@ impl Editor {
286 registers: Registers::default(),
288 registers: Registers::default(),
287 clipboard_provider: get_clipboard_provider(),
289 clipboard_provider: get_clipboard_provider(),
288 status_msg: None,
290 status_msg: None,
291+ autoinfo: None,
289 idle_timer: Box::pin(sleep(config.idle_timeout)),
292 idle_timer: Box::pin(sleep(config.idle_timeout)),
290 last_motion: None,
293 last_motion: None,
291 config,
294 config,
helix-view/src/info.rs+40−18
@@ -1,5 +1,5 @@
1use crate::input::KeyEvent;
1use crate::input::KeyEvent;
2−use helix_core::unicode::width::UnicodeWidthStr;
2+use helix_core::{register::Registers, unicode::width::UnicodeWidthStr};
3use std::{collections::BTreeSet, fmt::Write};
3use std::{collections::BTreeSet, fmt::Write};
4
4
5#[derive(Debug)]
5#[derive(Debug)]
@@ -16,26 +16,21 @@ pub struct Info {
16}
16}
17
17
18impl Info {
18impl Info {
19− pub fn new(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
19+ pub fn new(title: &str, body: Vec<(String, String)>) -> Self {
20− let body = body
20+ if body.is_empty() {
21− .into_iter()
21+ return Self {
22− .map(|(desc, events)| {
22+ title: title.to_string(),
23− let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
23+ height: 1,
24− (desc, events.join(", "))
24+ width: title.len() as u16,
25+ text: "".to_string(),
25− })
26+ };
26− .collect::<Vec<_>>();
27+ }
27
28
28− let keymaps_width = body.iter().map(|r| r.1.len()).max().unwrap();
29+ let item_width = body.iter().map(|(item, _)| item.width()).max().unwrap();
29 let mut text = String::new();
30 let mut text = String::new();
30
31
31− for (desc, keyevents) in &body {
32+ for (item, desc) in &body {
32− let _ = writeln!(
33+ let _ = writeln!(text, "{:width$} {}", item, desc, width = item_width);
33− text,
34− "{:width$} {}",
35− keyevents,
36− desc,
37− width = keymaps_width
38− );
39 }
34 }
40
35
41 Self {
36 Self {
@@ -45,4 +40,31 @@ impl Info {
45 text,
40 text,
46 }
41 }
47 }
42 }
43+
44+ pub fn from_keymap(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
45+ let body = body
46+ .into_iter()
47+ .map(|(desc, events)| {
48+ let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
49+ (events.join(", "), desc.to_string())
50+ })
51+ .collect();
52+
53+ Self::new(title, body)
54+ }
55+
56+ pub fn from_registers(registers: &Registers) -> Self {
57+ let body = registers
58+ .inner()
59+ .iter()
60+ .map(|(ch, reg)| {
61+ let content = reg.read().join(", ").trim_end().to_string();
62+ (ch.to_string(), content)
63+ })
64+ .collect();
65+
66+ let mut infobox = Self::new("Registers", body);
67+ infobox.width = 30; // copied content could be very long
68+ infobox
69+ }
48}
70}