fix: Header selection in Safari (#10671)

* Move heading actions to decorations

* fix: Selection issues in Safari
This commit is contained in:
Tom Moor authored and GitHub committed 2025-11-21 10:42:09 +01:00
1 parent 9bdf904b7e
commit 0d1c8490b5
2 files changed
+71 -58

No files matched your search

+7 -9
View File
@@ -818,13 +818,6 @@ img.ProseMirror-separator {
}
}
.heading-content {
&::before {
content: "​";
display: inline;
}
}
.${EditorStyleHelper.headingPositionAnchor}, .${EditorStyleHelper.imagePositionAnchor} {
color: ${props.theme.text};
pointer-events: none;
@@ -935,8 +928,9 @@ h6:not(.placeholder)::before {
margin-left: -26px;
flex-direction: row;
display: none;
position: relative;
top: -2px;
position: absolute;
left: 0;
top: calc(.5em - 6px);
width: 26px;
height: 24px;
@@ -1184,6 +1178,10 @@ p {
min-height: 1.6em;
}
.heading-content {
position: relative;
}
.heading-content a,
p a {
color: ${props.theme.text};
+64 -49
View File
@@ -50,55 +50,15 @@ export default class Heading extends Node {
parseDOM: this.options.levels.map((level: number) => ({
tag: `h${level}`,
attrs: { level },
contentElement: (node: HTMLHeadingElement) =>
node.querySelector(".heading-content") || node,
})),
toDOM: (node) => {
let anchor, fold;
if (typeof document !== "undefined") {
anchor = document.createElement("button");
anchor.innerText = "#";
anchor.type = "button";
anchor.className = "heading-anchor";
anchor.addEventListener("click", this.handleCopyLink);
fold = document.createElement("button");
fold.innerText = "";
fold.innerHTML =
'<svg fill="currentColor" width="12" height="24" viewBox="6 0 12 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.23823905,10.6097108 L11.207376,14.4695888 L11.207376,14.4695888 C11.54411,14.907343 12.1719566,14.989236 12.6097108,14.652502 C12.6783439,14.5997073 12.7398293,14.538222 12.792624,14.4695888 L15.761761,10.6097108 L15.761761,10.6097108 C16.0984949,10.1719566 16.0166019,9.54410997 15.5788477,9.20737601 C15.4040391,9.07290785 15.1896811,9 14.969137,9 L9.03086304,9 L9.03086304,9 C8.47857829,9 8.03086304,9.44771525 8.03086304,10 C8.03086304,10.2205442 8.10377089,10.4349022 8.23823905,10.6097108 Z" /></svg>';
fold.type = "button";
fold.className = `heading-fold ${
node.attrs.collapsed ? "collapsed" : ""
}`;
fold.addEventListener("mousedown", (event) =>
this.handleFoldContent(event)
);
}
return [
`h${node.attrs.level + (this.options.offset || 0)}`,
{
dir: "auto",
},
[
"span",
{
contentEditable: "false",
class: `heading-actions ${
node.attrs.collapsed ? "collapsed" : ""
}`,
},
...(anchor ? [anchor, fold] : []),
],
[
"span",
{
class: "heading-content",
},
0,
],
];
},
toDOM: (node) => [
`h${node.attrs.level + (this.options.offset || 0)}`,
{
dir: "auto",
class: "heading-content",
},
0,
],
};
}
@@ -221,6 +181,61 @@ export default class Heading extends Node {
}
get plugins() {
const widgetsPlugin: Plugin = new Plugin({
props: {
decorations: (state) => {
const { doc } = state;
const decorations: Decoration[] = [];
doc.descendants((node, pos) => {
if (node.type.name === "heading") {
// Create anchor button
const anchor = document.createElement("button");
anchor.innerText = "#";
anchor.type = "button";
anchor.className = "heading-anchor";
anchor.addEventListener("mousedown", (event) =>
this.handleCopyLink(event)
);
// Create fold button
const fold = document.createElement("button");
fold.innerText = "";
fold.innerHTML =
'<svg fill="currentColor" width="12" height="24" viewBox="6 0 12 24" xmlns="http://www.w3.org/2000/svg"><path d="M8.23823905,10.6097108 L11.207376,14.4695888 L11.207376,14.4695888 C11.54411,14.907343 12.1719566,14.989236 12.6097108,14.652502 C12.6783439,14.5997073 12.7398293,14.538222 12.792624,14.4695888 L15.761761,10.6097108 L15.761761,10.6097108 C16.0984949,10.1719566 16.0166019,9.54410997 15.5788477,9.20737601 C15.4040391,9.07290785 15.1896811,9 14.969137,9 L9.03086304,9 L9.03086304,9 C8.47857829,9 8.03086304,9.44771525 8.03086304,10 C8.03086304,10.2205442 8.10377089,10.4349022 8.23823905,10.6097108 Z" /></svg>';
fold.type = "button";
fold.className = `heading-fold ${
node.attrs.collapsed ? "collapsed" : ""
}`;
fold.addEventListener("mousedown", (event) =>
this.handleFoldContent(event)
);
// Create container span
const container = document.createElement("span");
container.contentEditable = "false";
container.className = `heading-actions ${
node.attrs.collapsed ? "collapsed" : ""
}`;
container.appendChild(anchor);
container.appendChild(fold);
decorations.push(
Decoration.widget(pos + node.nodeSize - 1, container, {
side: 1,
ignoreSelection: true,
relaxedSide: true,
key: pos.toString(),
})
);
}
});
return DecorationSet.create(doc, decorations);
},
},
});
const foldPlugin: Plugin = new Plugin({
props: {
decorations: (state) => {
@@ -237,7 +252,7 @@ export default class Heading extends Node {
},
});
return [foldPlugin];
return [widgetsPlugin, foldPlugin];
}
inputRules({ type }: { type: NodeType }) {