Keep marking the copy source's first cell after the selection moves on

Copying a range showed the dashed marquee around the whole source, but the
distinct border on its first (anchor) cell disappeared the moment you
selected something else -- that border was drawn from the *live* selection's
anchor, which had just moved to the new (paste-destination) cell.

- ClipboardData now also stores the copy/cut selection's own anchor -- the
  cell the drag/shift-selection actually started from, which isn't always
  rect's top-left corner (a drag can start at any corner).
- clipboardRect exposes it; TableGrid renders a second small overlay,
  .clip-anchor, positioned on just that one cell -- independent of the
  current selection, so it stays visible for as long as the marquee does.

Verified interactively: copy B2:B5, click a cell elsewhere -- the marquee
and the solid border on B2 both remain, while the new cell gets its own
live-selection border.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
wkh
2026-09-02 10:35:35 +02:00
co-authored by Claude Sonnet 5
parent 47afe8fc20
commit fafb118db6
3 changed files with 56 additions and 2 deletions
+23
View File
@@ -565,6 +565,29 @@ describe('clipboard: copy / cut / paste', () => {
expect(s.hasClipboard.value).toBe(false);
});
it('clipboardRect keeps the copy source\'s own anchor after the live selection moves elsewhere', () => {
const s = fresh();
const id = s.addTable(s.doc.activeSheetId);
s.setSelection({ tableId: id, anchor: coords('B2'), focus: coords('B5') });
s.copySelection();
expect(s.clipboardRect.value?.anchor).toEqual(coords('B2'));
// picking a paste destination elsewhere must not move the source's anchor marker
s.setSelection({ tableId: id, anchor: coords('D2'), focus: coords('D5') });
expect(s.clipboardRect.value?.anchor).toEqual(coords('B2'));
expect(s.clipboardRect.value).toMatchObject({ tableId: id, c0: 1, c1: 1, r0: 1, r1: 4 });
});
it('the source anchor is the drag\'s own start cell, not the rectangle\'s top-left corner', () => {
const s = fresh();
const id = s.addTable(s.doc.activeSheetId);
// dragged bottom-right -> top-left: anchor is B5, not the normalised B2
s.setSelection({ tableId: id, anchor: coords('B5'), focus: coords('B2') });
s.copySelection();
expect(s.clipboardRect.value?.anchor).toEqual(coords('B5'));
expect(s.clipboardRect.value).toMatchObject({ c0: 1, c1: 1, r0: 1, r1: 4 });
});
it('copy leaves $-locked axes exactly as typed; a relative axis still shifts', () => {
const s = fresh();
const id = s.addTable(s.doc.activeSheetId);