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 40
Do not run AttributeToAttribute
downcast conversion on TextProxy
nodes
#1595
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
669c5fd
Do not run 'AttributeToAttribute' conversion on 'TextProxy'.
f1ames 50f78a0
Add warning message to point out converters misconfiguration.
f1ames 07321e3
Docs: proper converter priority usage. [skip ci]
f1ames 1844649
Docs: The 'aToA' converter docs mentions usage of 'aToE' converter fo…
f1ames 83f7091
Docs: Rewording.
f1ames File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ModelElement from '../model/element'; | |
import ViewAttributeElement from '../view/attributeelement'; | ||
import DocumentSelection from '../model/documentselection'; | ||
|
||
import log from '@ckeditor/ckeditor5-utils/src/log'; | ||
import { cloneDeep } from 'lodash-es'; | ||
|
||
/** | ||
|
@@ -685,9 +686,44 @@ export function changeAttribute( attributeCreator ) { | |
const viewElement = conversionApi.mapper.toViewElement( data.item ); | ||
const viewWriter = conversionApi.writer; | ||
|
||
// If model item cannot be mapped to view element, it means item is not an `Element` instance (it is a `TextProxy`). | ||
// Only elements can have attributes in a view so do not proceed for anything else (see #1587). | ||
// If model item cannot be mapped to a view element, it means item is not an `Element` instance but a `TextProxy` node. | ||
// Only elements can have attributes in a view so do not proceed for anything else (#1587). | ||
if ( !viewElement ) { | ||
/** | ||
* This error occurs when a {@link module:engine/model/textproxy~TextProxy text node} is to be downcasted | ||
* by {@link module:engine/conversion/conversion~Conversion#attributeToAttribute `Attribute to Attribute converter`}. | ||
* In most cases it is caused by converters misconfiguration when only "generic" converter is defined: | ||
* | ||
* editor.conversion.for( 'downcast' ).add( downcastAttributeToAttribute( { | ||
* model: 'attribute-name', | ||
* view: 'attribute-name' | ||
* } ) ); | ||
* | ||
* and given attribute is used on text node, for example: | ||
* | ||
* model.change( writer => { | ||
* writer.insertText( 'Foo', { 'attribute-name': 'bar' }, parent, 0 ); | ||
* } ); | ||
* | ||
* In such cases, to convert the same attribute for both {@link module:engine/model/element~Element} | ||
* and {@link module:engine/model/textproxy~TextProxy `Text`} nodes, text specific | ||
* {@link module:engine/conversion/conversion~Conversion#attributeToElement `Attribute to Element converter`} | ||
* with higher {@link module:utils/priorities~PriorityString priority} must also be defined: | ||
* | ||
* conversion.for( 'downcast' ).add( downcastAttributeToElement( { | ||
* model: { | ||
* key: 'attribute-name', | ||
* name: '$text' | ||
* }, | ||
* view: ( value, writer ) => { | ||
* return writer.createAttributeElement( 'span', { 'attribute-name': value } ); | ||
* } | ||
* } ), { priority: 'high' } ); | ||
* | ||
* @error conversion-attribute-to-attribute-on-text | ||
*/ | ||
log.warn( 'conversion-attribute-to-attribute-on-text: Trying to convert text node with attribute to attribute converter.' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. text node's attribute attribute-to-attribute |
||
|
||
return; | ||
} | ||
|
||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text node's attribute