fix integration tests

pull/9143/head
Ingrid 9 months ago
parent 69a13fbba2
commit ca16809d75

@ -159,13 +159,11 @@ impl Application {
); );
// TODO: do most of this in the background? // TODO: do most of this in the background?
#[cfg(not(feature = "integration"))]
editor editor
.registers .registers
.write(':', persistence::read_command_history()) .write(':', persistence::read_command_history())
// TODO: do something about this unwrap // TODO: do something about this unwrap
.unwrap(); .unwrap();
#[cfg(not(feature = "integration"))]
editor editor
.registers .registers
.write('/', persistence::read_search_history()) .write('/', persistence::read_search_history())

@ -614,7 +614,6 @@ impl Component for Prompt {
{ {
cx.editor.set_error(err.to_string()); cx.editor.set_error(err.to_string());
} }
#[cfg(not(feature = "integration"))]
persistence::push_reg_history(register, &self.line); persistence::push_reg_history(register, &self.line);
}; };
} }

@ -8,9 +8,10 @@ use std::{
use anyhow::bail; use anyhow::bail;
use crossterm::event::{Event, KeyEvent}; use crossterm::event::{Event, KeyEvent};
use helix_core::{diagnostic::Severity, test, Selection, Transaction}; 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_term::{application::Application, args::Args, config::Config, keymap::merge_keys};
use helix_view::{current_ref, doc, editor::LspConfig, input::parse_macro, Editor}; use helix_view::{current_ref, doc, editor::LspConfig, input::parse_macro, Editor};
use tempfile::NamedTempFile; use tempfile::{NamedTempFile, TempPath};
use tokio_stream::wrappers::UnboundedReceiverStream; use tokio_stream::wrappers::UnboundedReceiverStream;
/// Specify how to set up the input text with line feeds /// Specify how to set up the input text with line feeds
@ -229,6 +230,22 @@ pub fn test_syntax_loader(overrides: Option<String>) -> helix_core::syntax::Load
helix_core::syntax::Loader::new(lang.try_into().unwrap()).unwrap() 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 /// Use this for very simple test cases where there is one input
/// document, selection, and sequence of key presses, and you just /// document, selection, and sequence of key presses, and you just
/// want to verify the resulting document and selection. /// want to verify the resulting document and selection.
@ -236,6 +253,7 @@ pub async fn test_with_config<T: Into<TestCase>>(
app_builder: AppBuilder, app_builder: AppBuilder,
test_case: T, test_case: T,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let (_, _, _) = init_persistence_files()?;
let test_case = test_case.into(); let test_case = test_case.into();
let app = app_builder.build()?; let app = app_builder.build()?;
@ -345,7 +363,7 @@ impl AppBuilder {
path: P, path: P,
pos: Option<helix_core::Position>, pos: Option<helix_core::Position>,
) -> Self { ) -> Self {
self.args.files.push((path.into(), pos.unwrap_or_default())); self.args.files.push((path.into(), pos));
self self
} }

@ -1740,25 +1740,36 @@ impl Editor {
self.old_file_locs.get(&path).map(|x| x.to_owned()) self.old_file_locs.get(&path).map(|x| x.to_owned())
{ {
let (view, doc) = current!(self); let (view, doc) = current!(self);
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; view.offset = view_position;
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
} }
} }
}
Ok(id) Ok(id)
} }
pub fn close(&mut self, id: ViewId) { 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(); let mut file_locs = Vec::new();
// Remove selections for the closed view on all documents.
for doc in self.documents_mut() { for doc in self.documents_mut() {
// 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() { if let Some(path) = doc.path() {
file_locs.push((path.clone(), offset, doc.selection(id).clone())); file_locs.push((path.clone(), offset, doc.selection(id).clone()));
}; }
}
// Remove selections for the closed view on all documents.
doc.remove_view(id); doc.remove_view(id);
} }

Loading…
Cancel
Save