Skip to content

Commit 492c306

Browse files
authored
Merge pull request #455 from Harbour-Enterprises/artem-HAR-9431-v1
HAR-9430 - fix paragraph text indentation
2 parents 8fd43ff + c6a7ac0 commit 492c306

5 files changed

Lines changed: 36 additions & 35 deletions

File tree

packages/super-editor/src/core/super-converter/exporter.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function generateParagraphProperties(node) {
167167
const { styleId } = attrs;
168168
if (styleId) pPrElements.push({ name: 'w:pStyle', attributes: { 'w:val': styleId } });
169169

170-
const { spacing, indent, textAlign } = attrs;
170+
const { spacing, indent, textAlign, textIndent } = attrs;
171171
if (spacing) {
172172
const { lineSpaceBefore, lineSpaceAfter, line, lineRule } = spacing;
173173

@@ -185,19 +185,31 @@ function generateParagraphProperties(node) {
185185
};
186186
pPrElements.push(spacingElement);
187187
}
188-
188+
189189
if (indent) {
190190
const { left, right, firstLine } = indent;
191191
const attributes = {};
192192
if (left || left === 0) attributes['w:left'] = pixelsToTwips(left);
193193
if (right || right === 0) attributes['w:right'] = pixelsToTwips(right);
194194
if (firstLine || firstLine === 0) attributes['w:firstLine'] = pixelsToTwips(firstLine);
195195

196+
if (textIndent && !attributes['w:left']) {
197+
attributes['w:left'] = inchesToTwips(textIndent);
198+
}
199+
196200
const indentElement = {
197201
name: 'w:ind',
198202
attributes,
199203
};
200204
pPrElements.push(indentElement);
205+
} else if (textIndent) {
206+
const indentElement = {
207+
name: 'w:ind',
208+
attributes: {
209+
'w:left': inchesToTwips(textIndent),
210+
},
211+
};
212+
pPrElements.push(indentElement);
201213
}
202214

203215
if (textAlign) {

packages/super-editor/src/core/super-converter/v2/importer/markImporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function getFontFamilyValue(attributes, docx) {
167167

168168
function getIndentValue(attributes) {
169169
let value = attributes['w:left'];
170-
if (!value) value = attributes['w:firstLine'];
170+
if (!value) return null;
171171
return `${twipsToInches(value)}in`;
172172
}
173173

packages/super-editor/src/core/super-converter/v2/importer/paragraphNodeImporter.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ export const handleParagraphNode = (params) => {
6464
if (firstLine) schemaNode.attrs['indent'].firstLine = twipsToPixels(firstLine);
6565
}
6666

67-
const textIndentVal = left || firstLine || 0;
68-
schemaNode.attrs['textIndent'] = `${twipsToInches(textIndentVal)}in`;
67+
const textIndentValue = left || 0;
68+
69+
if (textIndentValue) {
70+
schemaNode.attrs['textIndent'] = `${twipsToInches(textIndentValue)}in`;
71+
}
6972
}
7073

7174
const justify = pPr?.elements?.find((el) => el.name === 'w:jc');

packages/super-editor/src/extensions/text-indent/text-indent.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { Extension } from '@core/index.js';
22
import { parseSizeUnit } from '@core/utilities/index.js';
33

4-
/**
5-
* Do we need a unit conversion system?
6-
*
7-
* For reference.
8-
* https://remirror.vercel.app/?path=/story/extensions-nodeformatting--basic
9-
* https://github.com/remirror/remirror/tree/HEAD/packages/remirror__extension-node-formatting
10-
*/
114
export const TextIndent = Extension.create({
125
name: 'textIndent',
136

@@ -32,7 +25,7 @@ export const TextIndent = Extension.create({
3225
renderDOM: (attrs) => {
3326
if (!attrs.textIndent) return {};
3427
let [value, unit] = parseSizeUnit(attrs.textIndent);
35-
if (Number.isNaN(value)) return {};
28+
if (Number.isNaN(value) || !value) return {};
3629
unit = unit ? unit : this.options.defaults.unit;
3730
return { style: `margin-left: ${value}${unit}` };
3831
},

packages/super-editor/src/tests/import/listImporter.test.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ describe('custom nested list tests', () => {
351351
'w:rsidR': '00F20DE4',
352352
'w:rsidRDefault': '00F20DE4',
353353
'w:rsidP': '00F20DE4',
354+
textAlign: 'both',
354355
paragraphProperties: {
355356
type: 'element',
356357
name: 'w:pPr',
@@ -411,8 +412,7 @@ describe('custom nested list tests', () => {
411412
},
412413
},
413414
],
414-
},
415-
textIndent: 'undefinedin',
415+
}
416416
},
417417
marks: [],
418418
},
@@ -428,7 +428,6 @@ describe('custom nested list tests', () => {
428428
textStyle: {
429429
type: 'textStyle',
430430
attrs: {
431-
textIndent: 'undefinedin',
432431
textAlign: 'both',
433432
},
434433
},
@@ -450,6 +449,7 @@ describe('custom nested list tests', () => {
450449
'w:rsidR': '00F20DE4',
451450
'w:rsidRDefault': '007B64C8',
452451
'w:rsidP': '00F20DE4',
452+
textAlign: 'both',
453453
paragraphProperties: {
454454
type: 'element',
455455
name: 'w:pPr',
@@ -489,8 +489,7 @@ describe('custom nested list tests', () => {
489489
},
490490
},
491491
],
492-
},
493-
textIndent: 'undefinedin',
492+
}
494493
},
495494
},
496495
numId: '2',
@@ -507,6 +506,7 @@ describe('custom nested list tests', () => {
507506
'w:rsidR': '00F20DE4',
508507
'w:rsidRDefault': '007B64C8',
509508
'w:rsidP': '00F20DE4',
509+
textAlign: 'both',
510510
paragraphProperties: {
511511
type: 'element',
512512
name: 'w:pPr',
@@ -546,8 +546,7 @@ describe('custom nested list tests', () => {
546546
},
547547
},
548548
],
549-
},
550-
textIndent: 'undefinedin',
549+
}
551550
},
552551
},
553552
},
@@ -564,7 +563,6 @@ describe('custom nested list tests', () => {
564563
textStyle: {
565564
type: 'textStyle',
566565
attrs: {
567-
textIndent: 'undefinedin',
568566
textAlign: 'both',
569567
},
570568
},
@@ -586,6 +584,7 @@ describe('custom nested list tests', () => {
586584
'w:rsidR': '00F20DE4',
587585
'w:rsidRDefault': '007B64C8',
588586
'w:rsidP': '00F20DE4',
587+
textAlign: 'both',
589588
paragraphProperties: {
590589
type: 'element',
591590
name: 'w:pPr',
@@ -625,8 +624,7 @@ describe('custom nested list tests', () => {
625624
},
626625
},
627626
],
628-
},
629-
textIndent: 'undefinedin',
627+
}
630628
},
631629
},
632630
numId: '1',
@@ -689,9 +687,7 @@ describe('custom nested list tests', () => {
689687
},
690688
textStyle: {
691689
type: 'textStyle',
692-
attrs: {
693-
textIndent: 'undefinedin',
694-
},
690+
attrs: {},
695691
},
696692
order: '1',
697693
lvlText: '○',
@@ -761,8 +757,7 @@ describe('custom nested list tests', () => {
761757
},
762758
},
763759
],
764-
},
765-
textIndent: 'undefinedin',
760+
}
766761
},
767762
},
768763
numId: '2',
@@ -829,8 +824,7 @@ describe('custom nested list tests', () => {
829824
},
830825
},
831826
],
832-
},
833-
textIndent: 'undefinedin',
827+
}
834828
},
835829
},
836830
},
@@ -847,7 +841,6 @@ describe('custom nested list tests', () => {
847841
textStyle: {
848842
type: 'textStyle',
849843
attrs: {
850-
textIndent: 'undefinedin',
851844
textAlign: 'both',
852845
},
853846
},
@@ -869,6 +862,7 @@ describe('custom nested list tests', () => {
869862
'w:rsidR': '00F20DE4',
870863
'w:rsidRDefault': '007B64C8',
871864
'w:rsidP': '00F20DE4',
865+
textAlign: 'both',
872866
paragraphProperties: {
873867
type: 'element',
874868
name: 'w:pPr',
@@ -908,8 +902,7 @@ describe('custom nested list tests', () => {
908902
},
909903
},
910904
],
911-
},
912-
textIndent: 'undefinedin',
905+
}
913906
},
914907
},
915908
numId: '1',
@@ -926,6 +919,7 @@ describe('custom nested list tests', () => {
926919
'w:rsidR': '00F20DE4',
927920
'w:rsidRDefault': '007B64C8',
928921
'w:rsidP': '00F20DE4',
922+
textAlign: 'both',
929923
paragraphProperties: {
930924
type: 'element',
931925
name: 'w:pPr',
@@ -965,8 +959,7 @@ describe('custom nested list tests', () => {
965959
},
966960
},
967961
],
968-
},
969-
textIndent: 'undefinedin',
962+
}
970963
},
971964
},
972965
},

0 commit comments

Comments
 (0)