Skip to content
Permalink
Browse files

Merge branch 't/13118' into major

  • Loading branch information...
Reinmar committed Apr 22, 2015
2 parents 2ad12d9 + b8660de commit fbfd310d46aacec1974e91bc2485d646f58782bb
Showing with 46 additions and 14 deletions.
  1. +4 −0 CHANGES.md
  2. +3 −2 core/editor.js
  3. +39 −12 tests/core/editor/getextractselectedhtml.js
@@ -3,6 +3,10 @@ CKEditor 4 Changelog

## CKEditor 4.5

Fixed Issues:

* [#13118](http://dev.ckeditor.com/ticket/13118): Fixed: The [`editor.getSelectedHtml()`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-getSelectedHtml) method throws error when called in the source mode.

## CKEditor 4.5 Beta

New Features:
@@ -1112,9 +1112,10 @@
*/
getSelectedHtml: function( toString ) {
var editable = this.editable(),
ranges = this.getSelection().getRanges();
selection = this.getSelection(),
ranges = selection && selection.getRanges();

if ( !editable || ranges.length === 0 ) {
if ( !editable || !ranges || ranges.length === 0 ) {
return null;
}

@@ -2,10 +2,20 @@

'use strict';

bender.editor = {
creator: 'inline',
config: {
allowedContent: true
bender.editors = {
editor: {
name: 'editor',
creator: 'inline',
config: {
allowedContent: true
}
},

editor2: {
name: 'editor2',
config: {
extraPlugins: 'sourcearea'
}
}
};

@@ -20,8 +30,25 @@ bender.test( {
}
},

'test getSelectedHtml in source mode (#13118)': function() {
var editor = this.editors.editor2;

editor.setMode( 'source', function() {
resume( function() {
editor.getSelectedHtml();
assert.isTrue( true, 'So far so good. Method "getSelectedHtml" shouldn\'t throw an error in a "source" mode.' );

// Clean up after the test.
editor.setMode( 'wysiwyg', resume );
wait();
} );
} );

wait();
},

'test getSelectedHtml': function() {
var editor = this.editor;
var editor = this.editors.editor;
bender.tools.selection.setWithHtml( editor, '<p>fo{ob}ar</p>' );

var frag = editor.getSelectedHtml();
@@ -31,7 +58,7 @@ bender.test( {
},

'test getSelectedHtml with toString option': function() {
var editor = this.editor;
var editor = this.editors.editor;
bender.tools.selection.setWithHtml( editor, '<p>fo{ob}ar</p>' );

assert.areSame( 'ob', editor.getSelectedHtml( true ) );
@@ -46,14 +73,14 @@ bender.test( {
sinon.stub( CKEDITOR.dom.selection.prototype, 'getRanges' ).returns( [] );
stubs.push( CKEDITOR.dom.selection.prototype.getRanges );

var editor = this.editor,
var editor = this.editors.editor,
selectedHtml = editor.getSelectedHtml();

assert.isNull( selectedHtml, 'There should be no error but null should be returns if selection contains no ranges' );
},

'test extractSelectedHtml': function() {
var editor = this.editor;
var editor = this.editors.editor;
bender.tools.selection.setWithHtml( editor, '<p>fo{ob}ar</p>' );

// We need to precisely check if selection was set, because
@@ -73,7 +100,7 @@ bender.test( {
},

'test extractSelectedHtml with toString option': function() {
var editor = this.editor;
var editor = this.editors.editor;
bender.tools.selection.setWithHtml( editor, '<p>fo{ob}ar</p>' );

assert.areSame( 'ob', editor.extractSelectedHtml( true ) );
@@ -85,14 +112,14 @@ bender.test( {
sinon.stub( CKEDITOR.dom.selection.prototype, 'getRanges' ).returns( [] );
stubs.push( CKEDITOR.dom.selection.prototype.getRanges );

var editor = this.editor,
var editor = this.editors.editor,
selectedHtml = editor.getSelectedHtml();

assert.isNull( selectedHtml, 'There should be no error but null should be returns if selection contains no ranges' );
},

'test extractSelectedHtml with removeEmptyBlock': function() {
var editor = this.editor;
var editor = this.editors.editor;
bender.tools.selection.setWithHtml( editor, '<p>{foo}</p><p>bar</p>' );

assert.areSame( 'foo', editor.extractSelectedHtml( true, true ) );
@@ -108,4 +135,4 @@ bender.test( {
assert.isTrue( html == null || html === '', 'returned value should be null if selection does not exist or should be an empty string' );
} );
}
} );
} );

0 comments on commit fbfd310

Please sign in to comment.
You can’t perform that action at this time.