function returnWord(text, caretPos) {\r
var index = text.indexOf(caretPos);\r
var preText = text.substring(0, caretPos);\r
- // If the last charachter is a space remove the one space\r
+ // If the last charachter is a space or enter remove it\r
// We need this in friendica for the url preview.\r
- if (preText.slice(-1) == " ") {\r
+ var lastChar = preText.slice(-1)\r
+ if ( lastChar === " "\r
+ || lastChar === "\n"\r
+ || lastChar === "\r"\r
+ )\r
+ {\r
preText = preText.substring(0, preText.length -1);\r
}\r
\r
+ // Replace new line with space.\r
+ preText = preText.replace(/\n/g, " ");\r
+\r
if (preText.indexOf(" ") > 0) {\r
var words = preText.split(" ");\r
return words[words.length - 1]; //return last word\r