-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Support for shift + enter #252
Comments
This is a pretty technically costly feature to add to Quill so there'd have to be a large need from the community for it to become a priority. |
Thanks for all of your work on quill.js! I'm in full support of this and hope it can be prioritized. Inserting Is there any current workaround to get the functionality I want? I've tried every hack I could think of to no avail. |
👍 |
Just wondering if there is anymore progress on this? In my editor I'm using the divs as a paragraph so having shift+editor would work great for newlines. |
This is not currently being worked on as it still lacks a compelling real world use case. From a user of an editor / word processor perspective, it's incredibly confusing to have two ways to have newlines, especially when one looks like two ( |
So there is no way for the user to enter a newline if |
A user inserts a newline by hitting enter. If the user hits enter again (leaving the new line blank), they have just created what most readers would consider a new paragraph. |
But only if Just thought I'll let you know my use case for it. |
+1 |
a very useful feature! |
+1 |
👍 We're building an internal document editor which should act similar to Word. This doesn't :( |
@jbrooksuk It doesn't claim to act similar to word. Though, the next update and inclusion of Parchment may provide you with an experience closer to what you're hoping for. |
I know that :) |
Using shift + enter in a document and bolding text across the two divs created by shift + enter causes the selected text to "jump" or simply doesn't bold the text. Is this a known bug in Quill? Removing the linebreak allows the user to unbold the text. Console output:
|
@cydrobolt I'm assuming you've made some modification to add shift+enter? On the quilljs.com editor shift+enter is the same as enter but in either case bolding across the line does not error. |
@jhchen : I can give you a real world use case. We are writing novels. When we are finished, we have to export the text somehow, so finally a designer can work on this and at least we get a book. . In the designers software, paragraphs will be formatted like for example
to make reading easier. We are editing our whole books in one document( more then 400 pages when printed). But unfortunatly everything is a new paragraph. By the way, I hoped to get this result with
and define a keybord binding like: (here for Ctrl-Return)
but can't get any result. |
This is an essential feature of any text editor, whether the output is html or books; there is a clear difference between paragraphs and line breaks, and a text editor not supporting both is severely limiting proper content handling. I'd love to use Quill over other editors, but this is a deal breaker for us. |
@tdolsen : as well as for us. but a found a nice workaround and with this we can live quite good: javascript:
then inside your keyboard handlers:
and finally css:
this causes that shift-enter inserts a new line which is a <p< in quill, but it gets a class linebreak. the css causes, that normal paragraphs appear with a line indent and a top margin, p.linebreak not. when exporting quills content to a dektop wordprocessor, just handle the linebreak attribute as a normal linefeed and process all others as normal paragraphs. hope this helps |
@robert-boulanger: Very much. That should be a workable solution, until native support is added. Thanks! |
@tdolsen : be welcome ;) |
+1 for this feature |
We're looking at moving from Trix to Quill for an (e)book editor we're building, as its more stable, and more flexible with regards to attaching random code in the document. But both Trix and Quill suffer for not handling paragraphs/line breaks in this (correct?!) manner. But +1 for adding this behaviour to Quill to make it less susceptible to changes/breakage. Many users who are used to professional writing tools are familiar with this UX pattern. |
If I understand correct from the documentations, paragraphs are used to mimic linebreaks and linebreaks are rendered as paragraphs. If I really understand it correct and this is by design then I believe there's a fundamental problem with the domain definition... A document does not consist of lines and line-breaks, it consists of paragraphs (and headings)... Inside the paragraphs you might want to "break" the line and that's where linebreaks comes into play. ...at least for hypertext documents. For plain text the simplest way to mimic a paragraph is to use double line-breaks since you're limited to ASCII characters. But that was the case before hypertext was invented!? In the current case you have no control on how paragraphs are displayed, you cannot adjust spacing between elements or you cannot indent the text as @robert-boulanger stated. Or as in my case you have to find a hack to get rid of these empty paragraphs after headings :\ If you still think that this is the correct behaviour, it would be nice to have some notice on the quickstart documentation describing this behaviour to save some hours of the programmers maybe... |
Jason, Here you have excellent text editor and I hope you will continue your great work on this. Community that is build around Quill is also great, you have really high quality inputs. Difference between If you do not accept that journalist, writers, bloggers use paragraphs that can contain brake-line your are wrong. If user hits enter twice is not solution, as code generated is simply wrong -> there are now three paragraphs instead one. Than think on programmers perspective, Hope you decide to add this high valuable feature. |
👍 Using this on a site which allows the users to enter poems, the lack of soft enter is crucial for such cases. |
Google docs inserts a |
Maybe this could done using custom let Parchment = Quill.import('parchment');
let Break = Quill.import('blots/break');
let Embed = Quill.import('blots/embed');
Break.prototype.insertInto = function(parent, ref) {
Embed.prototype.insertInto.call(this, parent, ref)
};
Break.prototype.length= function() {
return 1;
}
Break.prototype.value= function() {
return '\n';
}
Quill.register(Break) and bindings like this handleEnter: {
key: 13,
handler: function (range, context) {
if (range.length > 0) {
this.quill.scroll.deleteAt(range.index, range.length); // So we do not trigger text-change
}
let lineFormats = Object.keys(context.format).reduce(function(lineFormats, format) {
if (Parchment.query(format, Parchment.Scope.BLOCK) && !Array.isArray(context.format[format])) {
lineFormats[format] = context.format[format];
}
return lineFormats;
}, {});
var previousChar = this.quill.getText(range.index - 1, 1);
// Earlier scroll.deleteAt might have messed up our selection,
// so insertText's built in selection preservation is not reliable
this.quill.insertText(range.index, '\n', lineFormats, Quill.sources.USER);
if (previousChar == '' || previousChar == '\n') {
this.quill.setSelection(range.index + 2, Quill.sources.SILENT);
} else {
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
}
this.quill.selection.scrollIntoView();
Object.keys(context.format).forEach((name) => {
if (lineFormats[name] != null) return;
if (Array.isArray(context.format[name])) return;
if (name === 'link') return;
this.quill.format(name, context.format[name], Quill.sources.USER);
});
}
},
linebreak: {
key: 13,
shiftKey: true,
handler: function (range, context) {
var nextChar = this.quill.getText(range.index + 1, 1)
var ee = this.quill.insertEmbed(range.index, 'break', true, 'user');
if (nextChar.length == 0) {
// second line break inserts only at the end of parent element
var ee = this.quill.insertEmbed(range.index, 'break', true, 'user');
}
this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
}
} |
@farnabaz Thank you very much for sharing this. I'm now working on it and fixing some issues that occur when quill first loads the HTML (as I'm saving it in the DB). I'll post my findings here once I get this working properly! |
I got it working great. The code @farnabaz posted worked great, just had some minor tweaks I had to do specific to my use case. For me, using Quill with React, I was before injecting the HTML into quill's container. But now that we have our fancy linebreaks, the solution was to instead send the HTML via the dangerouslyPasteHTML method of the clipboard module. With that, you can then write a little matcher for our new And this concludes dozens and dozens of hours for me of doing RegExp work that can now be replaced by a handful of lines of code. Thank you very much once again farnabaz, you saved my week! 👍 🍺 |
@rpmonteiro I'm glad to hear it 👍 |
Just FYI, I really need this to format poems correctly, where there are often line breaks that are not paragraph breaks. |
hy @ollyfg |
@nhunzaker and I had a couple issues with the above codepen solutions:
We've forked and updated the codepen with our solution here: http://codepen.io/mackermedia/pen/gmNwZP Notable additions:
|
We're using Quill as an email composer, trying to replicate Gmail as much as possible. Gmail's default line break is the single Is it possible to optionally convert Quill's |
@jhchen, what @RobAley said. All word processors support shift+Enter for BR:s, but if your copy of Word doesn't have margins on its P:s configured, you won't see it. If you were to configure margins on your Word document, you'd see what you see on the web. In MS Word terms, it's called a soft carriage return (or just Soft Return), see here: https://www.computerhope.com/jargon/s/softretu.htm |
I've sure noticed i've wrote a duplicate - issue #1511. |
@farnabaz, your code works well but I have an issue when setting content to the editor. I use this code to set the editor content : but the Is it the right way to set HTML content to Quill? |
No it is not :) See https://quilljs.com/docs/modules/clipboard/#dangerouslypastehtml |
@mackermedia small fix is to change length that SmartBreak returns from a 1 to 0 because otherwise you can't escape a list format and will fix cursor position when you press enter on a empty line |
tried the codepen solutions here, which are not bad but all seem to have issues with saving and the delta format, I always get corruption would be nice to have official support for this. |
The best workaround I've found so far is to use a simple custom Style Attributor to set padding-top to 0px for shift-enter lines. Then you use css to set padding-top to whatever spacing you want for not shift-enter lines. Obviously this will not have all of the exact same functionality as br tags but for the vast majority of use cases it will be the same and it doesn't cause errors or weird Enter behavior. I've made a simple CodePen example to demonstrate this. Note: you have to use padding NOT MARGINS as margins can add whitespace due to issue 1157. |
@jhchen this thing is as necessary as having P and BR tags both in HTML. You can't make a good HTML page with only one. I think it should be in one of the priority list. All of the solutions above aren't working fine when you save delta and retrieve because it creates double spacing every where. MS-Word also have this functionality |
are there any plans to add this functionality to quill.js? or are there any plans that make this extension doable by an average coder without rewriting the delta format? Note the solutions presented here do not work with the delta format and the way \n is approached in delta makes it extremely confusing to even know where to begin to extend... overriding break causes havoc understandably. |
also padding-top to 0px with P is not an acceptable solution, without break support in blocks you can't create a simple div with a border where you can edit it's contents..., because you can't put P tags (blocks) inside blocks so no new lines. Specifically those |
Hey @jhchen,
Would you have some time to outline what's involved in adding support for this? I'd be more than happy to work on this and raise a PR so Quill can support this in core. For our editing needs, we'd like to give users more control over where line breaks appear in a paragraph that has paragraph-level formatting applied (e.g., text alignment, list-ness, indentation, line height, etc) to avoid widows or for artistic reasons (e.g., poetry, manually breaking lines to simulate flowing around arbitrary shapes, etc). Treating a manually broken set of lines as a single paragraph instead of separate paragraphs would make changing paragraph-level formatting a little easier. I've been playing around with an idea that differentiates between line breaks and paragraph breaks at the A line breaks is represented in a Delta as a
Would love to hear your thoughts on the correct way to proceed. Thanks for all your work on Quill! |
+1 Plz add this feature |
Quill 2.0 has been released (announcement post) with many changes and fixes. If this is still an issue please create a new issue after reviewing our updated Contributing guide 🙏 |
I believe supporting shift + enter should be a a priority. If you want to use div, that's fine, but
<div>text</div><div>text</div>
should be output with an enter, and<div>text<br>text</div>
with shift + enter.The text was updated successfully, but these errors were encountered: