From d97ad5f32ca328d9301fc7d2f17cead7efb4c931 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 23 Feb 2016 10:11:43 +0900 Subject: [PATCH] Use variable instead of closure --- extensions/mentions/js/forum/src/addPostReplyAction.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/extensions/mentions/js/forum/src/addPostReplyAction.js b/extensions/mentions/js/forum/src/addPostReplyAction.js index b2bff1aab..108e274fe 100644 --- a/extensions/mentions/js/forum/src/addPostReplyAction.js +++ b/extensions/mentions/js/forum/src/addPostReplyAction.js @@ -9,10 +9,6 @@ export default function () { 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() + ' '; @@ -25,10 +21,11 @@ export default function () { } const cursorPosition = component.editor.getSelectionRange()[0]; - const precedingContent = component.editor.value().slice(0, cursorPosition); + const preceding = component.editor.value().slice(0, cursorPosition); + const precedingNewlines = preceding.length == 0 ? 0 : 3 - preceding.match(/(\n{0,2})$/)[0].length; component.editor.insertAtCursor( - Array(calculatePrecedingNewlines(precedingContent)).join('\n') + // Insert up to two newlines, depending on preceding whitespace + Array(precedingNewlines).join('\n') + // Insert up to two newlines, depending on preceding whitespace (quote ? '> ' + mention + quote.trim().replace(/\n/g, '\n> ') + '\n\n' : mention)