From a62c7392aacf9a87d8c7dbf11b8b047529a162b3 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 22 Jan 2014 03:14:50 -0500
Subject: [PATCH] Add 'markfolder' event (#1485775)

---
 program/js/tiny_mce/plugins/autolink/editor_plugin_src.js |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/program/js/tiny_mce/plugins/autolink/editor_plugin_src.js b/program/js/tiny_mce/plugins/autolink/editor_plugin_src.js
index 8c1cd68..5b61f7a 100644
--- a/program/js/tiny_mce/plugins/autolink/editor_plugin_src.js
+++ b/program/js/tiny_mce/plugins/autolink/editor_plugin_src.js
@@ -89,8 +89,11 @@
 					while (endContainer.nodeType != 3 && endContainer.firstChild)
 						endContainer = endContainer.firstChild;
 
-					r.setStart(endContainer, 0);
-					r.setEnd(endContainer, endContainer.nodeValue.length);
+					// Move range to text node
+					if (endContainer.nodeType == 3) {
+						r.setStart(endContainer, 0);
+						r.setEnd(endContainer, endContainer.nodeValue.length);
+					}
 				}
 
 				if (r.endOffset == 1)
@@ -104,8 +107,8 @@
 			do
 			{
 				// Move the selection one character backwards.
-				r.setStart(endContainer, end - 2);
-				r.setEnd(endContainer, end - 1);
+				r.setStart(endContainer, end >= 2 ? end - 2 : 0);
+				r.setEnd(endContainer, end >= 1 ? end - 1 : 0);
 				end -= 1;
 
 				// Loop until one of the following is found: a blank space, &nbsp;, delimeter, (end-2) >= 0

--
Gitblit v1.9.1