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

Soft Break support #54

Merged
merged 24 commits into from
Jun 11, 2018
Merged

Soft Break support #54

merged 24 commits into from
Jun 11, 2018

Conversation

alexeckermann
Copy link
Contributor

@alexeckermann alexeckermann commented Apr 24, 2018

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 the EnterPlugin, by importing ckeditor5-enter/src/softbreak.


Additional information

  • Used the enter plugin as a template to build out the implementation of the soft break feature.
  • The enter plugin will not respond to an enter keypress if event.shiftKey is truthy.
  • The soft break plugin adds br tags to the writer view using typical conversion definitions. The model element name is also br.
  • The view downcaster will create an empty element for the view. However, not a self-closing tag like <br/> but rather an empty <br></br>. Being an EmptyElement object it should not be able to receive child nodes.
  • One area where I am not 100% sure of is the schema definition of br. It has been defined as: { isObject: false, isBlock: false, allowWhere: '$text' }. Let me know if this is technically correct.
    • Changed to: { isObject: true, isBlock: false, allowWhere: '$text' } based on documentation.
  • Apologies for not following the commit message convention initially.

@coveralls
Copy link

coveralls commented Apr 24, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling cec771c on alexeckermann:soft-breaks into 90ce459 on ckeditor:master.

@alexeckermann
Copy link
Contributor Author

This PR addresses #2

@Reinmar Reinmar requested review from oleq and pomek May 4, 2018 12:25
@Reinmar
Copy link
Member

Reinmar commented May 4, 2018

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.

@Reinmar
Copy link
Member

Reinmar commented May 4, 2018

PS. Amazing job, @alexeckermann with all these changes. It's a good start for the rest of the changes.

@Reinmar
Copy link
Member

Reinmar commented May 4, 2018

The view downcaster will create an empty element for the view. However, not a self-closing tag like <br/> but rather an empty <br></br>. Being an EmptyElement object it should not be able to receive child nodes.

That's a very good point. Could elementToElement() support that, @scofalik?

@scofalik scofalik assigned scofalik and unassigned scofalik May 9, 2018
Copy link
Contributor

@scofalik scofalik left a 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
Copy link
Contributor

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?

@pomek
Copy link
Member

pomek commented May 15, 2018

@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.

@pomek
Copy link
Member

pomek commented May 16, 2018

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.

// @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 ) {
Copy link
Member

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).

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 ) {
Copy link
Member

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.

@Reinmar
Copy link
Member

Reinmar commented Jun 4, 2018

@pomek, I left you a couple of comments. Other than that, this PR is ready.

@Reinmar
Copy link
Member

Reinmar commented Jun 7, 2018

Please add one more test that will verify that the ShiftEnter plugin adds the enter observer. You can make it more a unit test by checking directly if the enter observer is available. Or integration test which checks this by firing a keydown event and checking if shiftEnter was executed.

This test is important because it's not that clear that ShiftEnter should be independent from the Enter plugin. If only the latter would register the observer, ShiftEnter would not work when loaded alone.

@Reinmar
Copy link
Member

Reinmar commented Jun 7, 2018

Let's finish this PR tomorro, @pomek because it blocks ckeditor/ckeditor5-engine#1430 too.

@pomek
Copy link
Member

pomek commented Jun 8, 2018

@Reinmar, I added missing tests. Could you check it once again? I also fixed an issue related to limit elements as you mentioned.

@@ -215,4 +215,94 @@ describe( 'ShiftEnterCommand', () => {
} );
}
} );

describe( '#isEnabled', () => {
test( 'should be disabled if $text cannot be inserted into element',
Copy link
Member

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 ;)

@@ -26,6 +27,12 @@ describe( 'ShiftEnter feature', () => {
expect( editor.commands.get( 'shiftEnter' ) ).to.be.instanceof( ShiftEnterCommand );
} );

it( 'registers the EnterObserver', () => {
Copy link
Member

@Reinmar Reinmar Jun 11, 2018

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.

@Reinmar Reinmar merged commit 0181bbf into ckeditor:master Jun 11, 2018
@Reinmar
Copy link
Member

Reinmar commented Jun 11, 2018

Done! Thanks guys!

@alexeckermann
Copy link
Contributor Author

alexeckermann commented Jul 4, 2018

Thanks to everyone that made this happen! 🍻

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.

5 participants