diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index bd6b5a870..8b9348bf5 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -27,6 +27,7 @@ use crate::{ handlers, job::Jobs, keymap::Keymaps, + session, ui::{self, overlay::overlaid}, }; @@ -148,6 +149,14 @@ impl Application { handlers, ); + // TODO: do most of this in the background? + #[cfg(not(feature = "integration"))] + editor + .registers + .write_unreversed(':', session::read_command_history()) + // TODO: do something about this unwrap + .unwrap(); + let keys = Box::new(Map::new(Arc::clone(&config), |config: &Config| { &config.keys })); diff --git a/helix-term/src/session.rs b/helix-term/src/session.rs index 0b06c6266..1019b6a9f 100644 --- a/helix-term/src/session.rs +++ b/helix-term/src/session.rs @@ -1,5 +1,9 @@ use helix_loader::command_histfile; -use std::{fs::OpenOptions, io::Write}; +use std::{ + fs::{File, OpenOptions}, + io::{self, BufRead, BufReader, Lines, Write}, + path::PathBuf, +}; pub fn push_history(register: char, line: &str) { let filepath = match register { @@ -17,3 +21,15 @@ pub fn push_history(register: char, line: &str) { // TODO: do something about this unwrap writeln!(file, "{}", line).unwrap(); } + +fn read_histfile(filepath: PathBuf) -> Lines> { + // TODO: do something about this unwrap + BufReader::new(File::open(filepath).unwrap()).lines() +} + +pub fn read_command_history() -> Vec { + read_histfile(command_histfile()) + .collect::>>() + // TODO: do something about this unwrap + .unwrap() +} diff --git a/helix-view/src/register.rs b/helix-view/src/register.rs index 3a2e1b7cc..0c2b5d4d6 100644 --- a/helix-view/src/register.rs +++ b/helix-view/src/register.rs @@ -104,6 +104,29 @@ impl Registers { } } + pub fn write_unreversed(&mut self, name: char, values: Vec) -> Result<()> { + match name { + '_' => Ok(()), + '#' | '.' | '%' => Err(anyhow::anyhow!("Register {name} does not support writing")), + '*' | '+' => { + self.clipboard_provider.set_contents( + values.join(NATIVE_LINE_ENDING.as_str()), + match name { + '+' => ClipboardType::Clipboard, + '*' => ClipboardType::Selection, + _ => unreachable!(), + }, + )?; + self.inner.insert(name, values); + Ok(()) + } + _ => { + self.inner.insert(name, values); + Ok(()) + } + } + } + pub fn push(&mut self, name: char, mut value: String) -> Result<()> { match name { '_' => Ok(()),