Using our own range to determine cursor position (more reliable)
authorAlexander Ebert <ebert@woltlab.com>
Sat, 7 Mar 2015 22:20:55 +0000 (23:20 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 7 Mar 2015 22:20:55 +0000 (23:20 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js

index 2824465d8883e64b15af20e47d862eac759db1b9..e80a5e1e46ccddb7804f0e4dbe08adf0bb296cb5 100644 (file)
@@ -790,26 +790,31 @@ RedactorPlugins.wutil = function() {
                 * @return      boolean
                 */
                isEndOfElement: function(element) {
-                       this.selection.get();
+                       // prefer our range because it is more reliable
+                       var $range = this.selection.implicitRange;
+                       if ($range === null) {
+                               this.selection.get();
+                               $range = this.range;
+                       }
                        
                        // range is not a plain caret
                        if (!this.wutil.isCaret()) {
                                return false;
                        }
                        
-                       if (this.range.endContainer.nodeType === Element.TEXT_NODE) {
+                       if ($range.endContainer.nodeType === Element.TEXT_NODE) {
                                // caret is not at the end
-                               if (this.range.endOffset < this.range.endContainer.length) {
+                               if ($range.endOffset < $range.endContainer.length) {
                                        return false;
                                }
                        }
                        
                        // range is not within the provided element
-                       if (!this.wutil.isNodeWithin(this.range.endContainer, element)) {
+                       if (!this.wutil.isNodeWithin($range.endContainer, element)) {
                                return false;
                        }
                        
-                       var $current = this.range.endContainer;
+                       var $current = $range.endContainer;
                        while ($current !== element) {
                                // end of range is not the last element
                                if ($current.nextSibling) {