This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from ckeditor/t/40
Feature: Add support for `copyOnEnter` attribute's parameter. Closes #40.
- Loading branch information
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module enter/utils | ||
*/ | ||
|
||
/** | ||
* Returns attributes that should be preserved on the enter key. | ||
* | ||
* Filtering is realized based on `copyOnEnter` attribute property. Read more about attribute properties | ||
* {@link module:engine/model/schema~Schema#setAttributeProperties here}. | ||
* | ||
* @param {module:engine/model/schema~Schema} schema | ||
* @param {Iterable.<*>} allAttributes attributes to filter. | ||
* @returns {Iterable.<*>} | ||
*/ | ||
export function* getCopyOnEnterAttributes( schema, allAttributes ) { | ||
for ( const attribute of allAttributes ) { | ||
if ( attribute && schema.getAttributeProperties( attribute[ 0 ] ).copyOnEnter ) { | ||
yield attribute; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
import { getCopyOnEnterAttributes } from '../src/utils'; | ||
import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor'; | ||
|
||
describe( 'utils', () => { | ||
describe( 'getCopyOnEnterAttributes()', () => { | ||
it( 'filters attributes with copyOnEnter property', () => { | ||
return ModelTestEditor.create() | ||
.then( editor => { | ||
const schema = editor.model.schema; | ||
|
||
schema.extend( '$text', { | ||
allowAttributes: [ 'foo', 'bar', 'baz' ] | ||
} ); | ||
|
||
schema.setAttributeProperties( 'foo', { copyOnEnter: true } ); | ||
schema.setAttributeProperties( 'baz', { copyOnEnter: true } ); | ||
|
||
const allAttributes = ( new Map( [ | ||
[ 'foo', true ], | ||
[ 'bar', true ], | ||
[ 'baz', true ] | ||
] ) )[ Symbol.iterator ](); | ||
|
||
expect( Array.from( getCopyOnEnterAttributes( schema, allAttributes ) ) ).to.deep.equal( | ||
[ | ||
[ 'foo', true ], | ||
[ 'baz', true ] | ||
] | ||
); | ||
} ); | ||
} ); | ||
} ); | ||
} ); |