-
Notifications
You must be signed in to change notification settings - Fork 8
Conversation
This PR addresses #2 |
In https://github.com/ckeditor/ckeditor5-enter/issues/2#issuecomment-386607029 I described some changes that we need to make in this plugin to introduce the soft line break feature. @alexeckermann I'm not sure you're willing to give it a try because the scope grew significantly. If not, @pomek can take it over from here. |
PS. Amazing job, @alexeckermann with all these changes. It's a good start for the rest of the changes. |
That's a very good point. Could |
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.
At the moment, neither Conversion#elementToElement
nor downcast-converters.downcastElementToElement
support this. However changing that might not be difficult. We would have to add something like view.ElementDefinition#type
which could be container|attribute|ui
. Then it would be used in downcast-converters.downcastElementToElement
.
src/softbreak.js
Outdated
*/ | ||
|
||
/** | ||
* @module enter/enter |
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.
Shouldn't it be enter/softbreak
?
@alexeckermann, because your PR was created before the @Reinmar's comment (https://github.com/ckeditor/ckeditor5-enter/issues/2#issuecomment-386607029), I introduced some commits into your PR that makes the whole PR is ready to review and can be merged. I found some bug with the soft enter but I guess it's not related to our work but some mechanism in the engine fails. I will report that in the engine. |
Reported in ckeditor/ckeditor5#1024. |
…that's where we should add the ShiftEnter plugin.
src/shiftentercommand.js
Outdated
// @param {module:engine/model/schema~Schema} schema | ||
// @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection | ||
function isEnabled( schema, selection ) { | ||
if ( selection.rangeCount > 1 ) { |
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.
First of all – there are no tests of ShiftEnterCommand#isEnabled
. There should be. Those tests should explain the logic in this function.
The other things is – why is this command disabled on multiple ranges? I guess you did that on purpose to simplify it and it makes sense to do that, but that requires a comment in the code (because, in the future, we'll need to change that).
src/shiftentercommand.js
Outdated
const endElement = range.end.parent; | ||
|
||
// If the selection contains at least two elements and one of them is the limit element, the soft enter shouldn't be enabled. | ||
if ( ( schema.isLimit( startElement ) || schema.isLimit( endElement ) ) && startElement !== endElement ) { |
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.
This logic is incomplete. Selection can be deeply nested inside limit elements. E.g.:
<limit>
<paragraph>X[Y</paragrap>
</limit>
<paragraph>Z]A</paragraph>
Besides, I'm not sure whether this command must be disabled in this case. It can be because cross-limit selections are (most likely) to be banned at all. But in any case, it's good to explain such decisions.
@pomek, I left you a couple of comments. Other than that, this PR is ready. |
Please add one more test that will verify that the This test is important because it's not that clear that |
Let's finish this PR tomorro, @pomek because it blocks ckeditor/ckeditor5-engine#1430 too. |
@Reinmar, I added missing tests. Could you check it once again? I also fixed an issue related to limit elements as you mentioned. |
tests/shiftentercommand.js
Outdated
@@ -215,4 +215,94 @@ describe( 'ShiftEnterCommand', () => { | |||
} ); | |||
} | |||
} ); | |||
|
|||
describe( '#isEnabled', () => { | |||
test( 'should be disabled if $text cannot be inserted into element', |
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.
Please don't create such test()
functions when not really necessary. And in this case it doesn't change much – from 5LOC to 4LOC ;)
tests/shiftenter.js
Outdated
@@ -26,6 +27,12 @@ describe( 'ShiftEnter feature', () => { | |||
expect( editor.commands.get( 'shiftEnter' ) ).to.be.instanceof( ShiftEnterCommand ); | |||
} ); | |||
|
|||
it( 'registers the EnterObserver', () => { |
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.
To make this test secure and show what it really tests, we should also check that the Enter
plugin is not loaded. Then, it'll be completely clear that ShiftEnter
should do it on purpose.
Done! Thanks guys! |
Thanks to everyone that made this happen! 🍻 |
Feature: Soft Break support in the Enter plugin. Optional usage, enabled by plugin inclusion.
Usage
The user will need to include the
SoftBreakPlugin
, as they would theEnterPlugin
, by importingckeditor5-enter/src/softbreak
.Additional information
event.shiftKey
is truthy.br
tags to the writer view using typical conversion definitions. The model element name is alsobr
.<br/>
but rather an empty<br></br>
. Being anEmptyElement
object it should not be able to receive child nodes.One area where I am not 100% sure of is the schema definition ofbr
. It has been defined as:{ isObject: false, isBlock: false, allowWhere: '$text' }
. Let me know if this is technically correct.{ isObject: true, isBlock: false, allowWhere: '$text' }
based on documentation.