-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
isTextSelection
always returns false
#2979
Comments
A workaround is to do what import { TextSelection } from 'prosemirror-state'
// ...
const hasSelection = editor && !editor.state.selection.empty;
const isTextSelected = hasSelection && editor.state.selection instanceof TextSelection
console.log(isTextSelected) // Will return true when text is selected So, I'm not sure why the version of |
Just ran into this issue myself. function isTextSelection(value) {
return isObject(value) && value instanceof TextSelection;
}
function isNodeSelection(value) {
return isObject(value) && value instanceof NodeSelection;
}
function isObject(value) {
return (value
&& typeof value === 'object'
&& !Array.isArray(value)
&& !isClass(value));
}
function isClass(value) {
var _a;
if (((_a = value.constructor) === null || _a === void 0 ? void 0 : _a.toString().substring(0, 5)) !== 'class') {
return false;
}
return true;
} It's not clear to me why tiptap's version of function isTextSelection(value) {
return value instanceof TextSelection;
}
function isNodeSelection(value) {
return value instanceof NodeSelection;
} |
It looks like ProseMirror's migration to TypeScript (which happened in That update made its way into Tiptap in #2854, which was first released in |
Fixes ueberdosis#2979. Since the ProseMirror TypeScript upgrade, these have always returned false, since the Selection type tree are all classes now.
PR opened at #3089. |
Great one @kivikakk - looking forward to merge your PR. |
Fixes #2979. Since the ProseMirror TypeScript upgrade, these have always returned false, since the Selection type tree are all classes now.
What’s the bug you are facing?
The method
isTextSelection
always returnfalse
even when object is aTextSelection
Which browser was this experienced in? Are any special extensions installed?
Chrome, Safari
How can we reproduce the bug on our side?
Import
isTextSelection
from@tiptap/core
Provide
editor.state.selection
to itSelect a text and
isTextSelected
will be falseCan you provide a CodeSandbox?
https://codesandbox.io/s/determined-gauss-7tnuji?file=/src/App.js
What did you expect to happen?
isTextSelected
should returntrue
when text is selectedAnything to add? (optional)
I'm using
@tiptap/react v2.0.0-beta.114
Thanks for this awesome library!
Did you update your dependencies?
Are you sponsoring us?
The text was updated successfully, but these errors were encountered: