From 39a9ba859271d6d4062e335cc21cc0ee60719213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kup=C5=9B?= Date: Thu, 8 Mar 2018 13:05:44 +0100 Subject: [PATCH] Aligned to chenges made to DocumentSelection in engine: manually removing attribute to not be stored in selection. --- src/inlineautoformatediting.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/inlineautoformatediting.js b/src/inlineautoformatediting.js index b8e4942..14bf9f5 100644 --- a/src/inlineautoformatediting.js +++ b/src/inlineautoformatediting.js @@ -68,7 +68,7 @@ export default class InlineAutoformatEditing { */ constructor( editor, testRegexpOrCallback, attributeOrCallback ) { let regExp; - let command; + let attributeKey; let testCallback; let formatCallback; @@ -79,7 +79,7 @@ export default class InlineAutoformatEditing { } if ( typeof attributeOrCallback == 'string' ) { - command = attributeOrCallback; + attributeKey = attributeOrCallback; } else { formatCallback = attributeOrCallback; } @@ -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', () => { @@ -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 );