diff --git a/helix-loader/src/persistence.rs b/helix-loader/src/persistence.rs index 926e0d4da..73e9d05bb 100644 --- a/helix-loader/src/persistence.rs +++ b/helix-loader/src/persistence.rs @@ -6,7 +6,7 @@ use std::{ path::PathBuf, }; -pub fn push_history(filepath: PathBuf, entry: T) { +pub fn push_history(filepath: PathBuf, entry: &T) { let file = OpenOptions::new() .append(true) .create(true) @@ -15,7 +15,7 @@ pub fn push_history(filepath: PathBuf, entry: T) { .unwrap(); // TODO: do something about this unwrap - serialize_into(file, &entry).unwrap(); + serialize_into(file, entry).unwrap(); } pub fn read_history Deserialize<'a>>(filepath: PathBuf) -> Vec { diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 906dc4fa4..9c65f08e6 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1765,7 +1765,11 @@ impl Editor { // We need to persist ViewPositions on documents a la PR #7568, then fetch that here. if doc.selections().contains_key(&id) { if let Some(path) = doc.path() { - file_locs.push((path.clone(), offset, doc.selection(id).clone())); + file_locs.push(FileHistoryEntry::new( + path.clone(), + offset, + doc.selection(id).clone(), + )); } } @@ -1774,13 +1778,9 @@ impl Editor { } for loc in file_locs { - // TODO: can the arg here be a reference? would save cloning - persistence::push_file_history(FileHistoryEntry::new( - loc.0.clone(), - loc.1, - loc.2.clone(), - )); - self.old_file_locs.insert(loc.0, (loc.1, loc.2)); + persistence::push_file_history(&loc); + self.old_file_locs + .insert(loc.path, (loc.view_position, loc.selection)); } self.tree.remove(id); @@ -1820,7 +1820,11 @@ impl Editor { if view.doc == doc_id { if let Some(path) = doc.path() { - file_locs.push((path.clone(), view.offset, doc.selection(view.id).clone())); + file_locs.push(FileHistoryEntry::new( + path.clone(), + view.offset, + doc.selection(view.id).clone(), + )); }; // something was previously open in the view, switch to previous doc @@ -1837,13 +1841,9 @@ impl Editor { .collect(); for loc in file_locs { - // TODO: can the arg here be a reference? would save cloning - persistence::push_file_history(FileHistoryEntry::new( - loc.0.clone(), - loc.1, - loc.2.clone(), - )); - self.old_file_locs.insert(loc.0, (loc.1, loc.2)); + persistence::push_file_history(&loc); + self.old_file_locs + .insert(loc.path, (loc.view_position, loc.selection)); } for action in actions { diff --git a/helix-view/src/persistence.rs b/helix-view/src/persistence.rs index d4a00cf04..bb02d7714 100644 --- a/helix-view/src/persistence.rs +++ b/helix-view/src/persistence.rs @@ -26,7 +26,7 @@ impl FileHistoryEntry { } } -pub fn push_file_history(entry: FileHistoryEntry) { +pub fn push_file_history(entry: &FileHistoryEntry) { push_history(file_histfile(), entry) } @@ -34,7 +34,7 @@ pub fn read_file_history() -> Vec { read_history(file_histfile()) } -pub fn push_reg_history(register: char, line: &str) { +pub fn push_reg_history(register: char, line: &String) { let filepath = match register { ':' => command_histfile(), '/' => search_histfile(),