From: rabuzarus Date: Mon, 4 Feb 2019 00:23:30 +0000 (+0100) Subject: attachment preview: fix a bug if inserted text did contain a new line between content... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b0372e5e9333dbfc0771000bacf5ce00ef4fc349;p=friendica.git attachment preview: fix a bug if inserted text did contain a new line between content and url --- diff --git a/view/js/linkPreview.js b/view/js/linkPreview.js index f2b65a1689..ae2f0af5ab 100644 --- a/view/js/linkPreview.js +++ b/view/js/linkPreview.js @@ -815,12 +815,20 @@ function returnWord(text, caretPos) { var index = text.indexOf(caretPos); var preText = text.substring(0, caretPos); - // If the last charachter is a space remove the one space + // If the last charachter is a space or enter remove it // We need this in friendica for the url preview. - if (preText.slice(-1) == " ") { + var lastChar = preText.slice(-1) + if ( lastChar === " " + || lastChar === "\n" + || lastChar === "\r" + ) + { preText = preText.substring(0, preText.length -1); } + // Replace new line with space. + preText = preText.replace(/\n/g, " "); + if (preText.indexOf(" ") > 0) { var words = preText.split(" "); return words[words.length - 1]; //return last word