#3136: a move on another sheet keeps the active sheet's selection

Addresses CodeRabbit review on #3216, "Keep the selection on the sheet it
describes": moving Two!B1:B2 with Sheet1 active selected A1:A2 on
Sheet1, where nothing moved. The selection belongs to the active sheet,
so range.move now keeps it when the moved cells are on another sheet; a
move on the active sheet still selects the moved cells.

Test: drag_and_drop_on_another_sheet_stays_on_that_sheet (now also
checks the selection).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hector VillarrealandClaude Opus 5.5 committed 2026-11-03 00:31:59 -06:00
1 parent 6874e0b689
commit ba1c62469d
2 files changed
+12 -2

No files matched your search

+8 -2
View File
@@ -183,8 +183,14 @@ pub(super) fn range_move(s: &mut Session, p: &Json) -> Result<Json> {
{
return Err(EngineError::Confirm("There's already data here. Do you want to replace it?".into()));
}
// On the range's sheet, which `paste` would leave to the active one.
paste_special(s, &json!({"what": "all", "at": to.a1(), "sheet": sheet}))
// On the range's sheet, which `paste` would leave to the active one. The selection
// belongs to the active sheet: it follows the moved cells only when they are on it.
let selection = s.doc()?.selection.clone();
let pasted = paste_special(s, &json!({"what": "all", "at": to.a1(), "sheet": sheet}))?;
if sheet != s.doc()?.wb.active_sheet() {
s.doc_mut()?.selection = selection;
}
Ok(pasted)
});
if moved.is_err() {
s.clipboard = kept;
+4
View File
@@ -408,7 +408,11 @@ fn drag_and_drop_on_another_sheet_stays_on_that_sheet() {
s.execute("range.setValues", json!({"range": "B1:B2", "values": [["Kiwi"], ["Plum"]]})).unwrap();
s.execute("sheet.activate", json!({"sheet": 0})).unwrap();
s.execute("cell.set", json!({"cell": "A1", "input": "Keep"})).unwrap();
s.execute("selection.set", json!({"range": "C5"})).unwrap();
s.execute("range.move", json!({"range": "Two!B1:B2", "to": "A1"})).unwrap();
// Sheet1 stays active with its own selection; the moved cells are on Two.
assert_eq!(s.doc().unwrap().wb.active_sheet(), 0);
assert_eq!(s.doc().unwrap().selection.a1(), "C5");
let wb = &s.doc().unwrap().wb;
let two = wb.sheet_index("Two").unwrap();
assert_eq!(wb.sheet(0).unwrap().value(CellRef::new(0, 0)), Value::text("Keep"));