-
Notifications
You must be signed in to change notification settings - Fork 56
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
#38: ignore decoration nodes in findDomRefAtPos #39
Conversation
src/selection.js
Outdated
const child = dom.node.childNodes[i]; | ||
// ignore decoration DOM nodes as ProseMirror ignores it while calculating the offset | ||
if ( | ||
child.nodeType === 1 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
child.nodeType === Node.ELEMENT_NODE
@@ -164,6 +164,17 @@ export const findPositionOfNodeBefore = selection => { | |||
// ``` | |||
export const findDomRefAtPos = (position, domAtPos) => { | |||
const dom = domAtPos(position); | |||
const node = dom.node.childNodes[dom.offset]; | |||
let { offset } = dom; | |||
for (let i = 0, count = dom.node.childNodes.length; i < count; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I have something like:
let { offset, node } = dom;
offset = 1;
node.childNodes = [decoration, decoration, myThing, decoration, decoration];
won't this set the offset to 5
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a test for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all done
caad1ea
to
dc82a0d
Compare
__tests__/selection.js
Outdated
deco2.className = 'fake-decoration2 ProseMirror-widget'; | ||
view.dom.insertBefore(deco2, view.dom.childNodes[1]); | ||
|
||
// prepend a fake decoration node 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
append*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
dc82a0d
to
97d6c80
Compare
see #38