From b0372e5e9333dbfc0771000bacf5ce00ef4fc349 Mon Sep 17 00:00:00 2001 From: rabuzarus Date: Mon, 4 Feb 2019 01:23:30 +0100 Subject: [PATCH] attachment preview: fix a bug if inserted text did contain a new line between content and url --- view/js/linkPreview.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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