-
Notifications
You must be signed in to change notification settings - Fork 40
StylesProcessor is no longer singleton #1826
Changes from 29 commits
09acfe9
3ffb904
2d99f8f
414f1c1
2f4357f
3b361f8
c7e0226
9831535
88b9089
034b044
8af8720
1fdcb8b
dd78af1
8b56db1
8681e0a
a23ad5d
5145ce0
821ae00
2ce8492
e2ed99c
d431e83
e7f04b5
066db20
c62176b
42fa0f7
6b9ac71
cd0f3b6
3c3e902
fabfb3a
5a4ab82
21390a9
8039a8d
b21a415
054d8a2
13dd24c
16301a1
fb8e77a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -46,11 +46,12 @@ export default class DataController { | |||||||||
/** | ||||||||||
* Creates a data controller instance. | ||||||||||
* | ||||||||||
* @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor Styles processor. | ||||||||||
* @param {module:engine/model/model~Model} model Data model. | ||||||||||
* @param {module:engine/dataprocessor/dataprocessor~DataProcessor} [dataProcessor] Data processor that should be used | ||||||||||
* by the controller. | ||||||||||
*/ | ||||||||||
constructor( model, dataProcessor ) { | ||||||||||
constructor( stylesProcessor, model, dataProcessor ) { | ||||||||||
/** | ||||||||||
* Data model. | ||||||||||
* | ||||||||||
|
@@ -59,6 +60,14 @@ export default class DataController { | |||||||||
*/ | ||||||||||
this.model = model; | ||||||||||
|
||||||||||
/** | ||||||||||
* StylesProcessor is responsible for writing and reading a normalized styles object. | ||||||||||
* | ||||||||||
* @readonly | ||||||||||
* @member {module:engine/view/stylesmap~StylesProcessor} | ||||||||||
*/ | ||||||||||
this.stylesProcessor = stylesProcessor; | ||||||||||
|
||||||||||
/** | ||||||||||
* Data processor used during the conversion. | ||||||||||
* | ||||||||||
|
@@ -187,12 +196,13 @@ export default class DataController { | |||||||||
|
||||||||||
// First, convert elements. | ||||||||||
const modelRange = ModelRange._createIn( modelElementOrFragment ); | ||||||||||
const viewDocument = new ViewDocument( this.stylesProcessor ); | ||||||||||
|
||||||||||
const viewDocumentFragment = new ViewDocumentFragment(); | ||||||||||
const viewDocumentFragment = new ViewDocumentFragment( viewDocument ); | ||||||||||
|
||||||||||
// Create separate ViewDowncastWriter just for data conversion purposes. | ||||||||||
// We have no view controller and rendering do DOM in DataController so view.change() block is not used here. | ||||||||||
const viewWriter = new ViewDowncastWriter( new ViewDocument() ); | ||||||||||
const viewWriter = new ViewDowncastWriter( viewDocument ); | ||||||||||
this.mapper.bindElements( modelElementOrFragment, viewDocumentFragment ); | ||||||||||
|
||||||||||
this.downcastDispatcher.convertInsert( modelRange, viewWriter ); | ||||||||||
|
@@ -371,6 +381,22 @@ export default class DataController { | |||||||||
} ); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Adds a style processor normalization rules. | ||||||||||
* | ||||||||||
* The available style processors: | ||||||||||
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.
Suggested change
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.
Suggested change
|
||||||||||
* | ||||||||||
* * background: {@link module:engine/view/styles/background~addBackgroundRules} | ||||||||||
* * border: {@link module:engine/view/styles/border~addBorderRules} | ||||||||||
* * margin: {@link module:engine/view/styles/margin~addMarginRules} | ||||||||||
* * padding: {@link module:engine/view/styles/padding~addPaddingRules} | ||||||||||
* | ||||||||||
* @param {Function} callback | ||||||||||
*/ | ||||||||||
addStyleProcessorRules( callback ) { | ||||||||||
callback( this.stylesProcessor ); | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Removes all event listeners set by the DataController. | ||||||||||
*/ | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -416,11 +416,12 @@ export function remove() { | |
* provided by the {@link module:engine/conversion/downcasthelpers~HighlightDescriptor highlight descriptor} object. If a priority | ||
* is not provided in the descriptor, the default priority will be used. | ||
* | ||
* @param {module:engine/view/downcastwriter~DowncastWriter} writer | ||
* @param {module:engine/conversion/downcasthelpers~HighlightDescriptor} descriptor | ||
* @returns {module:engine/view/attributeelement~AttributeElement} | ||
*/ | ||
export function createViewElementFromHighlightDescriptor( descriptor ) { | ||
const viewElement = new ViewAttributeElement( 'span', descriptor.attributes ); | ||
export function createViewElementFromHighlightDescriptor( writer, descriptor ) { | ||
const viewElement = writer.createAttributeElement( 'span', descriptor.attributes ); | ||
|
||
if ( descriptor.classes ) { | ||
viewElement._addClass( descriptor.classes ); | ||
|
@@ -543,7 +544,7 @@ export function clearAttributes() { | |
// Not collapsed selection should not have artifacts. | ||
if ( range.isCollapsed ) { | ||
// Position might be in the node removed by the view writer. | ||
if ( range.end.parent.document ) { | ||
if ( range.end.parent.parent ) { | ||
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. TODO: check this later. Seems dangerous. 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. Yes, this changes the semantics and I'm also unsure about it. But it means that if this change didn't cause any test to fail, then we may be missing a test. cc @scofalik 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. @scofalik ping - would be nice to have this confirmed or debunked ;) |
||
conversionApi.writer.mergeAttributes( range.start ); | ||
} | ||
} | ||
|
@@ -919,8 +920,8 @@ function highlightText( highlightDescriptor ) { | |
return; | ||
} | ||
|
||
const viewElement = createViewElementFromHighlightDescriptor( descriptor ); | ||
const viewWriter = conversionApi.writer; | ||
const viewElement = createViewElementFromHighlightDescriptor( viewWriter, descriptor ); | ||
const viewSelection = viewWriter.document.selection; | ||
|
||
if ( data.item instanceof ModelSelection || data.item instanceof DocumentSelection ) { | ||
|
@@ -1034,7 +1035,7 @@ function removeHighlight( highlightDescriptor ) { | |
} | ||
|
||
// View element that will be used to unwrap `AttributeElement`s. | ||
const viewHighlightElement = createViewElementFromHighlightDescriptor( descriptor ); | ||
const viewHighlightElement = createViewElementFromHighlightDescriptor( conversionApi.writer, descriptor ); | ||
|
||
// Get all elements bound with given marker name. | ||
const elements = conversionApi.mapper.markerNameToElements( data.markerName ); | ||
|
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.
Why is this the first param? It should be the last one. It is the last one in the
EditingController
already.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.
Because
dataProcessor
is not required. Following the docs: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.
There is also a test that says the same.
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.
Still, the
model
is required. So if anything, this should be the 2nd arg.