aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorGokul Soumya2021-11-04 18:33:31 +0000
committerBlaž Hrastnik2022-02-10 01:52:06 +0000
commitbf773db45171b59a758b7dabf9f10ffb8852dcf0 (patch)
tree1f472eeaf0f752d2d0af83aeb7b2931811e47e65 /helix-view
parent5995568c1d23239a230d6e1bcbfc370e5c8cd287 (diff)
Show infobox with register contents
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/editor.rs3
-rw-r--r--helix-view/src/info.rs58
2 files changed, 43 insertions, 18 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 27e6f137..43ea8d15 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -2,6 +2,7 @@ use crate::{
clipboard::{get_clipboard_provider, ClipboardProvider},
document::{Mode, SCRATCH_BUFFER_NAME},
graphics::{CursorKind, Rect},
+ info::Info,
input::KeyEvent,
theme::{self, Theme},
tree::{self, Tree},
@@ -243,6 +244,7 @@ pub struct Editor {
pub theme_loader: Arc<theme::Loader>,
pub status_msg: Option<(String, Severity)>,
+ pub autoinfo: Option<Info>,
pub config: Config,
@@ -286,6 +288,7 @@ impl Editor {
registers: Registers::default(),
clipboard_provider: get_clipboard_provider(),
status_msg: None,
+ autoinfo: None,
idle_timer: Box::pin(sleep(config.idle_timeout)),
last_motion: None,
config,
diff --git a/helix-view/src/info.rs b/helix-view/src/info.rs
index 73856154..fbe27ea0 100644
--- a/helix-view/src/info.rs
+++ b/helix-view/src/info.rs
@@ -1,5 +1,5 @@
use crate::input::KeyEvent;
-use helix_core::unicode::width::UnicodeWidthStr;
+use helix_core::{register::Registers, unicode::width::UnicodeWidthStr};
use std::{collections::BTreeSet, fmt::Write};
#[derive(Debug)]
@@ -16,26 +16,21 @@ pub struct Info {
}
impl Info {
- pub fn new(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
- let body = body
- .into_iter()
- .map(|(desc, events)| {
- let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
- (desc, events.join(", "))
- })
- .collect::<Vec<_>>();
+ pub fn new(title: &str, body: Vec<(String, String)>) -> Self {
+ if body.is_empty() {
+ return Self {
+ title: title.to_string(),
+ height: 1,
+ width: title.len() as u16,
+ text: "".to_string(),
+ };
+ }
- let keymaps_width = body.iter().map(|r| r.1.len()).max().unwrap();
+ let item_width = body.iter().map(|(item, _)| item.width()).max().unwrap();
let mut text = String::new();
- for (desc, keyevents) in &body {
- let _ = writeln!(
- text,
- "{:width$} {}",
- keyevents,
- desc,
- width = keymaps_width
- );
+ for (item, desc) in &body {
+ let _ = writeln!(text, "{:width$} {}", item, desc, width = item_width);
}
Self {
@@ -45,4 +40,31 @@ impl Info {
text,
}
}
+
+ pub fn from_keymap(title: &str, body: Vec<(&str, BTreeSet<KeyEvent>)>) -> Self {
+ let body = body
+ .into_iter()
+ .map(|(desc, events)| {
+ let events = events.iter().map(ToString::to_string).collect::<Vec<_>>();
+ (events.join(", "), desc.to_string())
+ })
+ .collect();
+
+ Self::new(title, body)
+ }
+
+ pub fn from_registers(registers: &Registers) -> Self {
+ let body = registers
+ .inner()
+ .iter()
+ .map(|(ch, reg)| {
+ let content = reg.read().join(", ").trim_end().to_string();
+ (ch.to_string(), content)
+ })
+ .collect();
+
+ let mut infobox = Self::new("Registers", body);
+ infobox.width = 30; // copied content could be very long
+ infobox
+ }
}