-
Notifications
You must be signed in to change notification settings - Fork 40
StylesProcessor is no longer singleton #1826
Conversation
… "view.DocumentFragment".
…cause it always be defined.
…fter inserting a children to an element.
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.
I think we're good to merge it now 👍
What happened to the CI? :D It's bloody red. |
@Reinmar #monorepo: https://travis-ci.org/ckeditor/ckeditor5/builds/654456582?utm_source=github_status&utm_medium=notification |
Why have I asked? :D |
OK, some more changes are needed, unfortunately. This time much smaller, though. I missed the fact that we should keep the model and view APIs as similar as possible. The following changes will ensure that:
|
Done. Ready for review once again. New CI => https://travis-ci.org/ckeditor/ckeditor5/builds/656226522. |
src/model/node.js
Outdated
@@ -189,20 +189,12 @@ export default class Node { | |||
} | |||
|
|||
/** | |||
* {@link module:engine/model/document~Document Document} that owns this node or `null` if the node has no parent or is inside | |||
* a {@link module:engine/model/documentfragment~DocumentFragment DocumentFragment}. | |||
* Returns true if a node is in a tree rooted in an element of the root type. |
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.
* Returns true if a node is in a tree rooted in an element of the root type. | |
* Returns true if the node is in a tree rooted in the document | |
* (is a descendant of one of its roots). |
src/view/node.js
Outdated
@@ -109,19 +118,12 @@ export default class Node { | |||
} | |||
|
|||
/** | |||
* {@link module:engine/view/document~Document View document} that owns this node, or `null` if the node is inside | |||
* {@link module:engine/view/documentfragment~DocumentFragment document fragment}. | |||
* Returns true if a node is in a tree rooted in an element of the root type. |
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.
* Returns true if a node is in a tree rooted in an element of the root type. | |
* Returns true if the node is in a tree rooted in the document | |
* (is a descendant of one of its roots). |
src/view/placeholder.js
Outdated
|
||
// The element was removed from document. | ||
if ( !doc ) { | ||
export function needsPlaceholder( elementOrDocumentFragment ) { |
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 these changes?
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.
I can see that we should use here isAttached()
and that we don't need the type change.
src/controller/datacontroller.js
Outdated
* @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 ) { |
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:
@param {module:engine/dataprocessor/dataprocessor~DataProcessor} [dataProcessor]
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.
src/controller/datacontroller.js
Outdated
/** | ||
* Adds a style processor normalization rules. | ||
* | ||
* The available style processors: |
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.
* The available style processors: | |
* You can implement your own rules as well as use one of the available processor rules: |
src/controller/datacontroller.js
Outdated
/** | ||
* Adds a style processor normalization rules. | ||
* | ||
* The available style processors: |
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.
* The available style processors: | |
* You can implement your own rules as well as use one of the available processor rules: |
src/model/selection.js
Outdated
@@ -829,7 +829,9 @@ function isUnvisitedBlock( element, visited ) { | |||
|
|||
visited.add( element ); | |||
|
|||
return element.document.model.schema.isBlock( element ) && element.parent; | |||
const document = element.is( 'rootElement' ) ? element.document : element.root.document; |
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.
That's not necessary. element.root.document
will always work, even if element
is a root.
src/view/downcastwriter.js
Outdated
@@ -1807,7 +1810,7 @@ function breakTextNode( position ) { | |||
position.parent._data = position.parent.data.slice( 0, position.offset ); | |||
|
|||
// Insert new text node after position's parent text node. | |||
position.parent.parent._insertChild( position.parent.index + 1, new Text( textToMove ) ); | |||
position.parent.parent._insertChild( position.parent.index + 1, new Text( position.parent.document, textToMove ) ); |
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.
position.parent
is slow. position.root
will be much better here.
OK, I'm done reviewing this PR :) Now, need to check the other ones :O |
Suggested merge commit message (convention)
Other:
StylesProcessor
rules will not be stored in a singleton, which made them shared between editor instances. In order to allow binding a styles processor instance to a specific view document, we had to replace a dynamic#document
property in view nodes with a static one, set upon node creation. Closes ckeditor/ckeditor5#6091.MAJOR BREAKING CHANGES:
EditingController
requires an instance of StylesProcessor in its constructor.MAJOR BREAKING CHANGES:
DataController
requires an instance of StylesProcessor in its constructor.MAJOR BREAKING CHANGES:
DomConverter
,HtmlDataProcessor
andXmlDataProcessor
require an instance of the view document in their constructors.MAJOR BREAKING CHANGES: The
View
class requires an instance ofStylesProcessor
as its first argument.MAJOR BREAKING CHANGES: The
createViewElementFromHighlightDescriptor()
function that is exported bysrc/conversion/downcasthelpers.js
file requires an instance of the view document as its first argument.MAJOR BREAKING CHANGES: Method
view.Document#addStyleProcessorRules()
has been moved to DataController class.MINOR BREAKING CHANGES:
DataController
does not accept the data processor instance any more.MAJOR BREAKING CHANGES: The
#document
getter was removed from model nodes. Only the root element holds the reference to the model document. For attached nodes, usenode.root.document
to access it.