mirror of
https://github.com/penpot/penpot.git
synced 2025-03-05 20:31:20 -05:00
🐛 Fix Unknown node type when replacing whole root node
This commit is contained in:
parent
1cbeafe85c
commit
ad077696b0
1 changed files with 21 additions and 1 deletions
|
@ -30,6 +30,7 @@ import {
|
|||
splitParagraph,
|
||||
mergeParagraphs,
|
||||
fixParagraph,
|
||||
createParagraph,
|
||||
} from "../content/dom/Paragraph.js";
|
||||
import {
|
||||
removeBackward,
|
||||
|
@ -42,7 +43,7 @@ import { getTextNodeLength, getClosestTextNode, isTextNode } from "../content/do
|
|||
import TextNodeIterator from "../content/dom/TextNodeIterator.js";
|
||||
import TextEditor from "../TextEditor.js";
|
||||
import CommandMutations from "../commands/CommandMutations.js";
|
||||
import { setRootStyles } from "../content/dom/Root.js";
|
||||
import { isRoot, setRootStyles } from "../content/dom/Root.js";
|
||||
import { SelectionDirection } from "./SelectionDirection.js";
|
||||
import SafeGuard from "./SafeGuard.js";
|
||||
|
||||
|
@ -946,6 +947,15 @@ export class SelectionController extends EventTarget {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is true if the current focus node is a root.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isRootFocus() {
|
||||
return isRoot(this.focusNode)
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates that we have multiple nodes selected.
|
||||
*
|
||||
|
@ -1201,6 +1211,16 @@ export class SelectionController extends EventTarget {
|
|||
);
|
||||
} else if (this.isLineBreakFocus) {
|
||||
this.focusNode.replaceWith(new Text(newText));
|
||||
} else if (this.isRootFocus) {
|
||||
const newTextNode = new Text(newText);
|
||||
const newInline = createInline(newTextNode, this.#currentStyle);
|
||||
const newParagraph = createParagraph([
|
||||
newInline
|
||||
], this.#currentStyle)
|
||||
this.focusNode.replaceChildren(
|
||||
newParagraph
|
||||
);
|
||||
return this.collapse(newTextNode, newText.length + 1);
|
||||
} else {
|
||||
throw new Error('Unknown node type');
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue