Pin that append and pop mark the editor, and only the editor's buffer does (improvise-2054)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VdfEGXA7aJ6ftMsCc9PJze
This commit is contained in:
Edward Langley
2026-09-22 23:31:33 -07:00
parent fa8c8b61a2
commit 3b8b186f67
2 changed files with 94 additions and 8 deletions
@@ -679,8 +679,16 @@ mod tests {
CellValue::Number(5.0),
))]);
press(&mut app, KeyCode::Backspace);
assert_eq!(
app.view_state.opened_editor.as_ref().map(|o| o.touched),
Some(true),
"Backspace alone did not mark the editor touched"
);
press(&mut app, KeyCode::Char('7'));
assert_eq!(app.view_state.buffers.get("edit").map(String::as_str), Some("7"));
assert_eq!(
app.view_state.buffers.get("edit").map(String::as_str),
Some("7")
);
press(&mut app, KeyCode::Enter);
assert_eq!(
app.model_state.workbook.model.get_cell(&target),
@@ -689,6 +697,30 @@ mod tests {
);
}
/// Either user edit marks the open editor, mirroring the browser's
/// `only_an_edit_of_the_editors_buffer_marks_it_touched`.
#[test]
fn appending_or_popping_marks_the_editor_touched() {
use crate::model::cell::CellValue;
use improvise_protocol::key::KeyCode;
for key in [KeyCode::Char('x'), KeyCode::Backspace] {
let mut app = grid_holding(CellValue::Number(7.0), false);
app.cursor_mut().selected = (1, 1);
press(&mut app, KeyCode::Char('i'));
assert_eq!(
app.view_state.opened_editor.as_ref().map(|o| o.touched),
Some(false)
);
press(&mut app, key);
assert_eq!(
app.view_state.opened_editor.as_ref().map(|o| o.touched),
Some(true),
"{key:?} did not mark the editor touched"
);
}
}
/// BUG (improvise-wv3h) — see `context/test-evidence/command.md`.
#[test]
fn an_editor_opened_by_enter_mode_does_not_inherit_an_earlier_seed() {
@@ -709,7 +741,10 @@ mod tests {
app.cursor_mut().selected = (0, 0);
press(&mut app, KeyCode::Char('i'));
assert_eq!(
app.view_state.opened_editor.as_ref().map(|o| o.seed.as_str()),
app.view_state
.opened_editor
.as_ref()
.map(|o| o.seed.as_str()),
Some(""),
"the first editor did not open on the empty cell"
);
@@ -720,7 +755,10 @@ mod tests {
press(&mut app, KeyCode::Char(c));
}
press(&mut app, KeyCode::Enter);
assert!(app.view_state.mode.is_editing(), "`:enter-mode editing` did not open an editor");
assert!(
app.view_state.mode.is_editing(),
"`:enter-mode editing` did not open an editor"
);
press(&mut app, KeyCode::Enter);
assert_eq!(
app.model_state.workbook.model.get_cell(&target),
+53 -5
View File
@@ -3427,7 +3427,9 @@ mod tests {
"{seed}: the advance and re-entry did not run: {commands:?}"
);
assert!(
commands.contains(&Command::SetOpenedEditor(Some(OpenedEditor::on("800".into())))),
commands.contains(&Command::SetOpenedEditor(Some(OpenedEditor::on(
"800".into()
)))),
"{seed}: the reopened editor did not capture its own seed: {commands:?}"
);
}
@@ -3461,6 +3463,11 @@ mod tests {
vec![((1, 0), moved)],
))));
press_folded(&mut client, KeyCode::Backspace);
assert_eq!(
client.view.opened_editor.as_ref().map(|o| o.touched),
Some(true),
"Backspace alone did not mark the editor touched"
);
press_folded(&mut client, KeyCode::Char('7'));
assert_eq!(read_buffer(&client.view, "edit"), "7");
let commands = press_folded(&mut client, KeyCode::Enter);
@@ -3479,24 +3486,65 @@ mod tests {
);
}
/// Either user edit marks the open editor, and nothing else does: a key
/// into another buffer leaves it alone. Evidence: clients.md.
#[test]
fn only_an_edit_of_the_editors_buffer_marks_it_touched() {
for key in [KeyCode::Char('x'), KeyCode::Backspace] {
let mut client = client_on_row_one("7");
press_folded(&mut client, KeyCode::Char('i'));
assert_eq!(
client.view.opened_editor.as_ref().map(|o| o.touched),
Some(false)
);
press_folded(&mut client, key);
assert_eq!(
client.view.opened_editor.as_ref().map(|o| o.touched),
Some(true),
"{key:?} did not mark the editor touched"
);
}
let mut state = client_on_row_one("7");
state.view.opened_editor = Some(OpenedEditor::on("7".into()));
assert_eq!(
typed_into(&state, "command", "q".into()),
vec![Command::SetBuffer {
name: "command".into(),
value: "q".into()
}],
"typing into another buffer marked the cell editor"
);
}
/// BUG (improvise-wv3h) — see `context/test-evidence/clients.md`.
#[test]
fn a_browser_editor_opened_by_enter_mode_does_not_inherit_an_earlier_seed() {
let mut client = client_on_row_one("");
press_folded(&mut client, KeyCode::Char('i'));
press_folded(&mut client, KeyCode::Esc);
assert!(!client.view.mode.is_editing(), "Esc did not close the editor");
assert!(
!client.view.mode.is_editing(),
"Esc did not close the editor"
);
let mut moved = CellDisplay::number("9");
moved.id = Some(record_cell());
client.fold(&Command::Project(Projection::Grid(GridUpdate::Cells(
vec![((1, 0), moved)],
))));
let entered = composed(&client, ev(KeyCode::Enter), "enter-mode", &["editing".into()])
.expect("enter-mode editing composes here");
let entered = composed(
&client,
ev(KeyCode::Enter),
"enter-mode",
&["editing".into()],
)
.expect("enter-mode editing composes here");
for command in &entered {
client.fold(command);
}
assert!(client.view.mode.is_editing(), "enter-mode did not open an editor");
assert!(
client.view.mode.is_editing(),
"enter-mode did not open an editor"
);
let commands = press_folded(&mut client, KeyCode::Enter);
assert!(
commands.iter().any(|c| matches!(