-
Notifications
You must be signed in to change notification settings - Fork 7
T/61: Improved the typing when the whole content is selected #111
Conversation
… Backspace inside the empty heading element.
src/deletecommand.js
Outdated
* @param {Number} options.sequence A number that describes which sequence of the same event is fired. | ||
* @returns {Boolean} | ||
*/ | ||
_shouldEntireContentBeReplacedWithParagraph( options ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a private method so just pass the sequence as its direct param. We don't need the options object right now here and since it's private we can do whatever we want with the params in the future.
src/deleteobserver.js
Outdated
@@ -55,4 +64,6 @@ export default class DeleteObserver extends Observer { | |||
* @param {module:engine/view/observer/domeventdata~DomEventData} data | |||
* @param {'forward'|'delete'} data.direction The direction in which the deletion should happen. | |||
* @param {'character'|'word'} data.unit The "amount" of content that should be deleted. | |||
* @param {Number} data.sequence A number that describes which sequence of the same event is fired. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A number describing which subsequent delete event it is without the key being released. If it's 2 or more it means that the key was pressed and hold.
The PR is really good. I had a bit different image of where the code should land, but it makes a lot of sense what you did (putting the code to the command). The only thing is... the code duplication with the engine ;| We need to figure out how to reuse the engine because this is quite a lot of code which I don't know where could land otherwise. So, there are at least two options:
The latter has a lot more sense. But it's tricky because we need to find the right pieces of functionality which make sense in some broader context. Like "is entire content selected" and maybe something more. |
src/deletecommand.js
Outdated
* the whole element without removing them. | ||
* | ||
* But, if the user pressed and released the key, we want to replace the entire content with a paragraph if: | ||
* - the entire content is selected, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line before a list in MD. And start items from *
(without additional indentation).
"get limit element" would be another piece of logic to be exposed somewhere else. |
and finally, in order to leave just a paragraph we can do this:
In sucj case, So, these 3 things would allow us removing nearly entire duplication. |
I introduced some fixes but it still requires some work…
Unfortunately, I am not sure whether I'm following a good way. Maybe should I extract requires function from And the one more (and the most important) thing – one of the test does not pass after my changes. Because the paragraph is not allowed in current element, replacing with the paragraps is not executed and at the end we have an empty document with the selection: |
I've just created a ticket for your suggestion – https://github.com/ckeditor/ckeditor5-engine/issues/1041. It's required before merging this PR. |
That ticket mentioned 3 methods, out of which only From this PR I can see that there are, in general, two methods which might be added to the engine – |
Could you refresh this PR so it's ready to review? Now, the build was failing. If there are some issues that you'd like to work on together with me, please describe them. |
I guess only the one thing is adding a new method to |
What do you mean? |
Can we add a new method to Selection class as you wrote a few days ago? The same as we did it for |
Yes, we can. |
This PR requires https://github.com/ckeditor/ckeditor5-engine/issues/1063. |
Your last change made the code even more unclear than it should be. You focused on code itself not on behaviour requirements. What is that common ancestor? Why paragraph can't be inside it? This code is neither correct nor clear. Please, before making any changes, think on WHEN we shouldn't replace the entire limit element content with a paragraph. |
TBH I don't understand what I should do. A part of the code prevents from replacing an empty paragraph with another paragraph. If you want, we can skip it and replace the entire content all the time. |
First of all – the code says something different:
So, this is the first problem – you're saying now something different than you documented. Which is wrong? The code. Second – you still didn't describe it precisely. The precise situation is that we don't want to replace this paragraph with a new paragraph: <limit>
<p>^</p>
</limit> However, we still want to replace this block quote with a new paragraph (the expected result is <limit>
<blockQuote>
<p>^</p>
</blockQuote>
</limit> Will your code do that? I don't think so. Your documentation neither explains what is supposed to happen nor implement it that. Start from writing precisely what you want achieve and the code will follow. |
ATM, the test below even does not work: it( 'leaves an empty paragraph after removing another paragraph from block element', () => {
doc.schema.registerItem( 'section', '$block' );
doc.schema.registerItem( 'blockQuote', '$block' );
doc.schema.limits.add( 'section' );
doc.schema.allow( { name: 'section', inside: '$root' } );
doc.schema.allow( { name: 'blockQuote', inside: 'section' } );
doc.schema.allow( { name: 'paragraph', inside: 'blockQuote' } );
setData( doc,
'<section>' +
'<blockQuote>' +
'<paragraph>[]</paragraph>' +
'</blockQuote>' +
'</section>'
);
editor.execute( 'delete' );
expect( getData( doc, { selection: true } ) ).to.equal(
'<section>' +
'<paragraph>[]</paragraph>' +
'</section>'
);
} ); because of: And this error occurs even when I remove code which I added. |
Hm... I think I experienced this error in the past. Yep... https://github.com/ckeditor/ckeditor5-engine/issues/905 Set data without setting selection and then set it using the normal selection API. Or check how I worked around this in block-quote tests. |
BTW, I don't think you need to pass |
But |
Yes, you're right. Thanks for helping! I forgot to allow appending |
Ok, I guess it's ready for review once again. |
Suggested merge commit message (convention)
Feature: Improved the typing when the whole content is selected. Closes ckeditor/ckeditor5#3065.