feat: enhance workspace management and history tracking in application state

This commit is contained in:
asepharyana
2026-07-12 18:09:03 +07:00
parent a59feb23c4
commit 8a11a469f9
12 changed files with 112 additions and 20 deletions
+15 -5
View File
@@ -72,6 +72,7 @@ pub struct InputState {
pub autocomplete_candidates: Vec<String>,
pub autocomplete_idx: usize,
pub autocomplete_visible: bool,
pub history_file: Option<PathBuf>,
}
const COMMANDS: &[&str] = &[
@@ -110,6 +111,7 @@ impl InputState {
autocomplete_candidates: Vec::new(),
autocomplete_idx: 0,
autocomplete_visible: false,
history_file: None,
}
}
@@ -219,14 +221,22 @@ impl InputState {
}
}
/// Submit the current buffer: push it to history, clear the buffer,
/// and return the submitted text.
///
/// Return: the text that was in the buffer before clearing.
pub fn submit(&mut self) -> String {
let result = self.buffer.clone();
if !result.is_empty() {
self.history.push(result.clone());
if self.history.last() != Some(&result) {
self.history.push(result.clone());
if let Some(ref path) = self.history_file {
if let Ok(mut file) = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(path)
{
use std::io::Write;
let _ = writeln!(file, "{}", result);
}
}
}
self.history_idx = None;
}
self.buffer.clear();