|
@@ -138,28 +138,7 @@ export default class ColorUI extends Plugin {
|
|
|
if ( documentColorsCount !== 0 ) {
|
|
if ( documentColorsCount !== 0 ) {
|
|
|
dropdownView.on( 'change:isOpen', ( evt, name, val ) => {
|
|
dropdownView.on( 'change:isOpen', ( evt, name, val ) => {
|
|
|
if ( val ) {
|
|
if ( val ) {
|
|
|
- const model = editor.model;
|
|
|
|
|
- const document = model.document;
|
|
|
|
|
- const rootNames = document.getRootNames();
|
|
|
|
|
- const maxCount = this.colorTableView.documentColorsCount;
|
|
|
|
|
- const documentColors = this.colorTableView.documentColors;
|
|
|
|
|
- documentColors.clear();
|
|
|
|
|
-
|
|
|
|
|
- for ( const rootName of rootNames ) {
|
|
|
|
|
- const root = document.getRoot( rootName );
|
|
|
|
|
- const range = model.createRangeIn( root );
|
|
|
|
|
- for ( const node of range.getItems() ) {
|
|
|
|
|
- if ( node.is( 'textProxy' ) && node.hasAttribute( this.componentName ) ) {
|
|
|
|
|
- this.addColorToDocumentColors( node.getAttribute( this.componentName ) );
|
|
|
|
|
- if ( documentColors.length >= maxCount ) {
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if ( documentColors.length >= maxCount ) {
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.findAndSetDocumentColors();
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
@@ -168,6 +147,34 @@ export default class ColorUI extends Plugin {
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Method scans through editor's content and search for text node attributes with name {@link #commandName}.
|
|
|
|
|
+ * Found entries are set as document colors. Previously stored document colors are lost with that process.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @private
|
|
|
|
|
+ */
|
|
|
|
|
+ findAndSetDocumentColors() {
|
|
|
|
|
+ const model = this.editor.model;
|
|
|
|
|
+ const document = model.document;
|
|
|
|
|
+ const maxCount = this.colorTableView.documentColorsCount;
|
|
|
|
|
+ const documentColors = this.colorTableView.documentColors;
|
|
|
|
|
+
|
|
|
|
|
+ documentColors.clear();
|
|
|
|
|
+
|
|
|
|
|
+ for ( const rootName of document.getRootNames() ) {
|
|
|
|
|
+ const root = document.getRoot( rootName );
|
|
|
|
|
+ const range = model.createRangeIn( root );
|
|
|
|
|
+ for ( const node of range.getItems() ) {
|
|
|
|
|
+ if ( node.is( 'textProxy' ) && node.hasAttribute( this.componentName ) ) {
|
|
|
|
|
+ this.addColorToDocumentColors( node.getAttribute( this.componentName ) );
|
|
|
|
|
+ if ( documentColors.length >= maxCount ) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Method tries to find a color on predefined color list to prevent of creating custom color from it.
|
|
* Method tries to find a color on predefined color list to prevent of creating custom color from it.
|
|
|
* If color is found, then it is added to the {@link module:font/ui/colortableview~ColorTableView#documentColors} model.
|
|
* If color is found, then it is added to the {@link module:font/ui/colortableview~ColorTableView#documentColors} model.
|
|
@@ -179,6 +186,7 @@ export default class ColorUI extends Plugin {
|
|
|
addColorToDocumentColors( color ) {
|
|
addColorToDocumentColors( color ) {
|
|
|
const predefinedColor = this.colorTableView.colorDefinitions
|
|
const predefinedColor = this.colorTableView.colorDefinitions
|
|
|
.find( definition => definition.color === color );
|
|
.find( definition => definition.color === color );
|
|
|
|
|
+
|
|
|
if ( !predefinedColor ) {
|
|
if ( !predefinedColor ) {
|
|
|
this.colorTableView.documentColors.add( {
|
|
this.colorTableView.documentColors.add( {
|
|
|
color,
|
|
color,
|