Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1128 from ckeditor/t/1127
Browse files Browse the repository at this point in the history
Fix: Fixed a bug when a block quote could not be applied to an empty paragraph with a basic style (bold, etc.) active in it. Closes #1127.
  • Loading branch information
Reinmar authored Sep 6, 2017
2 parents 5cbb4b2 + 6ad4baa commit 6d33b9f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,17 @@ export default class DocumentSelection extends Selection {
return storePrefix + key;
}

/**
* Checks whether the given attribute key is an attribute stored on an element.
*
* @protected
* @param {String} key
* @returns {Boolean}
*/
static _isStoreAttributeKey( key ) {
return key.startsWith( storePrefix );
}

/**
* Internal method for setting `DocumentSelection` attribute. Supports attribute priorities (through `directChange`
* parameter).
Expand Down
8 changes: 8 additions & 0 deletions src/model/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import Position from './position';
import Element from './element';
import Range from './range';
import DocumentSelection from './documentselection';
import clone from '@ckeditor/ckeditor5-utils/src/lib/lodash/clone';
import isArray from '@ckeditor/ckeditor5-utils/src/lib/lodash/isArray';
import isString from '@ckeditor/ckeditor5-utils/src/lib/lodash/isString';
Expand Down Expand Up @@ -217,6 +218,13 @@ export default class Schema {
// Keep in mind that if the query has no attributes, query.attribute was converted to an array
// with a single `undefined` value. This fits the algorithm well.
for ( const attribute of query.attributes ) {
// Skip all attributes that are stored in elements.
// This isn't perfect solution but we have to deal with it for now.
// `attribute` may have `undefined` value.
if ( attribute && DocumentSelection._isStoreAttributeKey( attribute ) ) {
continue;
}

let matched = false;

for ( const schemaItem of schemaItems ) {
Expand Down
10 changes: 10 additions & 0 deletions tests/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ describe( 'DocumentSelection', () => {
} );
} );

describe( '_isStoreAttributeKey', () => {
it( 'should return true if given key is a key of an attribute stored in element by DocumentSelection', () => {
expect( DocumentSelection._isStoreAttributeKey( fooStoreAttrKey ) ).to.be.true;
} );

it( 'should return false if given key is not a key of an attribute stored in element by DocumentSelection', () => {
expect( DocumentSelection._isStoreAttributeKey( 'foo' ) ).to.be.false;
} );
} );

// DocumentSelection uses LiveRanges so here are only simple test to see if integration is
// working well, without getting into complicated corner cases.
describe( 'after applying an operation should get updated and fire events', () => {
Expand Down
10 changes: 10 additions & 0 deletions tests/model/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ describe( 'Schema', () => {
it( 'should omit path elements that are added to schema', () => {
expect( schema.check( { name: '$inline', inside: '$block new $block' } ) ).to.be.true;
} );

it( 'should ignore attributes stored in elements by document selection', () => {
expect( schema.check( { name: '$block', attributes: 'selection:foo', inside: '$root' } ) ).to.be.true;
} );

it( 'should disallow attribute stored in an element if that attribute was explicitly disallowed', () => {
schema.disallow( { name: '$block', attributes: [ 'selection:foo' ], inside: '$root' } );

expect( schema.check( { name: '$block', attributes: [ 'selection:foo' ], inside: '$root' } ) ).to.be.false;
} );
} );

describe( 'array of elements as inside', () => {
Expand Down

0 comments on commit 6d33b9f

Please sign in to comment.