Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

T/884 Mapper: default position mapping algorithms may crash editor #885

Merged
merged 7 commits into from
Mar 24, 2017

Conversation

scofalik
Copy link
Contributor

@scofalik scofalik commented Mar 21, 2017

Suggested merge commit message (convention)

Other: Default conversion.Mapper position mapping algorithms are now added as callbacks with low priority and are fired only if earlier callbacks did not provide a result. Closes ckeditor/ckeditor5#4025.

BREAKING CHANGES: Since default position mapping algorithms are attached with low priority, custom position mapping callbacks added with higher priority won't receive position calculated by default algorithms in data. To execute default position mapping algorithms and use their value, hook custom callback with lower priority.

mapper: this
};

this.fire( 'viewToModelPosition', data );

return data.modelPosition;
return data.modelPosition ? data.modelPosition : this._defaultToModelPosition( viewPosition );
Copy link

@pjasiun pjasiun Mar 22, 2017

Choose a reason for hiding this comment

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

Can't we put this._defaultToModelPosition( viewPosition ) as an viewToModelPosition event listener? Someone may need a mapped position to calculate his version.

Copy link

Choose a reason for hiding this comment

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

In fact I was curious how such custom mapping may look like, how to create custom mapping without the result of the default mapping, and I realised there is no single test for this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't we put this._defaultToModelPosition( viewPosition ) as an viewToModelPosition event listener?

We can, it was like this for some time some time ago.

In fact I was curious how such custom mapping may look like, how to create custom mapping without the result of the default mapping, and I realised there is no single test for this change.

I don't understand what exactly you mean. There are test for adding a custom callback and there are tests for default mapping. What exactly do you need?

Copy link

Choose a reason for hiding this comment

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

We can, it was like this for some time some time ago.

I wanted to say in the ticket that I remember that it was already possible to add the custom listener before the default mapping and I don't know why it's not possible anymore, but I thought it was a dream ;)

Copy link

Choose a reason for hiding this comment

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

There are test for adding a custom callback and there are tests for default mapping. What exactly do you need?

Could you link where are these tests, because I may miss something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to say in the ticket that I remember that it was already possible to add the custom listener before the default mapping and I don't know why it's not possible anymore, but I thought it was a dream ;)

Yes, it was like this for a while but then it got changed. I don't remember the exact reasons, though. I can change it so the default mapping callback is fired with low priority. Not a big deal.

Could you link where are these tests, because I may miss something.

I meant these:
https://github.com/ckeditor/ckeditor5-engine/blob/master/tests/conversion/mapper.js#L209-L223
https://github.com/ckeditor/ckeditor5-engine/blob/master/tests/conversion/mapper.js#L282-L296

I haven't added new tests because, from API point of view, in fact nothing changed, other than the fact that you don't get "default" position in the callback.

Copy link

Choose a reason for hiding this comment

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

I see that there were tests. As I said I was curious how such custom converter may look like if I do not have access to the default mapping. Tests is the place where I look for the sample use-case and I did not find any example how I could use this event.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, you mean something that resembles real case scenario. Well, the problem with such tests is that you need to think of some non-dumb case/feature and then code it. So you either go easy way (like the linked tests) or start re-writing other feature (i.e. List). Maybe it would be better to drop some reference in the event description (to List feature?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW. I just noticed that there's example in event's description.

Copy link

Choose a reason for hiding this comment

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

BTW. I just noticed that there's example in event's description.

I see. That's fine then.

const viewPosition = conversionApi.mapper.toViewPosition( data.sourcePosition );
const viewRange = data.item.is( 'element' ) ?
ViewRange.createOn( viewPosition.nodeAfter ) :
_expandViewPositionOnText( viewPosition, data.item.offsetSize );
Copy link

@pjasiun pjasiun Mar 22, 2017

Choose a reason for hiding this comment

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

What The Freak?!

@scofalik
Copy link
Contributor Author

Fixed.

@pjasiun pjasiun merged commit 5627993 into master Mar 24, 2017
@pjasiun pjasiun deleted the t/884 branch March 24, 2017 09:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mapper: default position mapping algorithms may crash editor.
2 participants