0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-15 17:21:17 -05:00

Merge pull request #5537 from penpot/azazeln28-fix-text-editor-issue-9716

🐛 Fix text editor issue 9716
This commit is contained in:
Andrey Antukh 2025-01-10 10:24:23 +01:00 committed by GitHub
commit 404297f837
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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');
} }