-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add support for shift+enter (soft line breaks) #4542
Comments
Hello, Hope you could implement it soon for inline purpose. I think it could be very useful when ckeditor is applied to Hn, P, SPAN or other editable root elements that don't allowed P inside. Thanks |
Hi. Is there any updates on where soft breaks is on the development timeline, level of importance? |
I think it is very important to point out here realistic use cases for this feature. The ones described by @VincentClair are "theoretically" right but don't smell good, when it comes to quality content creation. For example, do I really want to have line breaks in a header? Or if I really expect line breaks to happen, why will I enable editing a There must be a good semantic-oriented justification that motivates the existence of such feature and the will indicated that it is more important than other features that we have in the backlog. In the other hand, this one fits well as a community contributed feature. |
@fredck thanks for the update. Great to see the care thought going into this. I've been working with CK5 in the past week and I am utterly blown away, it's amazing. Just for some background; the content creation that I am developing for is around literary work — stories, poems, academic material, etc. In these cases authors tend to want to finesse the structure of the content and this tends to include the usage of An idea I have to get around supporting |
@alexeckermann, I clearly understand your use case. It's related to the artistical face of writing and such soft-breaks are indeed important. In fact, the HTML5 specs even predict a proper use for
What we want to avoid, by not providing such feature by default, is the other part of the spec:
But this should be an edge-case. Therefore, bringing such feature to life makes total sense and it could live as a contributed plugin. So here goes the challenge... don't you want to bring this plugin to life? This would be very helpful for us so we can have feedback from the community about the custom development of features. When it comes to the implementation, there is no need to try to figure out crazy solutions for it. I see this as an empty Maybe others would be happy to jump in and help if you are really interested in this. |
We don't have a complete guide about implementing such a feature yet, so I'll try to give here some examples. The code of a soft line break feature will be very similar to the bold's feature (see https://github.com/ckeditor/ckeditor5-basic-styles/blob/master/src/boldengine.js). However, instead of registering an attribute on inline nodes you will be allowing line breaks doc.schema.allow( { name: 'softLineBreak', inside: '$block' } ); And instead of converting to/from model attribute your feature should be converting model element to view element (and back): // Build converter from model to view for data and editing pipelines.
buildModelConverter().for( data.modelToView, editing.modelToView )
.fromElement( 'softLineBreak' )
.toElement( 'br' );
// Build converter from view to model for data pipeline.
buildViewConverter().for( data.viewToModel )
.fromElement( 'br' )
.toElement( 'softLineBreak' ); This should enable loading and rendering Another step is to add a listener to import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element';
// In your plugin's init() method:
this.listenTo( editor.editing.view, 'keydown', ( evt, data ) => {
if ( data.keyCode == keyCodes.enter && data.shiftKey ) {
editor.data.insertContent( new ModelElement( 'softLineBreak' ), editor.document.selection );
}
} ); Hopefully, this is all that is needed. But since we didn't test editor for such cases yet there may be something I miss or something will simply break. |
@fredck @Reinmar Yup, im more than happy to create a plugin and share it. Thanks for the guidance. Will let you know when a public repo is up. Before I commented on this issue I did have a quick attempt at handling |
Interesting. @szymonkups , am I right that this might be because the model to view converter used a wrong view element type? I guess it uses a import EmptyElement from '@ckeditor/ckeditor5-engine/src/view/emptyelement';
// Build converter from model to view for data and editing pipelines.
buildModelConverter().for( data.modelToView, editing.modelToView )
.fromElement( 'softLineBreak' )
.toElement( new EmptyElement( 'br' ) ); |
|
Any progress on this? @alexeckermann Were you ever able to get your plugin working correctly? |
@RedHatter It's still in progress. Unfortunately I have had to jostle around my priorities and this has been pushed back a little bit. However, because I need this in the current project we're working on its going to be done sometime soon. |
I now have a repo public for a soft break plugin 🎉
You can access the prerelease branch here https://github.com/alexeckermann/ckeditor5-soft-break/tree/prerelease
Update: Found the problems with the test failing. Was a misunderstanding of the conversion process, based upon copying existing plugins but lacking the nuanced understanding. |
The lack of soft line-break feature badly affects how pasting plain-text works: #766. |
Just adding a vote for how important this is for those of us that want to offer CKEditor 5 in our CMS |
@alexeckermann already proposed a PR in ckeditor/ckeditor5-enter#54, but there are a couple of things which we need to consider here:
|
Another thing to consider – what should happen if soft break is not loaded (see e.g. ckeditor/ckeditor5-block-quote#23 (comment)). |
IMHO |
Initially I thought that we need to name 3 plugins –
WDYT? |
👍 It allows avoiding the BC with the |
Just a thought, how about using Reasoning: "soft return" is semantically closer to classic typesetting, while "Enter" and "line break" feel more connected with using and abusing HTML. Using "soft return" instead could maybe, hopefully hint to some users what the intended purpose of this feature is about. |
The pair At the same time, This means that we can rule out pairs like:
So, I've got two options:
You can vote with the ❤️ / 🎉 reactions ;) |
Any updates? @Reinmar |
The PR is mostly ready, but we'll need to iron out a couple of bugs before enabling it by default in all builds. |
@Reinmar when will you create a new npm build that contain the shift+enter? |
Within 2-3 weeks. We're polishing the upcoming release now. If you want to use it earlier, you should be able to do that quite safely from the development version of CKEditor 5. |
Sounds great! Would this shift + enter feature also work inside "code" elements, aka < code >? |
You will be able to do this: But the output is this: "<p><i>This</i> <s>is</s></p><p><code>dzdfsdn</code><br><code>sdfsdfsdf</code><br><code>Sdfsdfsdf</code><br><code>sdfsdfsdf</code><br><code>sdfsdf</code></p><p>sdfsdfdsf<br> <strong>editor</strong> <u>instance</u>.</p>" So I guess that what you want are code blocks and this is a separate feature (which is not yet available): #436 |
how can i make the enter button behave in same way as Shift+enter (soft Break). I dont want line breaks, (on how enter key is working) but want it a soft break. |
We're not going to implement this in #4541 as it's not needed currently and we don't have line break support planned.
The text was updated successfully, but these errors were encountered: