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

H1 toggle endlessly grows text if in <ol>/<ul> #53

Closed
dvnrsn opened this issue Jul 17, 2019 · 5 comments
Closed

H1 toggle endlessly grows text if in <ol>/<ul> #53

dvnrsn opened this issue Jul 17, 2019 · 5 comments

Comments

@dvnrsn
Copy link

dvnrsn commented Jul 17, 2019

Chrome 75

h1 grows

Given

<ol><li>bla</li></ol>

Invoking formatBlock() and thus performCommandWithValue() with param "h1" results in expected:

<h1><ol><li>bla</li></ol></h1>

On second click, we'll fall (as expected) into

// useFormatBlockHook 'h1' = 'h1'
if (value === document.queryCommandValue('formatBlock')) {
  performCommandWithValue('div')

and on the resulting execution of document.execCommand('formatBlock', 'div') we get a div wrapped by h1:

<h1><div><ol><li>bla</li></ol></div></h1>

This behavior is unexpected to me especially given formatBlock's description: Adds an HTML block-level element around the line containing the current selection, replacing the block element containing the line if one exists.

Another click replaces the div with an h1:

<h1><h1><ol><li>bla</li></ol></h1></h1>

and <h1>s all the way down

Why is <ol> breaking formatBlock behavior? Is there a way to detect if current line is <ol>?

Interestingly, even though <ol> is indeed a block level element, it is not detected by document.queryCommandValue('formatBlock') (I get an empty string).

@dvnrsn dvnrsn changed the title H1 toggle endlessly grows text if in <ol> H1 toggle endlessly grows text if in <ol>/<ul> Jul 17, 2019
@dvnrsn
Copy link
Author

dvnrsn commented Jul 17, 2019

Will this be a situation where we have to resort to browser checks and direct DOM manipulation? I hope not, but here is a PR that works for my chrome https://github.com/CanopyTax/bandicoot/pull/54/files. This is intended strictly for discussion and proof of concept.

@joeldenning
Copy link
Contributor

I'll leave a comment on #54 for this

@dvnrsn
Copy link
Author

dvnrsn commented Jul 18, 2019

Firefox

(Each line is a click to h1 with cursor on <li>)

<li><h1>awef</h1></li>
<li><div>awef</div></li>
<li><div><h1>awef</h1></div></li>
<li><div><h1>awef</h1></div></li>
<li><div><h1>awef</h1></div></li>

(it stops changing)

@dvnrsn
Copy link
Author

dvnrsn commented Jul 18, 2019

Safari appears to mimic Chrome behavior

@dvnrsn
Copy link
Author

dvnrsn commented Sep 3, 2019

wrote note in docs for this

@dvnrsn dvnrsn closed this as completed Sep 3, 2019
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

No branches or pull requests

2 participants