mirror of
https://github.com/penpot/penpot.git
synced 2026-03-29 15:52:17 +02:00
🐛 Fix text-align before typing and sync attrs with v2 editor
This commit is contained in:
@@ -2030,6 +2030,18 @@ export class SelectionController extends EventTarget {
|
||||
|
||||
this.#textNodeIterator.nextNode();
|
||||
} while (this.#textNodeIterator.currentNode);
|
||||
} else {
|
||||
// Empty paragraph uses a text span with <br> only (no text node). The
|
||||
// selection is then on the line-break element, not a TEXT_NODE, so none
|
||||
// of the branches above run — only setRootStyles applied. Paragraph
|
||||
// styles (e.g. text-align) must still be applied before the user types.
|
||||
const paragraph = this.startParagraph;
|
||||
if (paragraph) {
|
||||
setParagraphStyles(paragraph, newStyles);
|
||||
for (const textSpan of paragraph.children) {
|
||||
setTextSpanStyles(textSpan, newStyles);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.#notifyStyleChange();
|
||||
}
|
||||
|
||||
@@ -1626,6 +1626,23 @@ describe("SelectionController", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("`applyStyles` sets paragraph styles when selection is on <br> (empty paragraph)", () => {
|
||||
const textEditorMock = TextEditorMock.createTextEditorMockWithText("");
|
||||
const root = textEditorMock.root;
|
||||
const selection = document.getSelection();
|
||||
const selectionController = new SelectionController(
|
||||
textEditorMock,
|
||||
selection,
|
||||
);
|
||||
const lineBreak = root.firstChild.firstChild.firstChild;
|
||||
expect(lineBreak.nodeName).toBe("BR");
|
||||
focus(selection, textEditorMock, lineBreak, 0, lineBreak, 0);
|
||||
selectionController.applyStyles({
|
||||
"text-align": "center",
|
||||
});
|
||||
expect(root.firstChild.style.textAlign).toBe("center");
|
||||
});
|
||||
|
||||
test("`selectAll` should select everything", () => {
|
||||
const textEditorMock = TextEditorMock.createTextEditorMockWithParagraphs([
|
||||
createParagraphWith(["Hello, "], {
|
||||
|
||||
Reference in New Issue
Block a user