Skip to content

Commit c0a4953

Browse files
tiagocmendesCopilot
andcommitted
fix: cap text indentation at 6.5 inches (9360 points)
Add maxIndentPoints constant and enforce limit in calculateNewIndentation to prevent excessive paragraph indentation values. Add test coverage for maximum indent behavior. Co-authored-by: Copilot <copilot@github.com>
1 parent 0cc2446 commit c0a4953

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

packages/super-editor/src/editors/v1/core/commands/textIndent.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getResolvedParagraphProperties } from '@extensions/paragraph/resolvedPr
22
import { ptToTwips } from '@converter/helpers';
33

44
const defaultIncrementPoints = 36;
5+
const maxIndentPoints = 9360; // 6.5 inches
56

67
/**
78
* Increase text indentation
@@ -64,6 +65,10 @@ function calculateNewIndentation(node, delta) {
6465
left += increment;
6566
}
6667

68+
if (left > maxIndentPoints) {
69+
left = maxIndentPoints;
70+
}
71+
6772
if (left <= 0) {
6873
left = null;
6974
}

packages/super-editor/src/editors/v1/core/commands/textIndent.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,16 @@ describe('text indent commands', () => {
9090
const finalNode = afterUnset.doc.firstChild;
9191
expect(finalNode.attrs.paragraphProperties.indent).toBeUndefined();
9292
});
93+
94+
it('increaseTextIndent caps at maximum indent (9360 points)', () => {
95+
const nearMaxIndent = 9000;
96+
const state = createState({ paragraphProperties: { indent: { left: nearMaxIndent } } });
97+
getResolvedParagraphProperties.mockReturnValueOnce({ indent: { left: nearMaxIndent } });
98+
99+
const { dispatched, nextState } = runCommand(increaseTextIndent(), state);
100+
101+
expect(dispatched).toBe(true);
102+
const updated = nextState.doc.firstChild;
103+
expect(updated.attrs.paragraphProperties.indent.left).toBe(9360);
104+
});
93105
});

0 commit comments

Comments
 (0)