mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🐛 Fix Unknown node type when replacing whole root node
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
|||||||
splitParagraph,
|
splitParagraph,
|
||||||
mergeParagraphs,
|
mergeParagraphs,
|
||||||
fixParagraph,
|
fixParagraph,
|
||||||
|
createParagraph,
|
||||||
} from "../content/dom/Paragraph.js";
|
} from "../content/dom/Paragraph.js";
|
||||||
import {
|
import {
|
||||||
removeBackward,
|
removeBackward,
|
||||||
@@ -42,7 +43,7 @@ import { getTextNodeLength, getClosestTextNode, isTextNode } from "../content/do
|
|||||||
import TextNodeIterator from "../content/dom/TextNodeIterator.js";
|
import TextNodeIterator from "../content/dom/TextNodeIterator.js";
|
||||||
import TextEditor from "../TextEditor.js";
|
import TextEditor from "../TextEditor.js";
|
||||||
import CommandMutations from "../commands/CommandMutations.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 { SelectionDirection } from "./SelectionDirection.js";
|
||||||
import SafeGuard from "./SafeGuard.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.
|
* Indicates that we have multiple nodes selected.
|
||||||
*
|
*
|
||||||
@@ -1201,6 +1211,16 @@ export class SelectionController extends EventTarget {
|
|||||||
);
|
);
|
||||||
} else if (this.isLineBreakFocus) {
|
} else if (this.isLineBreakFocus) {
|
||||||
this.focusNode.replaceWith(new Text(newText));
|
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 {
|
} else {
|
||||||
throw new Error('Unknown node type');
|
throw new Error('Unknown node type');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user