diff --git a/crates/ui-egui/src/app/editing.rs b/crates/ui-egui/src/app/editing.rs index abb849aba..61b2af1ff 100644 --- a/crates/ui-egui/src/app/editing.rs +++ b/crates/ui-egui/src/app/editing.rs @@ -100,7 +100,8 @@ impl SheetApp { let Some(ed) = self.editor.take() else { return true }; self.session.mode = gridcraft_engine::Mode::Ready; let text = match &ed.completion { - Some(full) if full.to_lowercase().starts_with(&ed.text.to_lowercase()) => full.clone(), + // A code edit commits the code as typed, whatever a completion holds. + Some(full) if !ed.code_edit && full.to_lowercase().starts_with(&ed.text.to_lowercase()) => full.clone(), _ => ed.text.clone(), }; // F2 then Enter (or a file command) on an untouched draft: nothing to write. diff --git a/crates/ui-egui/src/formula_bar.rs b/crates/ui-egui/src/formula_bar.rs index 557e3dac0..1f0bf11b3 100644 --- a/crates/ui-egui/src/formula_bar.rs +++ b/crates/ui-egui/src/formula_bar.rs @@ -390,8 +390,10 @@ pub fn editor_widget(app: &mut SheetApp, ui: &mut egui::Ui, id: egui::Id, font: } if resp.changed() { ed.completion = None; + // Python code is never completed from the column's text values. if app.ui.autocomplete && !ed.is_formula() + && !ed.code_edit && !entry_shrank(chars_before, &ed.text) && ed.caret == ed.text.chars().count() && let Some(sh) = app.session.active().and_then(|d| d.wb.sheet(ed.sheet)) diff --git a/crates/ui-egui/tests/it/python_cell_edit.rs b/crates/ui-egui/tests/it/python_cell_edit.rs index 0afa43185..3153299c5 100644 --- a/crates/ui-egui/tests/it/python_cell_edit.rs +++ b/crates/ui-egui/tests/it/python_cell_edit.rs @@ -113,3 +113,16 @@ fn deleting_all_the_code_clears_a_python_cell_with_no_cached_value() { assert!(h.state().editor.is_none()); assert_eq!(python(&h), None, "the code is removed, not kept as an unchanged empty cell"); } + +#[test] +fn a_code_edit_is_never_completed_from_the_column() { + let mut h = harness(); + // A2 holds text that starts with A1's code: typing at the end of the code would offer it. + h.state_mut().session.execute("cell.set", json!({"cell": "A2", "input": "1 + 1 and more"})).unwrap(); + select_a1(&mut h); + key(&mut h, Key::F2); + text(&mut h, " "); + assert_eq!(h.state().editor.as_ref().and_then(|e| e.completion.clone()), None, "no completion while code is edited"); + key(&mut h, Key::Enter); + assert_eq!(python(&h), Some(("1 + 1 ".into(), true)), "the typed code is kept"); +}