Keep the first-selected cell marked as active during a multi-cell selection

The active cell (bold border/handle, formula bar target) used to track
selection.focus, so it followed the mouse/cursor while dragging or
shift-extending a range. Switch it to selection.anchor -- the first cell of
the current selection action -- so it stays put while the range grows,
matching Excel/Numbers. Tab/Enter data-entry flow already keeps anchor ==
focus while it moves the cursor, so that behaviour is unaffected.

- document.ts: activeCell/activeCellName/activeCellInput read the anchor.
- FormulaBar.vue: commits to the anchor cell to match what it displays.
- TableGrid.vue: isActive() (border + handle) and F2/type-to-edit target
  the anchor; Home/End keep using the cursor's row via s.focus.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
wkh
2026-09-02 09:59:29 +02:00
co-authored by Claude Sonnet 5
parent 44f3314137
commit e45cdfd077
4 changed files with 18 additions and 9 deletions
+6 -3
View File
@@ -993,18 +993,21 @@ function createStore() {
});
}
const activeCell = computed<CellCoord>(() => doc.selection?.focus ?? { col: 0, row: 0 });
// The "active cell" is always the anchor -- the first cell of the current
// selection action (click, shift-click, drag start, ...) -- so it stays put
// while a multi-cell selection is being made, matching Excel/Numbers.
const activeCell = computed<CellCoord>(() => doc.selection?.anchor ?? { col: 0, row: 0 });
const activeCellName = computed(() => {
const sel = doc.selection;
const t = sel ? tableById(sel.tableId) : activeTable.value;
const cell = sel?.focus ?? { col: 0, row: 0 };
const cell = sel?.anchor ?? { col: 0, row: 0 };
return `${t?.name ?? '—'}::${toA1(cell.col, cell.row)}`;
});
const activeCellInput = computed(() => {
const sel = doc.selection;
return sel ? cellInput(sel.tableId, sel.focus.col, sel.focus.row) : '';
return sel ? cellInput(sel.tableId, sel.anchor.col, sel.anchor.row) : '';
});
const selectionAggregate = computed(() => {