Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(sheets): keep a cell's fill and font while it is selected or edited (#8127)

teo3716ac0bd8bf
diff --git a/apps/web/src/features/block-spreadsheet/README.md b/apps/web/src/features/block-spreadsheet/README.md
index ac1ebe895b..a3b0d133dd 100644
--- a/apps/web/src/features/block-spreadsheet/README.md
+++ b/apps/web/src/features/block-spreadsheet/README.md
@@ -262,9 +262,11 @@ Selection does not recalculate the workbook. A bounded row window mounts visible
rows and a small buffer, keeping the active editor mounted while scrolling. Shared
row offsets account for wrapped text, font size, and zoom. Two overlays
draw the selected range and active cell, while Solid selectors update only
-changed cell selection attributes. Footer aggregates run outside urgent pointer
-updates, and collaborator presence is limited to ten updates per second with a
-trailing update for the final selection.
+changed cell selection attributes. The range's tint has a hole at the active
+cell, and the in-cell editor inherits the cell's fill, font and color, so a
+styled cell looks the same selected, editing and unselected. Footer aggregates
+run outside urgent pointer updates, and collaborator presence is limited to ten
+updates per second with a trailing update for the final selection.
IronCalc handles formula parsing, ranges, relative and absolute references,
dependency evaluation, functions, circular references, Excel errors, and array
diff --git a/apps/web/src/features/block-spreadsheet/browser-test/README.md b/apps/web/src/features/block-spreadsheet/browser-test/README.md
index 6cc4dca9ca..0926801efb 100644
--- a/apps/web/src/features/block-spreadsheet/browser-test/README.md
+++ b/apps/web/src/features/block-spreadsheet/browser-test/README.md
@@ -112,4 +112,4 @@ explicit test document/socket query parameters are supplied.
## Editor interaction regressions
-`editor-interactions.browser.e2e.ts` mounts the real global hotkey listener to verify that selected-cell typing and arrows beat app navigation shortcuts. It also exercises multi-header drag/Shift selection, persistent row resizing and auto-fit, cross-sheet formula reference picking, and numeric/month-end date fill with undo. `formatting.browser.e2e.ts` checks mixed whole-column formatting, style persistence, viewport stability, and percentage entry through both editors against the real calculation worker.
+`editor-interactions.browser.e2e.ts` mounts the real global hotkey listener to verify that selected-cell typing and arrows beat app navigation shortcuts. It also exercises multi-header drag/Shift selection, persistent row resizing and auto-fit, cross-sheet formula reference picking, and numeric/month-end date fill with undo. `formatting.browser.e2e.ts` checks mixed whole-column formatting, style persistence, viewport stability, a styled cell's pixels staying the same when selected, in a range and edited, and percentage entry through both editors against the real calculation worker.
diff --git a/apps/web/src/features/block-spreadsheet/browser-test/formatting.browser.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/formatting.browser.e2e.ts
index ee30443548..06d5e6915c 100644
--- a/apps/web/src/features/block-spreadsheet/browser-test/formatting.browser.e2e.ts
+++ b/apps/web/src/features/block-spreadsheet/browser-test/formatting.browser.e2e.ts
@@ -63,6 +63,72 @@ test('formats a mixed whole column from ribbon menus without losing selection or
await expect(top).toBeInViewport();
});
+test('keeps a styled cell looking the same while it is selected, in a range and edited', async ({
+ page,
+}) => {
+ const styled = page.locator('[data-address="A2"]');
+ await styled.click();
+ await page.locator('[data-address="B2"]').click({ modifiers: ['Shift'] });
+ await choose(page, 'Fill color', 'Fill color: Blue');
+ await choose(page, 'Text color', 'Text color: Light yellow');
+ await choose(page, 'Font family', 'Serif');
+ await choose(page, 'Horizontal alignment', 'Center');
+ for (const label of [
+ 'Bold',
+ 'Italic',
+ 'Underline',
+ 'Increase font size',
+ 'Increase font size',
+ ])
+ await page.getByRole('button', { name: label, exact: true }).click();
+ // Pixels inside the selection outline and clear of the fill handle.
+ const inside = async (address: string) => {
+ const box = await page.locator(`[data-address="${address}"]`).boundingBox();
+ if (!box) throw new Error(`${address} is not rendered.`);
+ return page.screenshot({
+ clip: {
+ x: box.x + 6,
+ y: box.y + 6,
+ width: box.width - 12,
+ height: box.height - 12,
+ },
+ });
+ };
+ await page.locator('[data-address="D7"]').click();
+ const unselected = await inside('A2');
+ const neighbor = await inside('B2');
+
+ await styled.click();
+ expect((await inside('A2')).equals(unselected)).toBe(true);
+
+ // A range tints the cells around the active one, over their own fill.
+ await page.locator('[data-address="B3"]').click({ modifiers: ['Shift'] });
+ expect((await inside('A2')).equals(unselected)).toBe(true);
+ expect((await inside('B2')).equals(neighbor)).toBe(false);
+ await expect(page.locator('[data-address="B2"]')).toHaveCSS(
+ 'background-color',
+ 'rgb(66, 133, 244)'
+ );
+
+ await styled.dblclick();
+ const editor = page.getByRole('textbox', { name: 'Edit A2', exact: true });
+ await expect(editor).toBeFocused();
+ for (const [property, value] of [
+ ['background-color', 'rgb(66, 133, 244)'],
+ ['color', 'rgb(255, 242, 204)'],
+ ['font-family', /Georgia/],
+ ['font-size', '16px'],
+ ['font-weight', '600'],
+ ['font-style', 'italic'],
+ ['text-align', 'center'],
+ ['text-decoration-line', 'underline'],
+ ] as const) {
+ await expect(styled).toHaveCSS(property, value);
+ await expect(editor).toHaveCSS(property, value);
+ }
+ expect((await inside('A2')).equals(unselected)).toBe(true);
+});
+
test('treats direct typing and formula-bar edits as percentage points while preserving formula math', async ({
page,
}) => {
diff --git a/apps/web/src/features/block-spreadsheet/components/FormulaInput.test.tsx b/apps/web/src/features/block-spreadsheet/components/FormulaInput.test.tsx
index 25ef33515e..683053f81d 100644
--- a/apps/web/src/features/block-spreadsheet/components/FormulaInput.test.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/FormulaInput.test.tsx
@@ -177,25 +177,34 @@ it('commits on blur after starting a formula without a mention adapter', () => {
expect(blur).toHaveBeenCalledOnce();
});
-it('colors reference text while the textarea keeps the caret', () => {
+it('colors reference text while the textarea keeps the caret in the text color', () => {
const view = render(() => (
- <FormulaInput
- label="Formula"
- value="=A1+B2"
- class=""
- references={[
- { start: 1, end: 3, color: 'var(--color-blue)' },
- { start: 4, end: 6, color: 'var(--color-red)' },
- ]}
- onInput={vi.fn()}
- onKeyDown={vi.fn()}
- onBlur={vi.fn()}
- />
+ <>
+ <style>{'textarea { color: rgb(255, 242, 204); }'}</style>
+ <FormulaInput
+ label="Formula"
+ value="=A1+B2"
+ class=""
+ references={[
+ { start: 1, end: 3, color: 'var(--color-blue)' },
+ { start: 4, end: 6, color: 'var(--color-red)' },
+ ]}
+ onInput={vi.fn()}
+ onKeyDown={vi.fn()}
+ onBlur={vi.fn()}
+ />
+ </>
));
const input = view.getByRole('textbox', { name: 'Formula' });
- expect(input.style.color).toBe('transparent');
- const mirror = view.container.querySelector('[data-formula-mirror]')!;
+ expect(input.style.getPropertyValue('-webkit-text-fill-color')).toBe(
+ 'transparent'
+ );
+ expect(getComputedStyle(input).color).toBe('rgb(255, 242, 204)');
+ const mirror = view.container.querySelector<HTMLElement>(
+ '[data-formula-mirror]'
+ )!;
expect(mirror.textContent).toBe('=A1+B2');
+ expect(mirror.style.color).toBe('rgb(255, 242, 204)');
const colored = [...mirror.querySelectorAll<HTMLSpanElement>('span span')]
.filter((span) => span.style.color)
.map((span) => [span.textContent, span.style.color]);
diff --git a/apps/web/src/features/block-spreadsheet/components/FormulaInput.tsx b/apps/web/src/features/block-spreadsheet/components/FormulaInput.tsx
index f8d8688fcd..2a9854bc25 100644
--- a/apps/web/src/features/block-spreadsheet/components/FormulaInput.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/FormulaInput.tsx
@@ -193,7 +193,7 @@ function FormulaTextarea(props: FormulaInputProps & { typed?: boolean }) {
class={`${props.class} touch:text-[max(16px,1rem)]`}
style={
props.references?.length
- ? { color: 'transparent', 'caret-color': 'var(--color-ink)' }
+ ? { '-webkit-text-fill-color': 'transparent' }
: undefined
}
value={props.value}
@@ -334,8 +334,8 @@ function FormulaTextarea(props: FormulaInputProps & { typed?: boolean }) {
/**
* Draws the textarea's text over it, with references in their colors. A
- * textarea cannot style part of its text, so it keeps the caret and selection
- * while its own text is transparent.
+ * textarea cannot style part of its text, so it keeps the caret, selection and
+ * text color while its glyphs are transparent.
*/
function ReferenceMirror(props: {
input: HTMLTextAreaElement;
@@ -371,6 +371,7 @@ function ReferenceMirror(props: {
fontSize: style.fontSize,
fontWeight: style.fontWeight,
fontStyle: style.fontStyle,
+ color: style.color,
letterSpacing: style.letterSpacing,
lineHeight: style.lineHeight,
textAlign: style.textAlign,
@@ -404,7 +405,7 @@ function ReferenceMirror(props: {
ref={mirror}
aria-hidden="true"
data-formula-mirror
- class="pointer-events-none absolute box-border overflow-hidden whitespace-pre border-solid border-transparent text-ink"
+ class="pointer-events-none absolute box-border overflow-hidden whitespace-pre border-solid border-transparent"
>
<span ref={text} class="block">
<For each={segments()}>
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
index e288e3301a..213fde9bd5 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
@@ -638,6 +638,19 @@ export function SpreadsheetGrid(props: {
width: width(props.selection.anchor.column),
height: `${rowHeights()[props.selection.anchor.row]}px`,
});
+ // As in Excel, the active cell shows its own fill: the range's tint has a
+ // hole there, and the active outline draws that edge.
+ const rangeClip = () => {
+ const area = bounds();
+ const { row, column } = props.selection.anchor;
+ const columns = columnOffsets();
+ const rows = rowOffsets();
+ const left = columns[column] - columns[area.left];
+ const right = columns[column + 1] - columns[area.left];
+ const top = rows[row] - rows[area.top];
+ const bottom = rows[row + 1] - rows[area.top];
+ return `polygon(evenodd, 0 0, 100% 0, 100% 100%, 0 100%, 0 0, ${left}px ${top}px, ${right}px ${top}px, ${right}px ${bottom}px, ${left}px ${bottom}px, ${left}px ${top}px)`;
+ };
function stopTouchGesture() {
if (autoScrollFrame !== undefined) cancelAnimationFrame(autoScrollFrame);
@@ -1913,7 +1926,15 @@ export function SpreadsheetGrid(props: {
(isTouchDevice() && !!props.referenceSelection)
}
onSelectionChange={props.onTextSelection}
- class="absolute inset-0 size-full resize-none overflow-hidden bg-panel px-[var(--spreadsheet-cell-padding)] py-[var(--spreadsheet-cell-padding-y)] font-normal text-left text-ink outline-none select-text"
+ // Inherits the cell's fill, font and color; automatic
+ // alignment edits from the left, as in Excel.
+ class={`absolute inset-0 size-full resize-none overflow-hidden bg-inherit px-[var(--spreadsheet-cell-padding)] py-[var(--spreadsheet-cell-padding-y)] [text-decoration-line:inherit] outline-none select-text ${
+ cell()?.horizontalAlign === 'center'
+ ? 'text-center'
+ : cell()?.horizontalAlign === 'right'
+ ? 'text-right'
+ : 'text-left'
+ }`}
value={props.draft}
onInput={props.onDraft}
onKeyDown={editKeyDown}
@@ -2090,7 +2111,7 @@ export function SpreadsheetGrid(props: {
aria-hidden="true"
data-selection-range
class="pointer-events-none absolute z-[1] border border-accent bg-accent/10"
- style={rangeStyle()}
+ style={{ ...rangeStyle(), 'clip-path': rangeClip() }}
/>
<div
aria-hidden="true"
diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.md
index 28294dee38..8d87e01ef5 100644
--- a/docs/agent-guide/documents.md
+++ b/docs/agent-guide/documents.md
@@ -280,9 +280,12 @@ Drag across row/column headers or Shift-click a second header to select multiple
whole rows/columns. Arrow keys then move from the selection's active cell. The
focused grid owns typing and navigation; app navigation shortcuts do not run while
it has focus.
-The active cell keeps a complete border while editing; a range has a shaded
-fill and an outer border. Verify selection in both drag directions and after
-scrolling, including near the last row and column.
+The active cell keeps a complete border while editing; a range has a translucent
+tint over its cells' own fills and an outer border. The active cell is never
+tinted: selected or being edited, it keeps its fill, font, text color, and
+explicit alignment (automatic alignment edits from the left, as in Excel).
+Verify selection in both drag directions and after scrolling, including near
+the last row and column.
Only nearby rows are mounted. Use **Go to cell** or keyboard navigation to reach
off-screen cells; verify the target is visible below the sticky column header.