X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fbidi%2Fplugin.js;h=830e2d4cefd87170acb1065df2baeb28f0b1a7c4;hp=d3ef3510246abf6127e3002deceb9853b62d72fe;hb=48b1db88210b4160dce439c6e3e32e14af8c106b;hpb=9afde8772159bd3436f1f5b7862960307710ae5a diff --git a/_source/plugins/bidi/plugin.js b/_source/plugins/bidi/plugin.js index d3ef351..830e2d4 100644 --- a/_source/plugins/bidi/plugin.js +++ b/_source/plugins/bidi/plugin.js @@ -1,11 +1,11 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ (function() { - var guardElements = { table:1, tbody: 1, ul:1, ol:1, blockquote:1, div:1, tr: 1 }, + var guardElements = { table:1, ul:1, ol:1, blockquote:1, div:1 }, directSelectionGuardElements = {}, // All guard elements which can have a direction applied on them. allGuardElements = {}; @@ -33,7 +33,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license selectedElement = selectedElement || path.block || path.blockLimit; - if ( !selectedElement || selectedElement.getName() == 'body' ) + // If we're having BODY here, user probably done CTRL+A, let's try to get the enclosed node, if any. + selectedElement.is( 'body' ) && + ( selectedElement = editor.getSelection().getRanges()[ 0 ].getEnclosedNode() ); + + if ( !selectedElement ) return; var selectionDir = useComputedState ? @@ -136,11 +140,14 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return null; } - function getFullySelected( range, elements ) + function getFullySelected( range, elements, enterMode ) { var ancestor = range.getCommonAncestor( false, true ); - range.enlarge( CKEDITOR.ENLARGE_BLOCK_CONTENTS ); + range = range.clone(); + range.enlarge( enterMode == CKEDITOR.ENTER_BR ? + CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS + : CKEDITOR.ENLARGE_BLOCK_CONTENTS ); if ( range.checkBoundaryOfElement( ancestor, CKEDITOR.START ) && range.checkBoundaryOfElement( ancestor, CKEDITOR.END ) ) @@ -149,8 +156,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license while ( ancestor && ancestor.type == CKEDITOR.NODE_ELEMENT && ( parent = ancestor.getParent() ) && parent.getChildCount() == 1 - && ( !( ancestor.getName() in elements ) || ( parent.getName() in elements ) ) - ) + && !( ancestor.getName() in elements ) ) ancestor = parent; return ancestor.type == CKEDITOR.NODE_ELEMENT @@ -187,7 +193,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( !selectedElement || selectedElement && !( selectedElement.type == CKEDITOR.NODE_ELEMENT && selectedElement.getName() in directSelectionGuardElements ) ) - selectedElement = getFullySelected( range, guardElements ); + selectedElement = getFullySelected( range, guardElements, enterMode ); if ( selectedElement && !selectedElement.isReadOnly() ) switchDir( selectedElement, dir, editor, database ); @@ -205,7 +211,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { return !! ( node.type == CKEDITOR.NODE_ELEMENT && node.getName() in guardElements - && !( node.getName() == ( enterMode == CKEDITOR.ENTER_P ) ? 'p' : 'div' + && !( node.getName() == ( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) && node.getParent().type == CKEDITOR.NODE_ELEMENT && node.getParent().getName() == 'blockquote' ) // Element must be fully included in the range as well. (#6485). @@ -221,7 +227,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license while ( ( block = iterator.getNextParagraph( enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ) ) ) !block.isReadOnly() && switchDir( block, dir, editor, database ); - } + } CKEDITOR.dom.element.clearAllMarkers( database ); @@ -263,3 +269,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }); })(); + +/** + * Fired when the language direction of an element is changed + * @name CKEDITOR.editor#dirChanged + * @event + * @param {CKEDITOR.editor} editor This editor instance. + * @param {Object} eventData.node The element that is being changed. + * @param {String} eventData.dir The new direction. + */