Skip to content
Browse files

FIXED: Problem where inline styles may be applied beyond the end of t…

…he selection.

Signed-off-by: Adrian Sutton <adrian.sutton@ephox.com>
  • Loading branch information...
1 parent eae310d commit 8d02ec2a891c1511d69e797094795a9f8f84ecef Yonas Yanfa committed with spocke Nov 4, 2010
Showing with 21 additions and 1 deletion.
  1. +1 −1 jscripts/tiny_mce/classes/dom/RangeUtils.js
  2. +20 −0 tests/tinymce.Formatter_apply.html
View
2 jscripts/tiny_mce/classes/dom/RangeUtils.js
@@ -93,7 +93,7 @@
// If index based end position then resolve it
if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
- endContainer = endContainer.childNodes[Math.min(startOffset == endOffset ? endOffset : endOffset - 1, endContainer.childNodes.length - 1)];
+ endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
// Find common ancestor and end points
ancestor = dom.findCommonAncestor(startContainer, endContainer);
View
20 tests/tinymce.Formatter_apply.html
@@ -624,6 +624,26 @@
equals(getContent(), '<table><tbody><tr><td><span class="a b c" style="color: #ff0000;" title="test">cell 1</span></td><td>cell 2</td></tr></tbody></table>', 'Apply format on single element that matches a selector');
//'<p class="a b c" style="color: #ff0000;" title="test">1234</p>', 'Apply format on single element that matches a selector');
});
+
+test('Formatter - Bold and italics is applied to text that is not highlighted', function() {
+ editor.setContent('<p>test1 test2 test3 test4 test5 test6</p>');
+ editor.execCommand('SelectAll');
+ editor.execCommand('FontName',false,'Arial');
+ equals(editor.getContent(), '<p><span style="font-family: ' + fontFace('Arial') + ';">test1 test2 test3 test4 test5 test6</span></p>', 'Font face should be Arial.');
+
+ rng = editor.dom.createRng();
+ rng.setStart(editor.dom.select('span')[0].firstChild, 0);
+ rng.setEnd(editor.dom.select('span')[0].firstChild, 12);
+ editor.selection.setRng(rng);
+ editor.execCommand('Bold');
+ equals(editor.getContent(), '<p><span style="font-family: ' + fontFace('Arial') + ';"><strong>test1 test2</strong> test3 test4 test5 test6</span></p>', 'Selected text should be bold.');
+
+ rng.setStart(editor.dom.select('strong')[0].firstChild, 6);
+ rng.setEnd(editor.dom.select('strong')[0].firstChild, 11);
+ editor.selection.setRng(rng);
+ editor.execCommand('Italic');
+ equals(editor.getContent(), '<p><span style="font-family: ' + fontFace('Arial') + ';"><strong>test1 <em>test2</em></strong> test3 test4 test5 test6</span></p>', 'Selected text should be bold.');
+});
/*
test('Formatter - apply (list block)', function() {

0 comments on commit 8d02ec2

Please sign in to comment.
Something went wrong with that request. Please try again.