Skip to content

Commit

Permalink
Fixed bug where the editor would get auto focused on IE running in qu…
Browse files Browse the repository at this point in the history
…irks mode.
  • Loading branch information
spocke committed Jun 1, 2012
1 parent 1aedce2 commit 5bca717
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Version 3.5.x (2012-xx-xx)
Fixed bug where the editor would get auto focused on IE running in quirks mode.
Version 3.5.2 (2012-05-31)
Added new formatChanged method to tinymce.Formatter class. Enables easier state change handling of formats.
Added new selectorChanged method to tinymce.dom.Selection class. Enables easier state change handling of matching CSS selectors.
Expand Down
41 changes: 22 additions & 19 deletions jscripts/tiny_mce/classes/ForceBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tinymce.ForceBlocks = function(editor) {
var settings = editor.settings, dom = editor.dom, selection = editor.selection, blockElements = editor.schema.getBlockElements();

function addRootBlocks() {
var node = selection.getStart(), rootNode = editor.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF, wrapped;
var node = selection.getStart(), rootNode = editor.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF, wrapped, isInEditorDocument;

if (!node || node.nodeType !== 1 || !settings.forced_root_block)
return;
Expand Down Expand Up @@ -40,6 +40,7 @@ tinymce.ForceBlocks = function(editor) {
rng.moveToElementText(node);
}

isInEditorDocument = rng.parentElement().ownerDocument === editor.getDoc();
tmpRng = rng.duplicate();
tmpRng.collapse(true);
startOffset = tmpRng.move('character', offset) * -1;
Expand Down Expand Up @@ -70,28 +71,30 @@ tinymce.ForceBlocks = function(editor) {
}
}

if (rng.setStart) {
rng.setStart(startContainer, startOffset);
rng.setEnd(endContainer, endOffset);
selection.setRng(rng);
} else {
try {
rng = editor.getDoc().body.createTextRange();
rng.moveToElementText(rootNode);
rng.collapse(true);
rng.moveStart('character', startOffset);
if (wrapped) {
if (rng.setStart) {
rng.setStart(startContainer, startOffset);
rng.setEnd(endContainer, endOffset);
selection.setRng(rng);
} else {
// Only select if the previous selection was inside the document to prevent auto focus in quirks mode
if (isInEditorDocument) {
try {
rng = editor.getDoc().body.createTextRange();
rng.moveToElementText(rootNode);
rng.collapse(true);
rng.moveStart('character', startOffset);

if (endOffset > 0)
rng.moveEnd('character', endOffset);
if (endOffset > 0)
rng.moveEnd('character', endOffset);

rng.select();
} catch (ex) {
// Ignore
rng.select();
} catch (ex) {
// Ignore
}
}
}
}

// Only trigger nodeChange when we wrapped nodes to prevent a forever loop
if (wrapped) {
editor.nodeChanged();
}
};
Expand Down

0 comments on commit 5bca717

Please sign in to comment.