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

Detected contentEditable element. #210

Merged
merged 2 commits into from Sep 16, 2019
Merged

Conversation

Alecyrus
Copy link
Contributor

@Alecyrus Alecyrus commented Sep 15, 2019

I don't get it why you detect contentEditable element.

Description

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

I don't get it why you detect contentEditable element.
if (
elem.tagName === "INPUT" ||
elem.tagName === "TEXTAREA" ||
elem.contentEditable === "true"
Copy link
Owner

Choose a reason for hiding this comment

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

The problem is that the value of contentEditable attribute may be inherit (default value), which means you have to traverse through all the ancestor elements to see if this one is editable.

Copy link
Owner

Choose a reason for hiding this comment

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

A simple but high-cost way to fix it:

while (elem) {
  if (elem.contentEditable === "true") {
     // do something
    break;
  }

  elem = elem.parentElement;
}

Copy link
Owner

Choose a reason for hiding this comment

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

Just got an answer from stack overflow:

- elem.contentEditable === "true"
+ elem.isContentEditable

@Alecyrus can you modify your code like the above snippet?

Copy link
Contributor Author

@Alecyrus Alecyrus left a comment

Choose a reason for hiding this comment

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

Change the rules for detecting ContentEditable elements

Copy link
Owner

@idiotWu idiotWu left a comment

Choose a reason for hiding this comment

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

Thanks!

@idiotWu idiotWu merged commit 7db2a1b into idiotWu:develop Sep 16, 2019
@idiotWu
Copy link
Owner

idiotWu commented Sep 16, 2019

v8.4.1 is out

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

2 participants