X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fselection%2Fplugin.js;h=d8888c19dae88b213abeec2e1aca5c14eecf7f17;hp=a42ef66f3617031c1cc52514d8cd1132407dc52c;hb=f0610347140239143439a511ee2bd48cb784f470;hpb=4e70ea24db840898be8cc21c950363a52a2a6aba diff --git a/_source/plugins/selection/plugin.js b/_source/plugins/selection/plugin.js index a42ef66..d8888c1 100644 --- a/_source/plugins/selection/plugin.js +++ b/_source/plugins/selection/plugin.js @@ -78,6 +78,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license && node.getName() in CKEDITOR.dtd.$removeEmpty; } + function singletonBlock( node ) + { + var body = range.document.getBody(); + return !node.is( 'body' ) && body.getChildCount() == 1; + } + var start = range.startContainer, offset = range.startOffset; @@ -86,7 +92,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // 1. Empty inline element. ^ // 2. Adjoin to inline element.

text^

- return !CKEDITOR.tools.trim( start.getHtml() ) ? isInlineCt( start ) : isInlineCt( start.getChild( offset - 1 ) ) || isInlineCt( start.getChild( offset ) ); + // 3. The only empty block in document.

^

(#7222) + return !CKEDITOR.tools.trim( start.getHtml() ) ? isInlineCt( start ) || singletonBlock( start ) + : isInlineCt( start.getChild( offset - 1 ) ) || isInlineCt( start.getChild( offset ) ); } var selectAllCmd = @@ -469,6 +477,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }); editor.selectionChange = checkSelectionChangeTimeout; + + // IE9 might cease to work if there's an object selection inside the iframe (#7639). + CKEDITOR.env.ie9Compat && editor.on( 'destroy', function() + { + var sel = editor.getSelection(); + sel && sel.getNative().clear(); + }, null, null, 9 ); } }); @@ -1138,12 +1153,35 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return cache.selectedElement = ( node ? new CKEDITOR.dom.element( node ) : null ); }, + /** + * Retrieves the text contained within the range, empty string is returned for non-text selection. + * @returns {String} string of text within the current selection. + * @since 3.6.1 + * @example + * var text = editor.getSelectedText(); + * alert( text ); + */ + getSelectedText : function() + { + var cache = this._.cache; + if ( cache.selectedText !== undefined ) + return cache.selectedText; + + var text = '', + nativeSel = this.getNative(); + if ( this.getType() == CKEDITOR.SELECTION_TEXT ) + text = CKEDITOR.env.ie ? nativeSel.createRange().text : nativeSel.toString(); + + return ( cache.selectedText = text ); + }, + lock : function() { // Call all cacheable function. this.getRanges(); this.getStartElement(); this.getSelectedElement(); + this.getSelectedText(); // The native selection is not available when locked. this._.cache.nativeSel = {};