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.

feat(sheets): indent cell text with Excel's increase and decrease indent (#8130)

teoca76d9ab459a
diff --git a/apps/web/src/features/block-spreadsheet/README.md b/apps/web/src/features/block-spreadsheet/README.md
index 593e8cdb13..38d6113015 100644
--- a/apps/web/src/features/block-spreadsheet/README.md
+++ b/apps/web/src/features/block-spreadsheet/README.md
@@ -323,8 +323,13 @@ compare formula, error, and formatting behavior before replacing it.
- Array results are shown within the visible grid. There is no grid expansion for
an array that spills beyond its edges.
- The ribbon exposes font family/size, bold/italic/underline/strikethrough,
- text/fill colors, per-edge borders, horizontal/vertical alignment, and wrapping.
- All cell styles persist, sync independently, copy/fill, and undo. Number formats
+ text/fill colors, per-edge borders, horizontal/vertical alignment, indent, and
+ wrapping. All cell styles persist, sync independently, copy/fill, and undo.
+ Increase and Decrease indent move each selected cell one level from its own,
+ as in Excel. A level is three spaces of the workbook's default font, measured
+ from the right edge of right-aligned cells and the left edge otherwise; an
+ indented cell with automatic alignment aligns left, and indenting centered text
+ makes it left-aligned. Indents round-trip as Excel's alignment `indent`. Number formats
include general, number, USD currency, USD accounting, percent, scientific, date,
time, and plain text, with adjustable decimal places. Accounting follows Excel:
the grid pins `$` to the cell's left edge and the amount to its right, negatives
@@ -400,7 +405,7 @@ Import keeps what Excel calculates and shows:
cached values with a warning.
- Theme and indexed colors with tints, built-in and custom number formats, the
workbook's default font (cells store only differences from it), borders, fills,
- alignment, column widths, row heights, hidden rows/columns/sheets, merges,
+ alignment and indent, column widths, row heights, hidden rows/columns/sheets, merges,
frozen panes, gridlines, tab colors and autofilters.
- 1904-based dates are converted. Unknown error literals, rich text, phonetic
runs, and invalid cell or merge references degrade to text or warnings rather
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 64631b8925..8764616767 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, drags that scroll the grid past its bottom and right edges and back over the sticky headers to reach off-screen cells (including a fill-handle drag down to the last row), persistent row resizing and auto-fit, cross-sheet formula reference picking (including after comparison operators, from a row past the other sheet's end), 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.
+`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, drags that scroll the grid past its bottom and right edges and back over the sticky headers to reach off-screen cells (including a fill-handle drag down to the last row), persistent row resizing and auto-fit, cross-sheet formula reference picking (including after comparison operators, from a row past the other sheet's end), 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, percentage entry through both editors against the real calculation worker, the accounting layout, and indented line items measured from their aligned edge.
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 b2fdfaf6e1..c9c6f07549 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
@@ -242,6 +242,92 @@ test('lays accounting figures across the cell with parentheses, dashes and digit
).toBeLessThanOrEqual(1);
});
+test('indents line items from their aligned edge and keeps nested levels apart', async ({
+ page,
+}) => {
+ const grid = page.getByRole('grid', { name: 'Spreadsheet' });
+ const increase = page.getByRole('button', {
+ name: 'Increase indent',
+ exact: true,
+ });
+ const decrease = page.getByRole('button', {
+ name: 'Decrease indent',
+ exact: true,
+ });
+ await page.locator('[data-address="B2"]').click();
+ await page.locator('[data-address="B3"]').click({ modifiers: ['Shift'] });
+ await choose(page, 'Horizontal alignment', 'Right');
+ await page.locator('[data-address="A2"]').click();
+ await page.locator('[data-address="A3"]').click({ modifiers: ['Shift'] });
+ await increase.click();
+ await expect(grid).toBeFocused();
+ await page.locator('[data-address="A3"]').click();
+ await increase.click();
+ await page.locator('[data-address="B3"]').click();
+ await increase.click();
+
+ const textEdges = () =>
+ page.evaluate(() =>
+ Object.fromEntries(
+ ['A1', 'A2', 'A3', 'B2', 'B3'].map((address) => {
+ const cell = document.querySelector(`[data-address="${address}"]`)!;
+ const text = document
+ .createTreeWalker(cell, NodeFilter.SHOW_TEXT, (node) =>
+ node.textContent?.trim()
+ ? NodeFilter.FILTER_ACCEPT
+ : NodeFilter.FILTER_SKIP
+ )
+ .nextNode()!;
+ const range = document.createRange();
+ range.selectNodeContents(text);
+ const box = range.getBoundingClientRect();
+ const bounds = cell.getBoundingClientRect();
+ return [
+ address,
+ { left: box.left - bounds.left, right: bounds.right - box.right },
+ ];
+ })
+ )
+ );
+ // Each level is three spaces of the 10 pt default font: 10 pixels.
+ let edges = await textEdges();
+ expect(edges.A2.left - edges.A1.left).toBeCloseTo(10, 0);
+ expect(edges.A3.left - edges.A1.left).toBeCloseTo(20, 0);
+ expect(edges.B3.right - edges.B2.right).toBeCloseTo(10, 0);
+ let saved = await page.evaluate(
+ () => window.spreadsheetFixture.snapshot()[0].cells
+ );
+ expect(saved.A2).toEqual({ value: 'Design', indent: 1 });
+ expect(saved.A3).toEqual({ value: 'Engineering', indent: 2 });
+ expect(saved.B3).toEqual({
+ value: '20',
+ horizontalAlign: 'right',
+ indent: 1,
+ });
+ // Editing keeps the text where it is shown: 3 px of cell padding plus the indent.
+ await page.locator('[data-address="A3"]').dblclick();
+ const editor = page.getByRole('textbox', { name: 'Edit A3', exact: true });
+ await expect(editor).toBeFocused();
+ await expect(editor).toHaveCSS('padding-left', '23px');
+ await editor.press('Escape');
+
+ await page.locator('[data-address="A2"]').click();
+ await page.locator('[data-address="A3"]').click({ modifiers: ['Shift'] });
+ await decrease.click();
+ edges = await textEdges();
+ expect(edges.A2.left).toBeCloseTo(edges.A1.left, 0);
+ expect(edges.A3.left - edges.A1.left).toBeCloseTo(10, 0);
+ saved = await page.evaluate(
+ () => window.spreadsheetFixture.snapshot()[0].cells
+ );
+ expect(saved.A2).toEqual({ value: 'Design' });
+ expect(saved.A3).toEqual({ value: 'Engineering', indent: 1 });
+
+ await grid.press('ControlOrMeta+z');
+ edges = await textEdges();
+ expect(edges.A3.left - edges.A1.left).toBeCloseTo(20, 0);
+});
+
test('reads typed partial dates as dates and restyles them from Date formats', async ({
page,
}) => {
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx
index ebcba03a10..4fe1c17d28 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.test.tsx
@@ -1024,6 +1024,33 @@ describe('spreadsheet presentation', () => {
);
});
+ it('indents from the aligned edge by three spaces of the default font per level', () => {
+ const view = renderGrid(
+ {
+ A1: { value: 'Product', indent: 2 },
+ A2: { value: '1200', indent: 1 },
+ A3: { value: '1200', indent: 1, horizontalAlign: 'right' },
+ A4: { value: 'Title', indent: 2, horizontalAlign: 'center' },
+ A5: { value: 'Revenue' },
+ },
+ { zoom: 150 }
+ );
+ const cell = (address: string) =>
+ view.container.querySelector<HTMLElement>(`[data-address="${address}"]`)!;
+ // 10 pt is 13⅓ px; three spaces are 10 px per level, zoomed by 150%.
+ expect(cell('A1').style.paddingLeft).toBe('30px');
+ expect(cell('A1').style.paddingRight).toBe('');
+ // An indented automatic number aligns left, as Excel's Increase Indent does.
+ expect(cell('A2').style.textAlign).toBe('left');
+ expect(cell('A2').style.paddingLeft).toBe('15px');
+ expect(cell('A3').style.textAlign).toBe('right');
+ expect(cell('A3').style.paddingRight).toBe('15px');
+ expect(cell('A3').style.paddingLeft).toBe('');
+ expect(cell('A4').style.paddingLeft).toBe('');
+ expect(cell('A4').style.paddingRight).toBe('');
+ expect(cell('A5').style.paddingLeft).toBe('');
+ });
+
it('hides the gridlines a fill covers and those a neighboring border replaces', () => {
const view = renderGrid({
B2: { value: '', fillColor: '#fff2cc' },
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
index fdd55e525c..87e04587dc 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx
@@ -86,6 +86,8 @@ const ROW_HEADER_WIDTH = 46;
const CELL_PADDING_X = 3;
const CELL_PADDING_Y = 2;
const CELL_LINE_HEIGHT = 1.2;
+/** Excel indents each level by three spaces of the workbook's default font. */
+const INDENT_EMS = 0.75;
const MAX_ROW_HEIGHT = 160;
export function renderedSelectionCell(
@@ -262,6 +264,11 @@ export function SpreadsheetGrid(props: {
const hiddenColumns = createMemo(() => new Set(props.hiddenColumns));
const hiddenRows = createMemo(() => new Set(props.hiddenRows));
const defaultFontSize = () => props.defaultFont?.size ?? 10;
+ /** Unzoomed pixels a cell's indent takes from its content. */
+ const indentWidth = (cell?: SpreadsheetCell) =>
+ cell?.indent && cell.horizontalAlign !== 'center'
+ ? cell.indent * fontPixels(undefined, defaultFontSize()) * INDENT_EMS
+ : 0;
const [fillTarget, setFillTarget] = createSignal<CellSelection>();
// The cell whose list is open; moving the selection closes it.
const [listOpenAt, setListOpenAt] = createSignal<string>();
@@ -419,7 +426,10 @@ export function SpreadsheetGrid(props: {
context.font = `${cell.italic ? 'italic ' : ''}${cell.bold ? 600 : 400} ${pixels}px ${fontFamily(cell)}`;
lines = wrappedLines(
display(address),
- columnWidth(position.column) - CELL_PADDING_X * 2 - borderInset,
+ columnWidth(position.column) -
+ CELL_PADDING_X * 2 -
+ borderInset -
+ indentWidth(cell),
(text) =>
context?.measureText(text).width ?? text.length * pixels * 0.6,
Math.ceil((MAX_ROW_HEIGHT - verticalInset) / lineHeight)
@@ -801,7 +811,10 @@ export function SpreadsheetGrid(props: {
for (const line of text.split('\n'))
measured = Math.max(
measured,
- context.measureText(line).width + CELL_PADDING_X * 2 + 1 / scale()
+ context.measureText(line).width +
+ CELL_PADDING_X * 2 +
+ indentWidth(cell) +
+ 1 / scale()
);
}
props.onResizeColumn?.(
@@ -1662,9 +1675,11 @@ export function SpreadsheetGrid(props: {
: literalNumber(cell()) !== undefined;
const horizontalAlign = () => {
const align = cell()?.horizontalAlign;
+ // Indenting an automatic cell aligns it left, as in Excel.
return align && align !== 'auto'
? align
: numeric() &&
+ !cell()?.indent &&
!(
props.showFormulas &&
cell()?.value.startsWith('=')
@@ -1672,6 +1687,13 @@ export function SpreadsheetGrid(props: {
? 'right'
: 'left';
};
+ const indentPadding = (side: 'left' | 'right') => {
+ const width = indentWidth(cell()) * scale();
+ return width > 0 &&
+ (horizontalAlign() === 'right') === (side === 'right')
+ ? `${width}px`
+ : undefined;
+ };
const pending = () =>
!!props.pendingFormulas &&
!value() &&
@@ -1770,6 +1792,12 @@ export function SpreadsheetGrid(props: {
: 'center',
'padding-block':
'var(--spreadsheet-cell-padding-y)',
+ 'padding-left': indentPadding('left'),
+ 'padding-right': indentPadding('right'),
+ '--spreadsheet-cell-indent-left':
+ indentPadding('left'),
+ '--spreadsheet-cell-indent-right':
+ indentPadding('right'),
'line-height': CELL_LINE_HEIGHT,
}}
class="absolute top-0 bottom-0 flex flex-col border-b border-r border-ink/12 bg-panel text-ink select-none"
@@ -1928,9 +1956,9 @@ export function SpreadsheetGrid(props: {
(isTouchDevice() && !!props.referenceSelection)
}
onSelectionChange={props.onTextSelection}
- // 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 ${
+ // Inherits the cell's fill, font, color and indent;
+ // automatic alignment edits from the left, as in Excel.
+ class={`absolute inset-0 size-full resize-none overflow-hidden bg-inherit pl-[calc(var(--spreadsheet-cell-padding)_+_var(--spreadsheet-cell-indent-left,0px))] pr-[calc(var(--spreadsheet-cell-padding)_+_var(--spreadsheet-cell-indent-right,0px))] py-[var(--spreadsheet-cell-padding-y)] [text-decoration-line:inherit] outline-none select-text ${
cell()?.horizontalAlign === 'center'
? 'text-center'
: cell()?.horizontalAlign === 'right'
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.test.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.test.tsx
index 5400191e07..4b9ceac47d 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.test.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.test.tsx
@@ -82,6 +82,18 @@ describe('spreadsheet toolbar', () => {
expect(view.onCommand).toHaveBeenCalledWith('undo');
});
+ it('indents the selection and returns focus to the sheet', () => {
+ const onRestoreFocus = vi.fn();
+ const view = toolbar({ onRestoreFocus });
+ fireEvent.click(view.getByRole('button', { name: 'Increase indent' }));
+ fireEvent.click(view.getByRole('button', { name: 'Decrease indent' }));
+ expect(view.onCommand.mock.calls).toEqual([
+ ['indent-increase'],
+ ['indent-decrease'],
+ ]);
+ expect(onRestoreFocus).toHaveBeenCalledTimes(2);
+ });
+
it('cancels a font size draft and restores keyboard focus without applying it', () => {
const editor = document.createElement('textarea');
document.body.append(editor);
@@ -309,6 +321,8 @@ describe('spreadsheet toolbar', () => {
'Italic',
'Fill color',
'Number format',
+ 'Increase indent',
+ 'Decrease indent',
'Functions',
'Undo',
'Paste special',
diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.tsx
index e1a94758da..cdf10c519b 100644
--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.tsx
+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetToolbar.tsx
@@ -10,7 +10,9 @@ import Minus from '@phosphor/minus.svg';
import Percent from '@phosphor/percent.svg';
import Plus from '@phosphor/plus.svg';
import TextB from '@phosphor/text-b.svg';
+import TextIndent from '@phosphor/text-indent.svg';
import TextItalic from '@phosphor/text-italic.svg';
+import TextOutdent from '@phosphor/text-outdent.svg';
import TextStrikethrough from '@phosphor/text-strikethrough.svg';
import TextUnderline from '@phosphor/text-underline.svg';
import X from '@phosphor/x.svg';
@@ -249,6 +251,28 @@ export function SpreadsheetToolbar(props: SpreadsheetToolbarProps) {
<Divider />
<BorderMenu {...props} />
<AlignmentMenu {...props} />
+ <ToolbarButton
+ size="icon-sm"
+ label="Decrease indent"
+ disabled={props.readonly}
+ onClick={() => {
+ props.onCommand('indent-decrease');
+ props.onRestoreFocus?.();
+ }}
+ >
+ <TextOutdent class="size-[18px]" />
+ </ToolbarButton>
+ <ToolbarButton
+ size="icon-sm"
+ label="Increase indent"
+ disabled={props.readonly}
+ onClick={() => {
+ props.onCommand('indent-increase');
+ props.onRestoreFocus?.();
+ }}
+ >
+ <TextIndent class="size-[18px]" />
+ </ToolbarButton>
<VerticalAlignmentMenu {...props} />
<ToolbarButton
size="icon-sm"
diff --git a/apps/web/src/features/block-spreadsheet/core/sheet-operations.test.ts b/apps/web/src/features/block-spreadsheet/core/sheet-operations.test.ts
index 942fc5255f..d9ed03315c 100644
--- a/apps/web/src/features/block-spreadsheet/core/sheet-operations.test.ts
+++ b/apps/web/src/features/block-spreadsheet/core/sheet-operations.test.ts
@@ -5,6 +5,7 @@ import {
borderEdits,
csvImportEdits,
findCells,
+ indentEdits,
replaceCellText,
sortedRangeCopies,
trimWhitespaceEdits,
@@ -50,6 +51,56 @@ describe('spreadsheet range operations', () => {
expect(borderEdits(origin, 'none').A1).toEqual(edges.B2);
});
+ it('moves each selected cell one indent level from its own, aligning centered text left', () => {
+ const cells = {
+ A1: { value: 'Revenue' },
+ A2: { value: 'Product', indent: 1 },
+ A3: { value: 'Hardware', indent: 2 },
+ A4: { value: 'Title', horizontalAlign: 'center' as const },
+ A5: { value: 'Deepest', indent: 250 },
+ };
+ const column = {
+ anchor: { row: 0, column: 0 },
+ focus: { row: 4, column: 0 },
+ };
+ expect(indentEdits(cells, column, 1)).toEqual({
+ A1: { indent: 1 },
+ A2: { indent: 2 },
+ A3: { indent: 3 },
+ A4: { indent: 1, horizontalAlign: 'left' },
+ });
+ expect(indentEdits(cells, column, -1)).toEqual({
+ A2: { indent: 0 },
+ A3: { indent: 1 },
+ A5: { indent: 249 },
+ });
+ });
+
+ it('indents empty cells in a selection up to a full column, and only held cells past it', () => {
+ expect(
+ indentEdits(
+ {},
+ { anchor: { row: 0, column: 0 }, focus: { row: 1, column: 0 } },
+ 1
+ )
+ ).toEqual({ A1: { indent: 1 }, A2: { indent: 1 } });
+
+ const cells = {
+ A1: { value: 'Revenue', indent: 1 },
+ Z100000: { value: 'Last' },
+ AA1: { value: 'Outside' },
+ };
+ const sheet = {
+ anchor: { row: 0, column: 0 },
+ focus: { row: 99_999, column: 25 },
+ };
+ expect(indentEdits(cells, sheet, 1)).toEqual({
+ A1: { indent: 2 },
+ Z100000: { indent: 1 },
+ });
+ expect(indentEdits(cells, sheet, -1)).toEqual({ A1: { indent: 0 } });
+ });
+
it('sorts whole selected rows by the anchor column, retaining styles and stable ties', () => {
const cells = {
A1: { value: '=B1*2', italic: true },
diff --git a/apps/web/src/features/block-spreadsheet/core/sheet-operations.ts b/apps/web/src/features/block-spreadsheet/core/sheet-operations.ts
index 3335e38b50..dd94ac86e5 100644
--- a/apps/web/src/features/block-spreadsheet/core/sheet-operations.ts
+++ b/apps/web/src/features/block-spreadsheet/core/sheet-operations.ts
@@ -15,12 +15,58 @@ import {
import {
SPREADSHEET_MAX_CELL_LENGTH,
SPREADSHEET_MAX_COLUMNS,
+ SPREADSHEET_MAX_INDENT,
SPREADSHEET_MAX_ROWS,
type SpreadsheetCellEdits,
type SpreadsheetCells,
} from './spreadsheet-document';
import { CSV_MAX_BYTES } from './workbook-file-types';
+/** Largest selection whose empty cells take an indent too: one full column.
+ * Past it, as with a whole sheet, only the cells the sheet holds move, so an
+ * indent never writes millions of style-only cells. */
+const INDENT_EMPTY_CELLS_LIMIT = SPREADSHEET_MAX_ROWS;
+
+/** Excel's Increase and Decrease Indent: each cell moves one level from its
+ * own, so nested line items keep their depth relative to each other. */
+export function indentEdits(
+ cells: SpreadsheetCells,
+ selection: CellSelection,
+ change: 1 | -1
+): SpreadsheetCellEdits {
+ const { top, bottom, left, right } = selectionBounds(selection);
+ const addresses =
+ (bottom - top + 1) * (right - left + 1) <= INDENT_EMPTY_CELLS_LIMIT
+ ? selectionAddresses(selection)
+ : Object.keys(cells).filter((address) => {
+ const position = positionFromAddress(address);
+ return (
+ !!position &&
+ position.row >= top &&
+ position.row <= bottom &&
+ position.column >= left &&
+ position.column <= right
+ );
+ });
+ const edits: SpreadsheetCellEdits = {};
+ for (const address of addresses) {
+ const cell = cells[address];
+ const current = cell?.indent ?? 0;
+ const indent = Math.max(
+ 0,
+ Math.min(SPREADSHEET_MAX_INDENT, current + change)
+ );
+ if (indent === current) continue;
+ edits[address] = {
+ indent,
+ // Centered text has no indent, so indenting it aligns it left.
+ ...(change > 0 &&
+ cell?.horizontalAlign === 'center' && { horizontalAlign: 'left' }),
+ };
+ }
+ return edits;
+}
+
export function borderEdits(
selection: CellSelection,
border: 'all' | 'outer' | 'none'
diff --git a/apps/web/src/features/block-spreadsheet/core/spreadsheet-document.test.ts b/apps/web/src/features/block-spreadsheet/core/spreadsheet-document.test.ts
index 7765049a28..a4bc2cdf29 100644
--- a/apps/web/src/features/block-spreadsheet/core/spreadsheet-document.test.ts
+++ b/apps/web/src/features/block-spreadsheet/core/spreadsheet-document.test.ts
@@ -152,6 +152,7 @@ describe('spreadsheet document', () => {
textColor: '#123aBc',
fillColor: '#FEDCBA',
horizontalAlign: 'center',
+ indent: 3,
verticalAlign: 'bottom',
wrap: true,
borderTop: true,
diff --git a/apps/web/src/features/block-spreadsheet/core/toolbar-types.ts b/apps/web/src/features/block-spreadsheet/core/toolbar-types.ts
index 7d1f551d61..f568c3a651 100644
--- a/apps/web/src/features/block-spreadsheet/core/toolbar-types.ts
+++ b/apps/web/src/features/block-spreadsheet/core/toolbar-types.ts
@@ -30,6 +30,8 @@ export type SpreadsheetCommand =
| 'border-all'
| 'border-outer'
| 'border-none'
+ | 'indent-decrease'
+ | 'indent-increase'
| 'insert-sum'
| 'insert-average'
| 'insert-count'
diff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-codec.test.ts b/apps/web/src/features/block-spreadsheet/core/xlsx-codec.test.ts
index 941d3350a2..0277edb14f 100644
--- a/apps/web/src/features/block-spreadsheet/core/xlsx-codec.test.ts
+++ b/apps/web/src/features/block-spreadsheet/core/xlsx-codec.test.ts
@@ -199,6 +199,62 @@ describe('Excel workbook files', () => {
});
});
+ it('round trips indented line items through Excel alignment', async () => {
+ const sheet = simpleSheet();
+ sheet.cells = {
+ A1: { value: 'Revenue' },
+ A2: { value: 'Product', indent: 1 },
+ A3: { value: 'Hardware', indent: 2, horizontalAlign: 'left' },
+ B2: { value: '1200', indent: 1, horizontalAlign: 'right' },
+ C2: { value: 'Centered', indent: 3, horizontalAlign: 'center' },
+ };
+ const encoded = await encodeXlsx({ sheets: [sheet] });
+ const external = new ExcelJS.Workbook();
+ await external.xlsx.load(encoded.bytes.slice().buffer);
+ const exported = external.worksheets[0];
+ // Excel indents only left- and right-aligned text.
+ expect(exported.getCell('A2').alignment).toMatchObject({
+ horizontal: 'left',
+ indent: 1,
+ });
+ expect(exported.getCell('A3').alignment).toMatchObject({
+ horizontal: 'left',
+ indent: 2,
+ });
+ expect(exported.getCell('B2').alignment).toMatchObject({
+ horizontal: 'right',
+ indent: 1,
+ });
+ expect(exported.getCell('C2').alignment.indent).toBeUndefined();
+ const decoded = await decodeXlsx(encoded.bytes);
+ expect(decoded.sheets[0].cells).toEqual({
+ A1: { value: 'Revenue' },
+ A2: { value: 'Product', indent: 1, horizontalAlign: 'left' },
+ A3: { value: 'Hardware', indent: 2, horizontalAlign: 'left' },
+ B2: { value: '1200', indent: 1, horizontalAlign: 'right' },
+ C2: { value: 'Centered', horizontalAlign: 'center' },
+ });
+ });
+
+ it('imports indents only where Excel shows them, up to its limit', async () => {
+ const workbook = new ExcelJS.Workbook();
+ const sheet = workbook.addWorksheet('Ledger');
+ for (const [address, alignment] of [
+ ['A1', { horizontal: 'left', indent: 3 }],
+ ['A2', { horizontal: 'right', indent: 400 }],
+ ['A3', { indent: 2 }],
+ ['A4', { horizontal: 'distributed', indent: 2 }],
+ ] as const) {
+ sheet.getCell(address).value = 'Line item';
+ sheet.getCell(address).alignment = alignment;
+ }
+ const cells = (await decodeXlsx(await file(workbook))).sheets[0].cells;
+ expect(cells.A1).toMatchObject({ horizontalAlign: 'left', indent: 3 });
+ expect(cells.A2).toMatchObject({ horizontalAlign: 'right', indent: 250 });
+ expect(cells.A3.indent).toBeUndefined();
+ expect(cells.A4.indent).toBeUndefined();
+ });
+
it('exports date and time formats as their Excel codes and imports them back', async () => {
const sheet = simpleSheet();
sheet.cells = {
diff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-financial.test.ts b/apps/web/src/features/block-spreadsheet/core/xlsx-financial.test.ts
index 5a24488ad2..90b225fb55 100644
--- a/apps/web/src/features/block-spreadsheet/core/xlsx-financial.test.ts
+++ b/apps/web/src/features/block-spreadsheet/core/xlsx-financial.test.ts
@@ -85,6 +85,10 @@ describe('independent financial workbook regression', () => {
expect(values.B23.display).toBe('36:00');
expect(sheets[1].cells.B24.value).toBe('60');
expect(values.B24.display).toBe('02/29/1900');
+ expect(sheets[1].cells.B18).toMatchObject({
+ horizontalAlign: 'right',
+ indent: 1,
+ });
// A value edit and formatting edit must survive export without destroying import metadata.
writeSpreadsheetCells(
reopened,
@@ -115,6 +119,10 @@ describe('independent financial workbook regression', () => {
style: 'double',
color: { argb: 'FF123456' },
});
+ expect(dcf.getCell('B18').alignment).toMatchObject({
+ horizontal: 'right',
+ indent: 1,
+ });
expect(dcf.getCell('A1').isMerged).toBe(true);
expect(dcf.getRow(1).height).toBe(32);
expect(dcf.getRow(6).hidden).toBe(true);
diff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-styles.ts b/apps/web/src/features/block-spreadsheet/core/xlsx-styles.ts
index 956b5597dc..618835503b 100644
--- a/apps/web/src/features/block-spreadsheet/core/xlsx-styles.ts
+++ b/apps/web/src/features/block-spreadsheet/core/xlsx-styles.ts
@@ -20,6 +20,7 @@ export type XlsxCellStyle = {
};
alignment: {
horizontal?: 'left' | 'center' | 'right';
+ indent?: number;
vertical: 'top' | 'center' | 'bottom';
wrapText: boolean;
};
@@ -94,6 +95,25 @@ export function readNumberFormat(format: string): SpreadsheetCellStyle {
return style;
}
+function xlsxAlignment(
+ style: Required<SpreadsheetCellStyle>
+): XlsxCellStyle['alignment'] {
+ // Excel indents only left- and right-aligned text.
+ const horizontal =
+ style.horizontalAlign !== 'auto'
+ ? style.horizontalAlign
+ : style.indent > 0
+ ? 'left'
+ : undefined;
+ return {
+ ...(horizontal && { horizontal }),
+ ...(style.indent > 0 &&
+ horizontal !== 'center' && { indent: style.indent }),
+ vertical: style.verticalAlign === 'middle' ? 'center' : style.verticalAlign,
+ wrapText: style.wrap,
+ };
+}
+
/** Excel style parts for a cell. Font properties the cell does not set come
* from the sheet's imported default font, else Macro's default. */
export function xlsxCellStyle(
@@ -131,14 +151,7 @@ export function xlsxCellStyle(
color: style.textColor.slice(1).toUpperCase(),
}),
},
- alignment: {
- ...(style.horizontalAlign !== 'auto' && {
- horizontal: style.horizontalAlign,
- }),
- vertical:
- style.verticalAlign === 'middle' ? 'center' : style.verticalAlign,
- wrapText: style.wrap,
- },
+ alignment: xlsxAlignment(style),
...(style.fillColor && { fill: style.fillColor.slice(1).toUpperCase() }),
border,
};
diff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-stylesheet.ts b/apps/web/src/features/block-spreadsheet/core/xlsx-stylesheet.ts
index 5e456c6e2d..a9338818b7 100644
--- a/apps/web/src/features/block-spreadsheet/core/xlsx-stylesheet.ts
+++ b/apps/web/src/features/block-spreadsheet/core/xlsx-stylesheet.ts
@@ -3,6 +3,7 @@ import { strFromU8 } from 'fflate';
import { SaxesParser, type SaxesTagNS } from 'saxes';
import {
SPREADSHEET_DEFAULT_STYLE,
+ SPREADSHEET_MAX_INDENT,
type SpreadsheetCellStyle,
} from './spreadsheet-document';
import { readNumberFormat } from './xlsx-styles';
@@ -513,6 +514,14 @@ export function readXlsxStylesheet(
result.horizontalAlign = 'center';
else if (horizontal === 'justify' || horizontal === 'fill')
result.horizontalAlign = 'left';
+ // Excel ignores the indent of other alignments.
+ const indent = Number(alignment.indent ?? 0);
+ if (
+ (horizontal === 'left' || horizontal === 'right') &&
+ Number.isInteger(indent) &&
+ indent > 0
+ )
+ result.indent = Math.min(SPREADSHEET_MAX_INDENT, indent);
const vertical = alignment.vertical;
if (vertical === 'top' || vertical === 'bottom')
result.verticalAlign = vertical;
diff --git a/apps/web/src/features/block-spreadsheet/core/xlsx-writer.ts b/apps/web/src/features/block-spreadsheet/core/xlsx-writer.ts
index 38fa1e8874..9e45d2e0c2 100644
--- a/apps/web/src/features/block-spreadsheet/core/xlsx-writer.ts
+++ b/apps/web/src/features/block-spreadsheet/core/xlsx-writer.ts
@@ -216,6 +216,7 @@ class StyleTable {
const alignment = [
style.alignment.horizontal &&
`horizontal="${style.alignment.horizontal}"`,
+ style.alignment.indent && `indent="${style.alignment.indent}"`,
style.alignment.vertical !== 'bottom' &&
`vertical="${style.alignment.vertical}"`,
style.alignment.wrapText && 'wrapText="1"',
diff --git a/apps/web/src/features/block-spreadsheet/primitives/create-sheet-actions.test.ts b/apps/web/src/features/block-spreadsheet/primitives/create-sheet-actions.test.ts
index cc285f025c..f9a97187ce 100644
--- a/apps/web/src/features/block-spreadsheet/primitives/create-sheet-actions.test.ts
+++ b/apps/web/src/features/block-spreadsheet/primitives/create-sheet-actions.test.ts
@@ -498,6 +498,7 @@ describe('spreadsheet menu actions', () => {
state.actions.setReplacement('replace');
state.actions.replace(true);
state.actions.borders('all');
+ state.actions.indent(1);
state.actions.clearFormatting();
state.actions.trimWhitespace();
state.actions.insertFunction('SUM');
diff --git a/apps/web/src/features/block-spreadsheet/primitives/create-sheet-actions.ts b/apps/web/src/features/block-spreadsheet/primitives/create-sheet-actions.ts
index 07349f1703..b256e646bb 100644
--- a/apps/web/src/features/block-spreadsheet/primitives/create-sheet-actions.ts
+++ b/apps/web/src/features/block-spreadsheet/primitives/create-sheet-actions.ts
@@ -13,6 +13,7 @@ import {
csvImportEdits,
type FindOptions,
findCells,
+ indentEdits,
replaceCellText,
sortedRangeCopies,
trimWhitespaceEdits,
@@ -121,6 +122,11 @@ export function createSheetActions(
if (source.canEdit())
source.setCells(borderEdits(grid.selection(), border));
}
+ function indent(change: 1 | -1) {
+ grid.commit();
+ if (source.canEdit())
+ source.setCells(indentEdits(source.cells(), grid.selection(), change));
+ }
function clearFormatting() {
grid.format(SPREADSHEET_DEFAULT_STYLE);
}
@@ -329,6 +335,7 @@ export function createSheetActions(
pending,
clearNotice: () => setNotice(''),
borders,
+ indent,
clearFormatting,
trimWhitespace,
sort,
diff --git a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
index e18dd40964..56d4d48c22 100644
--- a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
+++ b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx
@@ -590,6 +590,8 @@ export function SpreadsheetEditor(props: {
.with('border-all', () => actions.borders('all'))
.with('border-outer', () => actions.borders('outer'))
.with('border-none', () => actions.borders('none'))
+ .with('indent-decrease', () => actions.indent(-1))
+ .with('indent-increase', () => actions.indent(1))
.with('insert-sum', () => actions.insertFunction('SUM'))
.with('insert-average', () => actions.insertFunction('AVERAGE'))
.with('insert-count', () => actions.insertFunction('COUNT'))
diff --git a/apps/web/src/lib/service-clients/service-cognition/generated/tools/schemas.ts b/apps/web/src/lib/service-clients/service-cognition/generated/tools/schemas.ts
index 0ef951c162..5859e1ee06 100644
--- a/apps/web/src/lib/service-clients/service-cognition/generated/tools/schemas.ts
+++ b/apps/web/src/lib/service-clients/service-cognition/generated/tools/schemas.ts
@@ -454,6 +454,9 @@ export const SpreadsheetResponse = z.any().superRefine((x, ctx) => {
z.null(),
])
.optional(),
+ indent: z
+ .union([z.number().int().gte(0).lte(255), z.null()])
+ .optional(),
verticalAlign: z
.union([
z.any().superRefine((x, ctx) => {
@@ -7977,6 +7980,9 @@ export const EditSpreadsheet = z.object({
z.null(),
])
.optional(),
+ indent: z
+ .union([z.number().int().gte(0).lte(255), z.null()])
+ .optional(),
verticalAlign: z
.union([
z.any().superRefine((x, ctx) => {
diff --git a/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts b/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts
index 8882e30ed3..b23dad6fd1 100644
--- a/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts
+++ b/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts
@@ -5079,6 +5079,11 @@ export interface SpreadsheetStyle {
* Horizontal alignment.
*/
horizontalAlign?: SpreadsheetHorizontalAlign | null;
+ /**
+ * Indent level, 0 through 250, as Excel's Increase Indent: each level is three spaces from the
+ * left edge, or from the right edge of right-aligned cells. Centered cells ignore it.
+ */
+ indent?: number | null;
/**
* Vertical alignment.
*/
diff --git a/crates/documents/src/domain/spreadsheet/models.rs b/crates/documents/src/domain/spreadsheet/models.rs
index 57eafb09a3..6e4dd9d2be 100644
--- a/crates/documents/src/domain/spreadsheet/models.rs
+++ b/crates/documents/src/domain/spreadsheet/models.rs
@@ -164,6 +164,10 @@ pub struct SpreadsheetStyle {
/// Horizontal alignment.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub horizontal_align: Option<SpreadsheetHorizontalAlign>,
+ /// Indent level, 0 through 250, as Excel's Increase Indent: each level is three spaces from the
+ /// left edge, or from the right edge of right-aligned cells. Centered cells ignore it.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub indent: Option<u8>,
/// Vertical alignment.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub vertical_align: Option<SpreadsheetVerticalAlign>,
diff --git a/crates/documents/src/domain/spreadsheet/test.rs b/crates/documents/src/domain/spreadsheet/test.rs
index 0382b62a52..eea7073c84 100644
--- a/crates/documents/src/domain/spreadsheet/test.rs
+++ b/crates/documents/src/domain/spreadsheet/test.rs
@@ -278,3 +278,32 @@ fn imported_styles_round_trip_through_the_ai_contract() {
.is_err()
);
}
+
+#[test]
+fn indented_cells_read_back_with_their_level() {
+ let parsed: SpreadsheetResponse = serde_json::from_value(serde_json::json!({
+ "action":"read", "revision":"r", "warnings":[], "sheets":[],
+ "ranges":[{"sheetId":"sheet1","sheetName":"Sheet1","range":"A2","truncated":false,
+ "cells":[{"address":"A2","source":"Product revenue","type":"text","value":"Product revenue",
+ "display":"Product revenue","style":{"indent":2,"horizontalAlign":"left"}}]}]
+ }))
+ .unwrap();
+ let SpreadsheetResponse::Read { ranges, .. } = parsed else {
+ panic!("expected a read response");
+ };
+ assert_eq!(
+ ranges[0].cells[0]
+ .style
+ .as_ref()
+ .and_then(|style| style.indent),
+ Some(2)
+ );
+ let operation: SpreadsheetOperation = serde_json::from_value(serde_json::json!({
+ "type": "format_cells", "sheetId": "sheet1", "range": "A2:A4", "style": {"indent": 1}
+ }))
+ .unwrap();
+ assert!(matches!(
+ operation,
+ SpreadsheetOperation::FormatCells { style, .. } if style.indent == Some(1)
+ ));
+}
diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.md
index ec325987a0..6ecc9149d2 100644
--- a/docs/agent-guide/documents.md
+++ b/docs/agent-guide/documents.md
@@ -318,9 +318,12 @@ and row additions save collaboratively and can be undone.
The document title and Share button sit above a compact formatting ribbon:
undo/redo, paste, zoom and view options, currency/percent/decimals/number format,
-font and size, text styles, text/fill color, borders, alignment, wrapping,
-functions, format/data actions, and find. Icon controls expose accessible button
-names and tooltips. **Number format → Accounting** shows Excel's accounting layout:
+font and size, text styles, text/fill color, borders, alignment, **Decrease
+indent**/**Increase indent**, wrapping, functions, format/data actions, and find.
+Icon controls expose accessible button names and tooltips. The indent buttons move
+each selected cell one level (three spaces) from its own level, from the cell's
+right edge when it is right-aligned and its left edge otherwise; indenting a
+centered cell aligns it left. **Number format → Accounting** shows Excel's accounting layout:
`$` at the cell's left edge, the amount at the right, negatives in parentheses and
zero as a dash; the cell's accessible name reads like `B2: $(1,234.50)`.
**Paste special** offers **Paste** and **Paste values only**.
diff --git a/packages/spreadsheet/src/ai-formatting.test.ts b/packages/spreadsheet/src/ai-formatting.test.ts
index 70f12ceb3d..c746dd2bb8 100644
--- a/packages/spreadsheet/src/ai-formatting.test.ts
+++ b/packages/spreadsheet/src/ai-formatting.test.ts
@@ -221,4 +221,52 @@ describe('AI formatting preserves spreadsheet values', () => {
doc.free();
}
});
+
+ it('indents line items, reads their levels back and clears them with the formatting', () => {
+ const doc = new LoroDoc();
+ try {
+ doc.getMap('spreadsheetMeta').set('formatVersion', 1);
+ writeSpreadsheetCells(doc, {
+ A1: { value: 'Revenue' },
+ A2: { value: 'Product' },
+ A3: { value: 'Services' },
+ });
+ const edit = (style: { indent: number }) =>
+ prepareSpreadsheetEdit(
+ doc,
+ {
+ action: 'edit',
+ expectedRevision: 'v',
+ operations: [
+ {
+ type: 'format_cells',
+ sheetId: 'sheet1',
+ range: 'A2:A3',
+ style,
+ },
+ ],
+ },
+ calculator
+ );
+ doc.import(edit({ indent: 2 }).update);
+ const result = readSpreadsheetForAi(
+ doc,
+ 'v',
+ { action: 'read', ranges: ['A1:A3'], includeStyles: true },
+ calculator
+ );
+ expect(
+ result.ranges[0].cells.map(({ address, style }) => ({ address, style }))
+ ).toEqual([
+ { address: 'A1', style: {} },
+ { address: 'A2', style: { indent: 2 } },
+ { address: 'A3', style: { indent: 2 } },
+ ]);
+ expect(() => edit({ indent: 251 })).toThrow('Invalid cell formatting');
+ doc.import(edit({ indent: 0 }).update);
+ expect(readSpreadsheetCells(doc).A2).toEqual({ value: 'Product' });
+ } finally {
+ doc.free();
+ }
+ });
});
diff --git a/packages/spreadsheet/src/document-validation.test.ts b/packages/spreadsheet/src/document-validation.test.ts
index 51e985b595..2bd2a8bc1d 100644
--- a/packages/spreadsheet/src/document-validation.test.ts
+++ b/packages/spreadsheet/src/document-validation.test.ts
@@ -29,6 +29,7 @@ describe('spreadsheet document validation outside sync', () => {
['spreadsheetFontNames', 'Calibri'],
['spreadsheetBorderBottomStyles', 'double'],
['spreadsheetBorderBottomColors', '#123456'],
+ ['spreadsheetIndent', 250],
])
doc.getMap(root).set('A1', value);
doc
@@ -66,6 +67,8 @@ describe('spreadsheet document validation outside sync', () => {
['spreadsheetValues', 'A1', 'x'.repeat(10_001)],
['spreadsheetValues', 'bad!sheet!A1', 'bad'],
['spreadsheetFontSize', 'A1', 'large'],
+ ['spreadsheetIndent', 'A1', 251],
+ ['spreadsheetIndent', 'A1', 1.5],
['spreadsheetFormats', 'A1', 'unsupported'],
['spreadsheetSheetNames', 'sheet1', ' Untrimmed '],
['spreadsheetSheetOrder', 'bad!id', 1],
diff --git a/packages/spreadsheet/src/spreadsheet-document.ts b/packages/spreadsheet/src/spreadsheet-document.ts
index cb7fe28aa6..152da60709 100644
--- a/packages/spreadsheet/src/spreadsheet-document.ts
+++ b/packages/spreadsheet/src/spreadsheet-document.ts
@@ -20,6 +20,8 @@ export const MIN_COLUMN_WIDTH = 8;
export const MAX_COLUMN_WIDTH = 640;
export const SPREADSHEET_FORMAT_VERSION = 1;
export const SPREADSHEET_MAX_CELL_LENGTH = 10_000;
+/** Excel's limit for a cell's indent level. */
+export const SPREADSHEET_MAX_INDENT = 250;
export type SpreadsheetFormat =
| 'general'
@@ -42,6 +44,9 @@ export type SpreadsheetCell = {
textColor?: string;
fillColor?: string;
horizontalAlign?: 'auto' | 'left' | 'center' | 'right';
+ /** Excel's indent level: three spaces each, from the right edge of
+ * right-aligned cells and the left edge otherwise. Centered text ignores it. */
+ indent?: number;
verticalAlign?: 'top' | 'middle' | 'bottom';
wrap?: boolean;
borderTop?: boolean;
@@ -76,6 +81,7 @@ export const SPREADSHEET_DEFAULT_STYLE: Required<SpreadsheetCellStyle> = {
textColor: '',
fillColor: '',
horizontalAlign: 'auto',
+ indent: 0,
verticalAlign: 'middle',
wrap: false,
borderTop: false,
@@ -158,6 +164,11 @@ const styleFields: {
value === 'center' ||
value === 'right',
},
+ indent: {
+ map: 'spreadsheetIndent',
+ valid: (value): value is number =>
+ integerStyle(value, 0, SPREADSHEET_MAX_INDENT),
+ },
verticalAlign: {
map: 'spreadsheetVerticalAlign',
valid: (value): value is 'top' | 'middle' | 'bottom' =>
diff --git a/packages/spreadsheet/src/spreadsheet-schema.ts b/packages/spreadsheet/src/spreadsheet-schema.ts
index 9b1b96c900..c180ded46b 100644
--- a/packages/spreadsheet/src/spreadsheet-schema.ts
+++ b/packages/spreadsheet/src/spreadsheet-schema.ts
@@ -100,6 +100,9 @@ export const SPREADSHEET_LORO_SCHEMA = schema({
spreadsheetVerticalAlign: schema.LoroMap(
{} as Record<string, ReturnType<typeof schema.String>>
),
+ spreadsheetIndent: schema.LoroMap(
+ {} as Record<string, ReturnType<typeof schema.Number>>
+ ),
spreadsheetFontSize: schema.LoroMap(
{} as Record<string, ReturnType<typeof schema.Number>>
),
diff --git a/services/ai-editing-worker/src/spreadsheet/runtime.test.ts b/services/ai-editing-worker/src/spreadsheet/runtime.test.ts
index 1a02ee53e6..3d4742019e 100644
--- a/services/ai-editing-worker/src/spreadsheet/runtime.test.ts
+++ b/services/ai-editing-worker/src/spreadsheet/runtime.test.ts
@@ -393,6 +393,30 @@ it('accepts the accounting number format in AI edits', () => {
expect(edit('ledger')).toBe(false);
});
+it('accepts indent levels up to Excel’s limit in AI edits', () => {
+ const edit = (indent: number) =>
+ spreadsheetBodySchema.safeParse({
+ documentId: crypto.randomUUID(),
+ documentToken: 'token',
+ request: {
+ action: 'edit',
+ expectedRevision: 'rev',
+ operations: [
+ {
+ type: 'format_cells',
+ sheetId: 'sheet1',
+ range: 'A2:A9',
+ style: { indent, horizontalAlign: 'left' },
+ },
+ ],
+ },
+ }).success;
+ expect(edit(0)).toBe(true);
+ expect(edit(250)).toBe(true);
+ expect(edit(251)).toBe(false);
+ expect(edit(1.5)).toBe(false);
+});
+
it('accepts dropdown operations and rejects unknown dropdown fields', () => {
const edit = (operation: Record<string, unknown>) =>
spreadsheetBodySchema.safeParse({
diff --git a/services/ai-editing-worker/src/spreadsheet/schema.ts b/services/ai-editing-worker/src/spreadsheet/schema.ts
index cdbecca05f..87c2c2ba2e 100644
--- a/services/ai-editing-worker/src/spreadsheet/schema.ts
+++ b/services/ai-editing-worker/src/spreadsheet/schema.ts
@@ -55,6 +55,7 @@ const style = z
textColor: color.optional(),
fillColor: color.optional(),
horizontalAlign: z.enum(['auto', 'left', 'center', 'right']).optional(),
+ indent: z.number().int().min(0).max(250).optional(),
verticalAlign: z.enum(['top', 'middle', 'bottom']).optional(),
wrap: z.boolean().optional(),
borderTop: z.boolean().optional(),