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

Should a styled paragraph maintain its own style when inserting it in a list ? #179

Closed
javifernandez opened this Issue Sep 11, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@javifernandez
Copy link

javifernandez commented Sep 11, 2018

Lets consider the following code:

<div id='test' contenteditable='true'>
    <div id='test0'>
      <span id='test0-1' style="font-style: italic; color: rgb(00, 255, 00)">This text should be green italic</span>
    </div>
    <div id='test1'>
        <ul style="font: 20px/1 monospace; color: blue;">
            <li>List item 1</li>
        </ul>
        <span id='test2' style="font-style: italic; color: rgb(00, 255, 00)">This text should be green italic</span>
    </div>
</div>
<script>
var d = document.getElementById('test');
d.focus();
var sel = document.getSelection();
var range = sel.getRangeAt(0);
d = document.getElementById('test2');
range.selectNode(d)
range.collapse();
document.execCommand('insertUnorderedList');
</script>

As far as I know, when applying the insertOrderedList/insertUnorderedList command, the newly created list item has to be merged with its previous list element sibling. The question is, what's the expected behavior regarding the paragraph's style ? Should we keep it even implying we'll breaking the list element's style ?

What would be the behavior if there was no previous list element sibling and the selected text will become the only list item if the newly created list ? Should we keep the paragraph's style in that case ?

Depending on the answers to the questions above, should we behave differently in those cases ? Why ? IS there any spec/doc describing how to proceed in the different cases where text paragraphs are transformed into list items via the insertOrderedList/insertUnorderedList command ?

@javifernandez

This comment has been minimized.

Copy link
Author

javifernandez commented Sep 11, 2018

As far as I could evaluate, this is the current behavior of some of the main browsers when loading the code above (and also the one without an existing list element):

Create a new listUse an existent list
Chrome 70
Firefox 62
Edge 17
Safari Tech Preview
@johanneswilm

This comment has been minimized.

Copy link
Contributor

johanneswilm commented Sep 28, 2018

AFAIK, there is no spec for this and this seems like extremely messy code to be dealing with. This clearly falls into the domain of JavaScript code cleaning it up which will be highly depending on what kind of editor we are working with, at least the web works is in 2018. Also, we are not actively working on execCommand.

That being said, as long as you are making browsers work more similarly, that will in general make it easier to work with for JavaScript code.

@javifernandez

This comment has been minimized.

Copy link
Author

javifernandez commented Sep 28, 2018

Ok, thanks for the info. I'm working now on changing Chrome's behavior regarding the text's style. If it's eventually accepted, at least it'll improve interoperability. The issues about the order of the elements after the execCommand will remain, though.

@johanneswilm

This comment has been minimized.

Copy link
Contributor

johanneswilm commented Sep 28, 2018

@javifernandez Ok, you are making Chrome more similar to which other browser then?

@javifernandez

This comment has been minimized.

Copy link
Author

javifernandez commented Sep 28, 2018

Chrome will match Firefox exactly for this use case.

@rniwa

This comment has been minimized.

Copy link
Contributor

rniwa commented Sep 29, 2018

FWIW, we're not going to change WebKit's behavior here. The current behavior is required to match the platform behavior we have.

@javifernandez

This comment has been minimized.

Copy link
Author

javifernandez commented Oct 22, 2018

I fixed Chrome's behavior to match Firefox in https://crrev.com/c/1216282 so I think we can close this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.