attachment preview: fix a bug if inserted text did contain a new line between content and url

This commit is contained in:
rabuzarus 2019-02-04 01:23:30 +01:00
parent ac22c0593d
commit b0372e5e93

View file

@ -815,12 +815,20 @@
function returnWord(text, caretPos) { function returnWord(text, caretPos) {
var index = text.indexOf(caretPos); var index = text.indexOf(caretPos);
var preText = text.substring(0, 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. // 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); preText = preText.substring(0, preText.length -1);
} }
// Replace new line with space.
preText = preText.replace(/\n/g, " ");
if (preText.indexOf(" ") > 0) { if (preText.indexOf(" ") > 0) {
var words = preText.split(" "); var words = preText.split(" ");
return words[words.length - 1]; //return last word return words[words.length - 1]; //return last word