Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_updateAttributes( clearAll ) {
const newAttributes = toMap( this._getSurroundingAttributes() );
const oldAttributes = toMap( this.getAttributes() );
if ( clearAll ) {
// If `clearAll` remove all attributes and reset priorities.
this._attributePriority = new Map();
this._attrs = new Map();
} else {
// If not, remove only attributes added with `low` priority.
for ( const [ key, priority ] of this._attributePriority ) {
if ( priority == 'low' ) {
this._attrs.delete( key );
this._attributePriority.delete( key );
}
}
}
_updateAttributes( clearAll ) {
const newAttributes = toMap( this._getSurroundingAttributes() );
const oldAttributes = toMap( this.getAttributes() );
if ( clearAll ) {
// If `clearAll` remove all attributes and reset priorities.
this._attributePriority = new Map();
this._attrs = new Map();
} else {
// If not, remove only attributes added with `low` priority.
for ( const [ key, priority ] of this._attributePriority ) {
if ( priority == 'low' ) {
this._attrs.delete( key );
this._attributePriority.delete( key );
}
}
}
// Convert view selection to model selection.
if ( viewSelection ) {
const ranges = [];
// Convert ranges.
for ( const viewRange of viewSelection.getRanges() ) {
ranges.push( mapper.toModelRange( viewRange ) );
}
// Create new selection.
selection = new ModelSelection( ranges, { backward: viewSelection.isBackward } );
// Set attributes to selection if specified.
for ( const [ key, value ] of toMap( options.selectionAttributes || [] ) ) {
selection.setAttribute( key, value );
}
}
// Return model end selection when selection was specified.
if ( selection ) {
return { model, selection };
}
// Otherwise return model only.
return model;
}
_updateAttributes( clearAll ) {
const newAttributes = toMap( this._getSurroundingAttributes() );
const oldAttributes = toMap( this.getAttributes() );
if ( clearAll ) {
// If `clearAll` remove all attributes and reset priorities.
this._attributePriority = new Map();
this._attrs = new Map();
} else {
// If not, remove only attributes added with `low` priority.
for ( const [ key, priority ] of this._attributePriority ) {
if ( priority == 'low' ) {
this._attrs.delete( key );
this._attributePriority.delete( key );
}
}
}
this._setAttributesTo( newAttributes );
setAttributesTo( attrs ) {
attrs = toMap( attrs );
if ( !mapsEqual( attrs, this._attrs ) ) {
// Create a set from keys of old and new attributes.
const changed = new Set( Array.from( attrs.keys() ).concat( Array.from( this._attrs.keys() ) ) );
for ( const [ key, value ] of attrs ) {
// If the attribute remains unchanged, remove it from changed set.
if ( this._attrs.get( key ) === value ) {
changed.delete( key );
}
}
this._attrs = attrs;
this.fire( 'change:attribute', { attributeKeys: Array.from( changed ), directChange: true } );
}
setSelectionAttribute( keyOrObjectOrIterable, value ) {
this._assertWriterUsedCorrectly();
if ( typeof keyOrObjectOrIterable === 'string' ) {
this._setSelectionAttribute( keyOrObjectOrIterable, value );
} else {
for ( const [ key, value ] of toMap( keyOrObjectOrIterable ) ) {
this._setSelectionAttribute( key, value );
}
}
}
_setAttributesTo( attrs ) {
this._attrs = toMap( attrs );
}