Skip to content

Commit

Permalink
streamline the state caching for IE mousedown a bit; also remember th…
Browse files Browse the repository at this point in the history
…e text area's scroll position
  • Loading branch information
balpha committed Aug 10, 2011
1 parent 963d02f commit afa3a9f
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions Markdown.Editor.js
Expand Up @@ -227,7 +227,7 @@

// A collection of the important regions on the page.
// Cached so we don't have to keep traversing the DOM.
// Also holds ieRetardedClick and ieCachedRange, where necessary; working around
// Also holds ieCachedRange and ieCachedScrollTop, where necessary; working around
// this issue:
// Internet explorer has problems with CSS sprite buttons that use HTML
// lists. When you click on the background image "button", IE will
Expand Down Expand Up @@ -678,7 +678,7 @@

this.setInputAreaSelectionStartEnd = function () {

if (!panels.ieRetardedClick && (inputArea.selectionStart || inputArea.selectionStart === 0)) {
if (!panels.ieCachedRange && (inputArea.selectionStart || inputArea.selectionStart === 0)) {

stateObj.start = inputArea.selectionStart;
stateObj.end = inputArea.selectionEnd;
Expand All @@ -688,16 +688,9 @@
stateObj.text = util.fixEolChars(inputArea.value);

// IE loses the selection in the textarea when buttons are
// clicked. On IE we cache the selection and set a flag
// which we check for here.
var range;
if (panels.ieRetardedClick && panels.ieCachedRange) {
range = panels.ieCachedRange;
panels.ieRetardedClick = false;
}
else {
range = doc.selection.createRange();
}
// clicked. On IE we cache the selection. Here, if something is cached,
// we take it.
var range = panels.ieCachedRange || doc.selection.createRange();

var fixedRange = util.fixEolChars(range.text);
var marker = "\x07";
Expand All @@ -722,6 +715,11 @@
range.text = fixedRange;
}

if (panels.ieCachedRange)
stateObj.scrollTop = panels.ieCachedScrollTop; // this is set alongside with ieCachedRange

panels.ieCachedRange = null;

this.setInputAreaSelection();
}
};
Expand Down Expand Up @@ -1344,8 +1342,8 @@
if (doc.activeElement && doc.activeElement !== panels.input) { // we're not even in the input box, so there's no selection
return;
}
panels.ieRetardedClick = true;
panels.ieCachedRange = document.selection.createRange();
panels.ieCachedScrollTop = panels.input.scrollTop;
};
}

Expand Down

0 comments on commit afa3a9f

Please sign in to comment.