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

Commit

Permalink
Merge branch 'master' into t/ckeditor5-alignment/16
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Mar 9, 2018
2 parents 162a933 + cf3b8cc commit 38eeaf4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/inlineautoformatediting.js
Expand Up @@ -68,7 +68,7 @@ export default class InlineAutoformatEditing {
*/
constructor( editor, testRegexpOrCallback, attributeOrCallback ) {
let regExp;
let command;
let attributeKey;
let testCallback;
let formatCallback;

Expand All @@ -79,7 +79,7 @@ export default class InlineAutoformatEditing {
}

if ( typeof attributeOrCallback == 'string' ) {
command = attributeOrCallback;
attributeKey = attributeOrCallback;
} else {
formatCallback = attributeOrCallback;
}
Expand Down Expand Up @@ -132,8 +132,12 @@ export default class InlineAutoformatEditing {
// A format callback run on matched text.
formatCallback = formatCallback || ( ( writer, validRanges ) => {
for ( const range of validRanges ) {
writer.setAttribute( command, true, range );
writer.setAttribute( attributeKey, true, range );
}

// After applying attribute to the text, remove given attribute from the selection.
// This way user is able to type a text without attribute used by auto formatter.
writer.removeSelectionAttribute( attributeKey );
} );

editor.model.document.on( 'change', () => {
Expand Down Expand Up @@ -187,7 +191,7 @@ export default class InlineAutoformatEditing {

// Use enqueueChange to create new batch to separate typing batch from the auto-format changes.
editor.model.enqueueChange( writer => {
const validRanges = editor.model.schema.getValidRanges( rangesToFormat, command );
const validRanges = editor.model.schema.getValidRanges( rangesToFormat, attributeKey );

// Apply format.
formatCallback( writer, validRanges );
Expand Down

0 comments on commit 38eeaf4

Please sign in to comment.