1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 13:10:24 +02:00

fixes flarum/core#781 adding unnecessary newlines with empty composer

fixing indentation
This commit is contained in:
Daniel Klabbers
2016-02-15 20:49:12 +01:00
parent ab920bab05
commit da59430cb7

View File

@@ -3,12 +3,16 @@ import Button from 'flarum/components/Button';
import CommentPost from 'flarum/components/CommentPost';
import DiscussionControls from 'flarum/utils/DiscussionControls';
export default function() {
extend(CommentPost.prototype, 'actionItems', function(items) {
export default function () {
extend(CommentPost.prototype, 'actionItems', function (items) {
const post = this.props.post;
if (post.isHidden() || (app.session.user && !post.discussion().canReply())) return;
function calculatePrecedingNewlines(precedingContent) {
return precedingContent.length == 0 ? 0 : 3 - precedingContent.match(/(\n{0,2})$/)[0].length;
}
function insertMention(component, quote) {
const user = post.user();
const mention = '@' + (user ? user.username() : post.number()) + '#' + post.id() + ' ';
@@ -22,10 +26,9 @@ export default function() {
const cursorPosition = component.editor.getSelectionRange()[0];
const precedingContent = component.editor.value().slice(0, cursorPosition);
const trailingNewlines = precedingContent.match(/(\n{0,2})$/)[0].length;
component.editor.insertAtCursor(
Array(3 - trailingNewlines).join('\n') + // Insert up to two newlines, depending on preceding whitespace
Array(calculatePrecedingNewlines(precedingContent)).join('\n') + // Insert up to two newlines, depending on preceding whitespace
(quote
? '> ' + mention + quote.trim().replace(/\n/g, '\n> ') + '\n\n'
: mention)