From 26d4fcc26ca188244a46121b7454cfb423698d2f Mon Sep 17 00:00:00 2001 From: Shafkath Shuhan Date: Mon, 30 Jan 2023 10:37:31 -0500 Subject: [PATCH] wip --- helix-term/src/commands/typed.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index befb816984043..a72d58327ef37 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1827,10 +1827,42 @@ fn save_workspace( _args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { + use helix_view::workspace::undo::UndoIndex; + use helix_view::workspace::Workspace; + if event != PromptEvent::Validate { return Ok(()); } + let mut workspace = Workspace::new()?; + let mut index_file = workspace.get_mut(".index")?; + + // Create a merged list of key-value tuples from the saved index and the open buffers. + let index = { + let mut saved_files = UndoIndex::deserialize(&mut index_file) + .unwrap_or(UndoIndex::default()) + .0; + let mut last_id = saved_files.last().map(|(id, _)| *id + 1).unwrap_or(0); + let mut new_files = cx + .editor + .documents() + .filter_map(|doc| { + doc.path().filter(|path| { + !saved_files + .iter() + .any(|(_, indexed_path)| indexed_path == *path) + }) + }) + .map(|path| { + let id = last_id; + last_id += 1; + (id, path.clone()) + }) + .collect(); + saved_files.append(&mut new_files); + UndoIndex(saved_files) + }; + cx.editor.save_workspace() }