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

Inconsistent "upcast writing" #4423

Closed
Reinmar opened this issue Sep 16, 2018 · 7 comments · Fixed by ckeditor/ckeditor5-engine#1579
Closed

Inconsistent "upcast writing" #4423

Reinmar opened this issue Sep 16, 2018 · 7 comments · Fixed by ckeditor/ckeditor5-engine#1579
Assignees
Milestone

Comments

@Reinmar
Copy link
Member

Reinmar commented Sep 16, 2018

We've just introduced UpcastWriter and when I've stumbled upon this piece of code (in the documentation) I thought that something's wrong:

editor.plugins.get( 'Clipboard' ).on( 'inputTransformation', ( evt, data ) => {
	if ( data.content.childCount == 1 && isUrlText( data.content.getChild( 0 ) ) ) {
		const linkUrl = data.content.getChild( 0 ).data;

		data.content = new ViewDocumentFragment( [
			ViewElement(
				'a',
				{ href: linkUrl },
				[ new ViewText( linkUrl ) ]
			)
		] );
	}
} );

Why aren't we using UpcastWriter here? If, instead of creating a fresh new document fragment, we'd like to modify the one in data.content, we'd need to use the upcast writer. So I actually thought that this piece of code is wrong... and it is – constructors of these node classes are protected so we can't use them like this. But they are not exposed in UpcastWriter.

Also, View#change() doesn't return the return value of its callback just like Model#change() does which would be highly inconvenient.

@Reinmar
Copy link
Member Author

Reinmar commented Sep 16, 2018

cc @pjasiun @f1ames

@f1ames
Copy link
Contributor

f1ames commented Sep 17, 2018

Why aren't we using UpcastWriter here?

Probably because UpcastWriter was introduced after the above code was created and no one took time to refactor it yet.

constructors of these node classes are protected so we can't use them like this. But they are not exposed in UpcastWriter.

That's the second issue that UpcastWriter don't expose this, so probably it should be added if needed.


We already have one task to utilize UpcastWriter in DOMConverter (https://github.com/ckeditor/ckeditor5-engine/issues/1520), but yes, there are more places in the code where it can be used.

@pjasiun
Copy link

pjasiun commented Sep 17, 2018

Agree that upcast writer should be used there. We can even create an instance in the clipboard plugin and put next to content in the event, so one should import nothing and should not need to think which writer should be used.

Also, View#change() doesn't return the return value of its callback just like Model#change() does which would be highly inconvenient.

This is a good idea too. However, we need to ensure that it is possible. It might be impossible if the view#change block would be executed asynchronously in some cases. But AFAIR all change blocks are now executed synchronously, so it should be possible.

@Reinmar
Copy link
Member Author

Reinmar commented Sep 17, 2018

This is a good idea too. However, we need to ensure that it is possible. It might be impossible if the view#change block would be executed asynchronously in some cases. But AFAIR all change blocks are now executed synchronously, so it should be possible.

AFAICS there should be no problem. Cool.

Which create*() methods are we going to need? Text, element (no subclasses), docfrag? Something more?

@pjasiun
Copy link

pjasiun commented Sep 17, 2018

Yep, we should introduce createDocumentFragment, createElement and createText and is should be enough.

BTW, there is no createDocumentFragment in the DowncastWriter, but I think we should not introduce it as long as we do not have a case for it. I am not sure if DocumentFragment makes much sense in downcast.

@f1ames
Copy link
Contributor

f1ames commented Sep 17, 2018

we should introduce createDocumentFragment, createElement and createText

So this issue is for introducing those 3 above methods to UpcastWriter? (and eventually correcting the clipboard docs).

What about:

View#change() doesn't return the return value of its callback just like Model#change() does...

Do we know that this change is needed? Should it be also covered here or in a separate issue?

@Reinmar
Copy link
Member Author

Reinmar commented Sep 17, 2018 via email

Reinmar referenced this issue in ckeditor/ckeditor5-engine Nov 8, 2018
Feature: Introduced `createDocumentFragment()`, `createElement()` and `createText()` methods in `UpcastWriter`. Additionally, the `View.change()` method now returns the return value of its callback. Closes #1549.
@mlewand mlewand transferred this issue from ckeditor/ckeditor5-engine Oct 9, 2019
@mlewand mlewand added this to the iteration 21 milestone Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants