streamline the state caching for IE mousedown a bit; also remember the text area... master
authorbalpha <devnull@localhost>
Wed, 10 Aug 2011 08:09:49 +0000 (10:09 +0200)
committerbalpha <devnull@localhost>
Wed, 10 Aug 2011 08:09:49 +0000 (10:09 +0200)
Markdown.Editor.js

index 5e839a9..19d6914 100644 (file)
 \r
     // A collection of the important regions on the page.\r
     // Cached so we don't have to keep traversing the DOM.\r
 \r
     // A collection of the important regions on the page.\r
     // Cached so we don't have to keep traversing the DOM.\r
-    // Also holds ieRetardedClick and ieCachedRange, where necessary; working around\r
+    // Also holds ieCachedRange and ieCachedScrollTop, where necessary; working around\r
     // this issue:\r
     // Internet explorer has problems with CSS sprite buttons that use HTML\r
     // lists.  When you click on the background image "button", IE will \r
     // this issue:\r
     // Internet explorer has problems with CSS sprite buttons that use HTML\r
     // lists.  When you click on the background image "button", IE will \r
 \r
         this.setInputAreaSelectionStartEnd = function () {\r
 \r
 \r
         this.setInputAreaSelectionStartEnd = function () {\r
 \r
-            if (!panels.ieRetardedClick && (inputArea.selectionStart || inputArea.selectionStart === 0)) {\r
+            if (!panels.ieCachedRange && (inputArea.selectionStart || inputArea.selectionStart === 0)) {\r
 \r
                 stateObj.start = inputArea.selectionStart;\r
                 stateObj.end = inputArea.selectionEnd;\r
 \r
                 stateObj.start = inputArea.selectionStart;\r
                 stateObj.end = inputArea.selectionEnd;\r
                 stateObj.text = util.fixEolChars(inputArea.value);\r
 \r
                 // IE loses the selection in the textarea when buttons are\r
                 stateObj.text = util.fixEolChars(inputArea.value);\r
 \r
                 // IE loses the selection in the textarea when buttons are\r
-                // clicked.  On IE we cache the selection and set a flag\r
-                // which we check for here.\r
-                var range;\r
-                if (panels.ieRetardedClick && panels.ieCachedRange) {\r
-                    range = panels.ieCachedRange;\r
-                    panels.ieRetardedClick = false;\r
-                }\r
-                else {\r
-                    range = doc.selection.createRange();\r
-                }\r
+                // clicked.  On IE we cache the selection. Here, if something is cached,\r
+                // we take it.\r
+                var range = panels.ieCachedRange || doc.selection.createRange();\r
 \r
                 var fixedRange = util.fixEolChars(range.text);\r
                 var marker = "\x07";\r
 \r
                 var fixedRange = util.fixEolChars(range.text);\r
                 var marker = "\x07";\r
                     range.text = fixedRange;\r
                 }\r
 \r
                     range.text = fixedRange;\r
                 }\r
 \r
+                if (panels.ieCachedRange)\r
+                    stateObj.scrollTop = panels.ieCachedScrollTop; // this is set alongside with ieCachedRange\r
+                \r
+                panels.ieCachedRange = null;\r
+\r
                 this.setInputAreaSelection();\r
             }\r
         };\r
                 this.setInputAreaSelection();\r
             }\r
         };\r
                         if (doc.activeElement && doc.activeElement !== panels.input) { // we're not even in the input box, so there's no selection\r
                             return;\r
                         }\r
                         if (doc.activeElement && doc.activeElement !== panels.input) { // we're not even in the input box, so there's no selection\r
                             return;\r
                         }\r
-                        panels.ieRetardedClick = true;\r
                         panels.ieCachedRange = document.selection.createRange();\r
                         panels.ieCachedRange = document.selection.createRange();\r
+                        panels.ieCachedScrollTop = panels.input.scrollTop;\r
                     };\r
                 }\r
 \r
                     };\r
                 }\r
 \r