diff --git a/view/js/linkPreview.js b/view/js/linkPreview.js index f2b65a168..ae2f0af5a 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