Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Jan 30, 2023
1 parent 1282066 commit 26d4fcc
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1827,10 +1827,42 @@ fn save_workspace(
_args: &[Cow<str>],
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()
}

Expand Down

0 comments on commit 26d4fcc

Please sign in to comment.