]> git.mxchange.org Git - friendica.git/commitdiff
attachment preview: fix a bug if inserted text did contain a new line between content...
authorrabuzarus <trebor@central-unit>
Mon, 4 Feb 2019 00:23:30 +0000 (01:23 +0100)
committerrabuzarus <trebor@central-unit>
Mon, 4 Feb 2019 00:23:30 +0000 (01:23 +0100)
view/js/linkPreview.js

index f2b65a1689086316a7f7ea705f64809fddd2b960..ae2f0af5aba9099ab9c69d40925c380c69b2397a 100644 (file)
        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