-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ProseMirror view's "separator hack".
Safari and Chrome both have cursor drawing/selection bugs that prevent users from making selections after non-contenteditable inline nodes in some situations. To work around this, in these browsers, we add an empty image element between the trailing non- contenteditable node and the "trailing hack", which allows users to place cursors there.
- Loading branch information
1 parent
24c43c9
commit db1e891
Showing
6 changed files
with
62 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 17 additions & 17 deletions
34
docs/assets/index-0b42cd6e.js → docs/assets/index-7c1043a3.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React, { useContext, useLayoutEffect, useRef, useState } from "react"; | ||
|
||
import { browser } from "../browser.js"; | ||
import { ChildDescriptorsContext } from "../contexts/ChildDescriptorsContext.js"; | ||
import { TrailingHackViewDesc } from "../viewdesc.js"; | ||
|
||
export function SeparatorHackView() { | ||
const siblingDescriptors = useContext(ChildDescriptorsContext); | ||
const ref = useRef<HTMLImageElement | null>(null); | ||
const [shouldRender, setShouldRender] = useState(false); | ||
|
||
// There's no risk of an infinite loop here, because | ||
// we call setShouldRender conditionally | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
useLayoutEffect(() => { | ||
const lastSibling = siblingDescriptors[siblingDescriptors.length - 1]; | ||
if ( | ||
(browser.safari || browser.chrome) && | ||
(lastSibling?.dom as HTMLElement)?.contentEditable == "false" | ||
) { | ||
setShouldRender(true); | ||
return; | ||
} | ||
|
||
if (!ref.current) return; | ||
|
||
const desc = new TrailingHackViewDesc(undefined, [], ref.current, null); | ||
siblingDescriptors.push(desc); | ||
}); | ||
|
||
return shouldRender ? ( | ||
<img ref={ref} className="ProseMirror-separator" /> | ||
) : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters