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

List style feature #7861

Merged
merged 39 commits into from
Aug 21, 2020
Merged

List style feature #7861

merged 39 commits into from
Aug 21, 2020

Conversation

pomek
Copy link
Member

@pomek pomek commented Aug 18, 2020

Suggested merge commit message (convention)

Feature (list): Introduced the list styles feature that allows customizing the list's marker of the list item elements. Closes #7801.

Feature (theme-lark): Creates styles for the ListStylesUI plugin (see #7803).

MINOR BREAKING CHANGE (ui): It is now possible to override existing components when adding new ones to the component factory (previously an error was thrown) (see #7803).


Additional information

UI part of the feature was reviewed in #7845.
Docs: #7881 (can be merged after this PR).

@pomek
Copy link
Member Author

pomek commented Aug 19, 2020

Keep in mind that I had some issues with the implementation and the feature could contain some bugs. See #7879.

@pomek pomek marked this pull request as ready for review August 19, 2020 10:44
@pomek
Copy link
Member Author

pomek commented Aug 19, 2020

@ckeditor/qa-team, could you check how critical are issues described in the #7879 issue? I mean, are we able to merge the feature core and fix bugs later?

Comment on lines 219 to 220
editor.execute( parentCommandName );
editor.execute( 'listStyles', { type } );
Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't we wrap the code in the model#change() block in order to have single undo step?

Copy link
Contributor

Choose a reason for hiding this comment

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

It might do the trick AFAIR. So for now might be OK.

The other thing that came to my mind might be that ListSyyle command might also do the parentCommand stuff but as per PR requirements to not-block this PR a wrap will be quicker.

@Reinmar
Copy link
Member

Reinmar commented Aug 19, 2020

One thing to keep in mind here is that the number of edge cases and weird cases and unclear cases will be significant. I'd heavily prioritize stability over correctness.

The other thing is that we're approaching the code freeze, so if the reviewer will stumble upon things that require minor code refactorings, those things should be split to a separate issue, to not block this PR.

@jodator jodator self-assigned this Aug 19, 2020
@Mgsy
Copy link
Member

Mgsy commented Aug 19, 2020

Steps to reproduce

  1. Open list styles manual test.
  2. Select some text in a list item.
  3. Press Ctrl + B

Current result

The editor crashes. It's interesting, as this manual test doesn't have Bold feature.

Error

liststylesediting.js:97 Uncaught TypeError: Cannot read property 'getStyle' of null
    at UpcastDispatcher.dispatcher.on.priority (liststylesediting.js:97)
    at UpcastDispatcher.fire (emittermixin.js:209)
    at UpcastDispatcher._convertItem (upcastdispatcher.js:249)
    at UpcastDispatcher.convert (upcastdispatcher.js:207)
    at Object.callback (datacontroller.js:414)
    at Model._runPendingChanges (model.js:830)
    at Model.change (model.js:175)
    at DataController.toModel (datacontroller.js:413)
    at MutationHandler._handleContainerChildrenMutations (injecttypingmutationshandling.js:109)
    at MutationHandler.handle (injecttypingmutationshandling.js:64)

Can't reproduce it after adding basic styles to the manual tests. Commit: 178ec10.

@FilipTokarski
Copy link
Member

Steps:

  1. Add two styled list items
  2. Apply link on the second one
  3. Select the second one and press Bulleted list on the toolbar

Expected: list changes to unordered

Actual: list changes to unordered only when you choose the specific style

01_list3

@Mgsy
Copy link
Member

Mgsy commented Aug 19, 2020

Steps to reproduce

  1. Create a new list with one nested item ( <ol><li>Test<ol><li>Test 2</li></ol></li></ol> ).
  2. Select all items.
  3. Add styling.

Current result

Only the root item is changed.

@FilipTokarski

This comment has been minimized.

@pomek pomek mentioned this pull request Aug 19, 2020
Copy link
Contributor

@jodator jodator left a comment

Choose a reason for hiding this comment

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

I've saw that there are some issues found so maybe checking if using differ instead of command's events might be relevant.

Abut naming - I've asked that question on the Slack channel as I'm not sure why the plural form and I might be lacking some conversation details.

If I commented something in the UI part - please ignore that. I've forgot instantly that this PR was partially reviewed. I would have some insights for retro though :D 

I'll do the jsdocs/tests re-read later on.


To sum up and to not block:

  1. The feature works, with minor bugs. Which, at least IMHO, we could pass.
  2. The naming might be the most important one before releasing (PITA to do, but should be fairly fast).
  3. crashes to be addressed/checked first.
  4. The event thing (if no time left) should be at least hidden under @Private to have it refactor later as I'm almost 100% sure that we could do the cleanup without it.

packages/ckeditor5-list/src/converters.js Show resolved Hide resolved
packages/ckeditor5-list/src/liststylesediting.js Outdated Show resolved Hide resolved
*
* @event executeCleanup
*/
this.fire( 'executeCleanup', itemsToChange );
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be a new pattern for already existing way of making such cleanups. So I'd say no for this (I might be missing a broader context though).

Ideally, we should make such cleanups using model post-fixer (basically the code that is run in listeners to this event). The itemsToChange can be obtained from editor.model.document.differ.getChanges().

I've used this:

function fixListAfterIndentListCommand( editor ) {
	return ( evt, changedItems ) => {
		let valueToSet;

		const changes = [ ...editor.model.document.differ.getChanges() ];

		for ( const change of changes ) {
			console.log( change.type, change.attributeKey );
		}

		const areSame = changedItems.length === changes.length;
		console.log( `Event ${ changedItems.length } Differ: ${ changes.length } \t => \tsame? ${ areSame }` );

to check if number of events will be the same as the number of elements touched by the commands. From this perspective it looks like you can obtain changed items from differ without adding an event.

ps.: The number of integration tests might be too small for this (judging just by the number of logged entries when running all list tests):

'attribute', 'listIndent'
'Event 1 Differ: 1 	 => 	same? true'
'attribute', 'listIndent'
'attribute', 'listIndent'
'Event 2 Differ: 2 	 => 	same? true'
'attribute', 'listIndent'
'Event 1 Differ: 1 	 => 	same? true'
'attribute', 'listIndent'
'Event 1 Differ: 1 	 => 	same? true'
'attribute', 'listIndent'
'attribute', 'listIndent'
'Event 2 Differ: 2 	 => 	same? true'
'attribute', 'listIndent'
'Event 1 Differ: 1 	 => 	same? true'
'attribute', 'listIndent'
'Event 1 Differ: 1 	 => 	same? true'
'attribute', 'listIndent'
'Event 1 Differ: 1 	 => 	same? true'

Process finished with exit code 0

Maybe one test with deeper nesting and/or bigger tree would be nice. So more than 2 items would change.

Copy link
Member Author

Choose a reason for hiding this comment

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

I marked the event as private and added _ as prefix. (0143084)
But you're right. Post-fixer could be better solution here.

packages/ckeditor5-list/src/liststyles.js Outdated Show resolved Hide resolved
packages/ckeditor5-list/src/liststylescommand.js Outdated Show resolved Hide resolved
packages/ckeditor5-list/src/liststylesediting.js Outdated Show resolved Hide resolved
Comment on lines 219 to 220
editor.execute( parentCommandName );
editor.execute( 'listStyles', { type } );
Copy link
Contributor

Choose a reason for hiding this comment

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

It might do the trick AFAIR. So for now might be OK.

The other thing that came to my mind might be that ListSyyle command might also do the parentCommand stuff but as per PR requirements to not-block this PR a wrap will be quicker.

packages/ckeditor5-ui/src/componentfactory.js Show resolved Hide resolved
execute( options = {} ) {
const model = this.editor.model;
const document = model.document;
const position = findPositionInsideList( document.selection );
Copy link
Contributor

Choose a reason for hiding this comment

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

This might cause "single item changed on range selection" issues.

From top of my head:

  1. Get elements/blocks from selection (to would get all selected list items).
  2. Use selection.getFirst/LastPostion() to get backward/forward siblings.

@jodator
Copy link
Contributor

jodator commented Aug 19, 2020

So I've also found similar issues to the above:

The 2-commands action behaves strangely because the first command (list type) changes all items to the other type and the second command (list style) applies style only to the top-most item.

So I think that my comment regarding how this command should work is valid (take elements from range or just the same ones as list type command does).

ps.: I've might found a bug in the original command as the one item does not change it's type 😮 .

@jodator
Copy link
Contributor

jodator commented Aug 19, 2020

ps.: I've might found a bug in the original command as the one item does not change it's type open_mouth .

It's some kind of downcast rendering glitch. I can't reproduce it on fresh content.

@pomek
Copy link
Member Author

pomek commented Aug 19, 2020

So as for now, we have three main issues:

  1. the command changes the most outdented list and ignores nested ones (assuming that selection has some)
  2. sometimes render fails (refreshing the same scenario helps)
  3. _executeCleanup pattern is not correct but it could be done as a followup after merging the PR.

The naming might be the most important one before releasing (PITA to do, but should be fairly fast).

Now the feature is called ListStyle.

@jodator
Copy link
Contributor

jodator commented Aug 20, 2020

@pomek I've updated an unrelated test name as it was bugging me ;)

@jodator
Copy link
Contributor

jodator commented Aug 20, 2020

@Reinmar if @pomek doesn't need to add anything else here I think that this might go to the testing phase as well.

@pomek
Copy link
Member Author

pomek commented Aug 20, 2020

Let me add a few tests that you mentioned and I'll check whether ListStyleCommand has all use cases covered.

@pomek
Copy link
Member Author

pomek commented Aug 21, 2020

@jodator, I added missing stuff. It's ready for merge.

@jodator jodator merged commit 137dd28 into master Aug 21, 2020
@jodator jodator deleted the i/7801 branch August 21, 2020 07:09
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.

Implement editing part for List Styles feature
6 participants