diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 57a8d0c52..d5c20a1e1 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -159,13 +159,11 @@ impl Application { ); // TODO: do most of this in the background? - #[cfg(not(feature = "integration"))] editor .registers .write(':', persistence::read_command_history()) // TODO: do something about this unwrap .unwrap(); - #[cfg(not(feature = "integration"))] editor .registers .write('/', persistence::read_search_history()) diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index ef87f49cd..0e0e1dcfa 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -614,7 +614,6 @@ impl Component for Prompt { { cx.editor.set_error(err.to_string()); } - #[cfg(not(feature = "integration"))] persistence::push_reg_history(register, &self.line); }; } diff --git a/helix-term/tests/test/helpers.rs b/helix-term/tests/test/helpers.rs index 70b3f4022..3e4c952c2 100644 --- a/helix-term/tests/test/helpers.rs +++ b/helix-term/tests/test/helpers.rs @@ -8,9 +8,10 @@ use std::{ use anyhow::bail; use crossterm::event::{Event, KeyEvent}; use helix_core::{diagnostic::Severity, test, Selection, Transaction}; +use helix_loader; use helix_term::{application::Application, args::Args, config::Config, keymap::merge_keys}; use helix_view::{current_ref, doc, editor::LspConfig, input::parse_macro, Editor}; -use tempfile::NamedTempFile; +use tempfile::{NamedTempFile, TempPath}; use tokio_stream::wrappers::UnboundedReceiverStream; /// Specify how to set up the input text with line feeds @@ -229,6 +230,22 @@ pub fn test_syntax_loader(overrides: Option) -> helix_core::syntax::Load helix_core::syntax::Loader::new(lang.try_into().unwrap()).unwrap() } +fn init_persistence_files() -> anyhow::Result<(TempPath, TempPath, TempPath)> { + let command_file = NamedTempFile::new()?; + let command_path = command_file.into_temp_path(); + helix_loader::initialize_command_histfile(Some(command_path.to_path_buf())); + + let search_file = NamedTempFile::new()?; + let search_path = search_file.into_temp_path(); + helix_loader::initialize_search_histfile(Some(search_path.to_path_buf())); + + let file_file = NamedTempFile::new()?; + let file_path = file_file.into_temp_path(); + helix_loader::initialize_file_histfile(Some(file_path.to_path_buf())); + + Ok((command_path, search_path, file_path)) +} + /// Use this for very simple test cases where there is one input /// document, selection, and sequence of key presses, and you just /// want to verify the resulting document and selection. @@ -236,6 +253,7 @@ pub async fn test_with_config>( app_builder: AppBuilder, test_case: T, ) -> anyhow::Result<()> { + let (_, _, _) = init_persistence_files()?; let test_case = test_case.into(); let app = app_builder.build()?; @@ -345,7 +363,7 @@ impl AppBuilder { path: P, pos: Option, ) -> Self { - self.args.files.push((path.into(), pos.unwrap_or_default())); + self.args.files.push((path.into(), pos)); self } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 04dd49fe8..906dc4fa4 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1740,8 +1740,13 @@ impl Editor { self.old_file_locs.get(&path).map(|x| x.to_owned()) { let (view, doc) = current!(self); - view.offset = view_position; - doc.set_selection(view.id, selection); + + let doc_len = doc.text().len_chars(); + // don't restore the view and selection if the selection goes beyond the file's end + if !selection.ranges().iter().any(|range| range.to() >= doc_len) { + view.offset = view_position; + doc.set_selection(view.id, selection); + } } } @@ -1749,16 +1754,22 @@ impl Editor { } pub fn close(&mut self, id: ViewId) { - let offset = self.tree.get(id).offset.clone(); + let offset = self.tree.get(id).offset; let mut file_locs = Vec::new(); - // Remove selections for the closed view on all documents. for doc in self.documents_mut() { - if let Some(path) = doc.path() { - file_locs.push((path.clone(), offset, doc.selection(id).clone())); - }; + // Persist file location history for this view + // FIXME: The view offset here is currently wrong when a doc is not current for that view. + // Right now it uses the current offset of the view, which is on a another document. + // 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())); + } + } + // Remove selections for the closed view on all documents. doc.remove_view(id); }