mirror of
https://github.com/l0ng-ai/tty7.git
synced 2026-11-06 00:15:06 +00:00
fix(editor): restore a split whose left group had no recorded files
The recorder writes files: [] with a split when the left group held only untitled or remote buffers, but restore returned early on an empty left list and dropped the right group too.
This commit is contained in:
@@ -2917,7 +2917,9 @@ impl Tty7App {
|
||||
let Some(state) = editor_session::get(cx, tab_id) else {
|
||||
return;
|
||||
};
|
||||
if state.files.is_empty() {
|
||||
// The left group can be empty while the right is not: it held only
|
||||
// files that are not recorded (untitled, remote).
|
||||
if state.files.is_empty() && state.split.as_ref().is_none_or(|s| s.files.is_empty()) {
|
||||
return;
|
||||
}
|
||||
let Some(host) = self.active_host(cx) else {
|
||||
|
||||
@@ -567,4 +567,50 @@ mod gpui_tests {
|
||||
let recorded = vcx.update(|_, cx| editor_session::get(cx, tab)).unwrap();
|
||||
assert_eq!(recorded, state);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_split_with_nothing_on_the_left_still_comes_back(cx: &mut TestAppContext) {
|
||||
// The left group held only untitled or remote buffers, which are
|
||||
// not recorded: only the right group's files were written down.
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let root = dir.path().canonicalize().unwrap();
|
||||
let c = root.join("c.rs");
|
||||
std::fs::write(&c, "fn main() {}\n").unwrap();
|
||||
let (app, mut vcx, _streams) = harness_with_tabs(cx, 1);
|
||||
crate::ui::i18n::set_locale("en");
|
||||
let state = TabEditor {
|
||||
files: vec![],
|
||||
active: 0,
|
||||
visible: true,
|
||||
split: Some(SplitEditor {
|
||||
files: vec![c.clone()],
|
||||
active: 0,
|
||||
focused: true,
|
||||
}),
|
||||
};
|
||||
let tab = app.read_with(&vcx, |app, _| app.tabs[0].tree_id.get());
|
||||
vcx.update(|_, cx| editor_session::put(cx, tab, state.clone()));
|
||||
app.update_in(&mut vcx, |app, window, cx| {
|
||||
app.editor.restored.remove(&tab);
|
||||
app.editor_restore_active(window, cx);
|
||||
});
|
||||
let has_files = |app: &Entity<Tty7App>, vcx: &mut VisualTestContext| {
|
||||
app.read_with(vcx, |app, _| {
|
||||
app.tab_code().is_some_and(|c| c.active_id().is_some())
|
||||
})
|
||||
};
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
|
||||
while !has_files(&app, &mut vcx) {
|
||||
assert!(
|
||||
std::time::Instant::now() < deadline,
|
||||
"the right group's file never came back"
|
||||
);
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
vcx.run_until_parked();
|
||||
}
|
||||
app.read_with(&vcx, |app, _| {
|
||||
let code = app.tab_code().unwrap();
|
||||
assert_eq!(app.buffer(code.active_id().unwrap()).unwrap().path, c);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user