-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
selection.set does not always open keyboard #2753
Comments
As pointed out in #2772,
This seems to be throwing off https://github.com/cybersemics/em/blob/650c3d2e38e109ec4e6b3f0c9a2b4e73ece43789/src/device/asyncFocus.ts. |
Changing the asyncFocus short circuit condition is possibly part of the solution: diff --git a/src/device/asyncFocus.ts b/src/device/asyncFocus.ts
index 77873951a5..c49e1acbba 100644
--- a/src/device/asyncFocus.ts
+++ b/src/device/asyncFocus.ts
@@ -32,8 +32,8 @@ export const AsyncFocus: () => () => void = () => {
document.body.prepend(hiddenInput)
return () => {
- // do not set the selection if it is already on a text node
- if (!selection.isText()) {
+ // do not set the selection if it is already on a contenteditable
+ if (!selection.isContentEditable()) {
hiddenInput.disabled = false
hiddenInput.focus()
// the hidden input should not be a valid focus target unless this function was invoked
diff --git a/src/device/selection.ts b/src/device/selection.ts
index af42d834b6..047afe1beb 100644
--- a/src/device/selection.ts
+++ b/src/device/selection.ts
@@ -66,6 +66,12 @@ const isEditable = (node?: Node | null) => {
)
}
+/** Returns true if the selection is on a contenteditable, either on the TEXT_NODE or ELEMENT_NODE. */
+export const isContentEditable = (node?: Node | null) => {
+ const focusNode = window.getSelection()?.focusNode as HTMLElement | undefined
+ return focusNode?.isContentEditable
+}
+
/** Returns true if the selection is on a thought. */
// We should see if it is possible to just use state.editing and selection.isActive()
export const isThought = (): boolean => {
It's possible that selection.set() has a bug, too. |
The goal of this issue is to:
selection.set
and whyfocus()
is needed (if possible).focus()
call intoselection.set
.focus()
fromuseEditMode
to restore the invariant that all selection behavior occurs via theselection
module.Originally posted by @ethan-james in #2752 (comment)
Related: #2770 #2772
The text was updated successfully, but these errors were encountered: