Skip to content
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

Merged
merged 1 commit into from
Jun 26, 2018

Conversation

eshvedai
Copy link
Collaborator

@eshvedai eshvedai commented Jun 26, 2018

see #38

@eshvedai eshvedai requested review from ahixon and 5id June 26, 2018 00:14
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 &&
Copy link

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++) {
Copy link

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?

Copy link
Collaborator Author

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all done

@eshvedai eshvedai force-pushed the issue-38-findDomRefAtPos branch 2 times, most recently from caad1ea to dc82a0d Compare June 26, 2018 00:46
deco2.className = 'fake-decoration2 ProseMirror-widget';
view.dom.insertBefore(deco2, view.dom.childNodes[1]);

// prepend a fake decoration node 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append*

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@eshvedai eshvedai merged commit a4063aa into master Jun 26, 2018
@eshvedai eshvedai deleted the issue-38-findDomRefAtPos branch November 5, 2018 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants