Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

View refactoring #1296

Merged
merged 103 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
eb76e20
Changed wirter utility functions to class methods.
szymonkups Jan 11, 2018
5639b6a
Fixed view writer tests.
szymonkups Jan 11, 2018
868d2aa
Initial view controller skeleton.
szymonkups Jan 11, 2018
5223afc
Moving responsibilites from view document to view controller.
szymonkups Jan 12, 2018
cde89ab
Merge branch 'master' into t/1210
szymonkups Jan 12, 2018
b53613f
Moved all DOM related functionality from view document to view contro…
szymonkups Jan 12, 2018
73677b6
More things moved from view document to view controller. Added event.
szymonkups Jan 12, 2018
a3cb217
Cleaned tests of view document.
szymonkups Jan 12, 2018
2b36519
Refactored observers' tests.
szymonkups Jan 15, 2018
3735a66
Fixed view controller tests.
szymonkups Jan 15, 2018
de945bb
Fixed tests with placeholder.
szymonkups Jan 16, 2018
ebe4922
Fixed view Position test.
szymonkups Jan 16, 2018
e8c7f75
Fixed view Selection test.
szymonkups Jan 16, 2018
1025f01
Fixed view TreeWalker test.
szymonkups Jan 16, 2018
c8dee0c
Fixed conversion tests.
szymonkups Jan 16, 2018
eb3290d
Fixed dev utils tests.
szymonkups Jan 16, 2018
e7f0ba9
Controller fixes.
szymonkups Jan 16, 2018
19af78b
Adjusting ticket test to changes in view.
szymonkups Jan 16, 2018
29a2e0a
Merge branch 'master' into t/1210
szymonkups Jan 16, 2018
25b9f6b
Merge branch 'master' into t/1210
szymonkups Jan 18, 2018
8eb46b1
Passing view writer with conversion API.
szymonkups Jan 18, 2018
6de4eff
Removed view and change() block from ModelConversionDispatcher. Now w…
szymonkups Jan 19, 2018
c4d1a6c
Merge branch 'master' into t/1210
szymonkups Jan 19, 2018
7eaa1ba
Moving model to view selection conversion into view.change block.
szymonkups Jan 22, 2018
0e04c07
Merge branch 'master' into t/1210
szymonkups Jan 22, 2018
1737084
Changed view utils methods to accept view instance instead of view do…
szymonkups Jan 22, 2018
5d9fcc5
Fixed docs after view controller creation.
szymonkups Jan 23, 2018
1aab5c8
Added creator methods to view writer.
szymonkups Jan 25, 2018
1ceb15f
Added view instance to writer. Fixed placeholder update listener.
szymonkups Jan 26, 2018
cfddbb1
Added one more test to placeholder.
szymonkups Jan 26, 2018
a78fe24
Added empty view writer test file.
szymonkups Jan 29, 2018
767bf2c
Merge branch 'master' into t/1210
szymonkups Jan 29, 2018
6d622c7
Moved view selection method access to view writer.
szymonkups Jan 29, 2018
b8c2bde
Fixed tests after view selection methods visibility change.
szymonkups Jan 29, 2018
142775f
Changed view selection setFake method as protected. Created view writ…
szymonkups Jan 30, 2018
f427bb2
Removed view selection from conversionApi, it can be accessed by writ…
szymonkups Jan 30, 2018
f91150e
Removed view selection parameter from view writer.wrap() method.
szymonkups Jan 30, 2018
9662257
Using view.change in dev-utils tests instead of modifing selection di…
szymonkups Jan 30, 2018
69f154f
Using view.change in placeholder tests instead of modifing selection …
szymonkups Jan 30, 2018
f5b9b68
Updated fake selection manual test to work with view changes.
szymonkups Jan 30, 2018
72356b4
Using view.change in focusobserver tests instead of modifing selectio…
szymonkups Jan 30, 2018
9feacdf
Using view.change in mutationobserver tests instead of modifing selec…
szymonkups Jan 30, 2018
9435e48
Using view.change in selectionobserver tests instead of modifing sele…
szymonkups Jan 30, 2018
8a00bcb
More test updated to use view writer.change() block.
szymonkups Jan 30, 2018
4ed39d2
Using writer to set fake selection in model selection to view convert…
szymonkups Jan 31, 2018
7269c08
Merge branch 'master' into t/1210
szymonkups Feb 1, 2018
ec7db7d
Merge branch 'master' into t/1210
szymonkups Feb 1, 2018
4b9e98c
Merge branch 'master' into t/1210
szymonkups Feb 1, 2018
9de3ace
Align manual tests to latest changes in the view.
szymonkups Feb 5, 2018
44580b5
Using setData in manual tests.
szymonkups Feb 5, 2018
80d346a
Using correct initialization on iframe manual test.
szymonkups Feb 5, 2018
cbe9a51
Changed EditableElement test to check if selection changes affects it…
szymonkups Feb 6, 2018
ae4b9a9
Added docs and tests to engine view controller.
szymonkups Feb 6, 2018
b1f8d21
Fixed docs.
szymonkups Feb 6, 2018
21f0dba
Merge branch 'master' into t/1210
szymonkups Feb 6, 2018
1d81921
Merge branch 'master' into t/1210
szymonkups Feb 6, 2018
2fd9058
Removed empty file.
szymonkups Feb 6, 2018
cacae9f
Updated documentation.
szymonkups Feb 7, 2018
deac6a1
Improved view writer's code coverage.
szymonkups Feb 7, 2018
3f9b87a
Removed default params from view writer.setFakeSelection() method.
szymonkups Feb 7, 2018
ad06c37
Merge branch 'master' into t/1210
szymonkups Feb 8, 2018
b962a48
Small docs fixes.
szymonkups Feb 9, 2018
7ec6f8a
Merge branch 'master' into t/1210
szymonkups Feb 9, 2018
199be4a
More fixes to tests after changes in the view.
szymonkups Feb 9, 2018
181f113
Updated downcast converters to use view writer where possible.
szymonkups Feb 11, 2018
fa87b53
More downcast conversion changes connected to view refactoring.
szymonkups Feb 11, 2018
b361fd6
Passing all conversion parameters to creator from array confing.
szymonkups Feb 12, 2018
1e46743
Fixed typos.
szymonkups Feb 13, 2018
983ce9b
Unified usage of view.Writer in converters.
szymonkups Feb 13, 2018
75d1d07
Fixed docs in view.Writer.
szymonkups Feb 13, 2018
85ae406
Removed unused view selection from writer.wrap(). call.
szymonkups Feb 13, 2018
b4e5273
Removed writer.createElement() method.
szymonkups Feb 13, 2018
3a546da
Using writer to set attribute on view element.
szymonkups Feb 13, 2018
85c3400
Using writer to remove attribute from view element.
szymonkups Feb 13, 2018
ad65a63
Using writer to set class on view element.
szymonkups Feb 13, 2018
d1d022c
Using writer to remove class from view element.
szymonkups Feb 13, 2018
8c8a4c5
Using writer to set styles to view element.
szymonkups Feb 13, 2018
c4c4d3d
Using writer to remove styles from view element.
szymonkups Feb 13, 2018
4041eb0
Using writer to set custom properties to view element.
szymonkups Feb 13, 2018
01ce914
Using writer to remove custom properties from view element.
szymonkups Feb 13, 2018
cefdba4
AttributeElement priority is now protected. EditableElement document …
szymonkups Feb 13, 2018
d4fe28f
View writer.createUIElement() method can now initialize rendering met…
szymonkups Feb 13, 2018
833b81f
Updated view writer's docs.
szymonkups Feb 13, 2018
3f110de
Added tests to new methods in view writer.
szymonkups Feb 13, 2018
5b1a8bd
Updated placeholder to use view writer to manipulate view nodes.
szymonkups Feb 13, 2018
7d321b7
Using writer in highlight manual test.
szymonkups Feb 14, 2018
2b923bb
Removed view.jsdoc file.
szymonkups Feb 14, 2018
a576a0a
Get rid of view.document#change event and rednerer#render events. Cre…
szymonkups Feb 14, 2018
6242b77
Added comment do DataController why we use view writer without change…
szymonkups Feb 14, 2018
d4a8844
Some docs changes in view writer.
szymonkups Feb 14, 2018
ce0cca4
Moved model.change() block out of upcast dispatcher.
szymonkups Feb 14, 2018
9d11c64
Docs: View class overview. [skip ci]
Feb 14, 2018
27c7906
Get rid of model parameter from downcast dispatcher.
szymonkups Feb 14, 2018
f63f2a1
Passing writer to highlight methods.
szymonkups Feb 14, 2018
226a96a
Merge branch 'master' into t/1210
szymonkups Feb 15, 2018
b1580a0
Updated highlighting manual test.
szymonkups Feb 15, 2018
4b33b87
Fixed nested editable manual test.
szymonkups Feb 15, 2018
5ac0d62
Updated manual test for ckeditor5-721.
szymonkups Feb 15, 2018
b119088
Updated fake selection manual test.
szymonkups Feb 15, 2018
61edf03
Updated UIElement manual test.
szymonkups Feb 15, 2018
47371da
Fixed docs.
szymonkups Feb 15, 2018
08eb9c9
Removed unneeded code.
Feb 16, 2018
8a07e76
Docs: use proper writer methods.
Feb 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import UpcastDispatcher from '../conversion/upcastdispatcher';
import { convertText, convertToModelFragment } from '../conversion/upcast-converters';

import ViewDocumentFragment from '../view/documentfragment';
import ViewDocument from '../view/document';
import ViewWriter from '../view/writer';

import ModelRange from '../model/range';

Expand Down Expand Up @@ -74,7 +76,7 @@ export default class DataController {
* @readonly
* @member {module:engine/conversion/downcastdispatcher~DowncastDispatcher}
*/
this.downcastDispatcher = new DowncastDispatcher( this.model, {
this.downcastDispatcher = new DowncastDispatcher( {
mapper: this.mapper
} );
this.downcastDispatcher.on( 'insert:$text', insertText(), { priority: 'lowest' } );
Expand All @@ -85,7 +87,7 @@ export default class DataController {
* @readonly
* @member {module:engine/conversion/upcastdispatcher~UpcastDispatcher}
*/
this.upcastDispatcher = new UpcastDispatcher( this.model, {
this.upcastDispatcher = new UpcastDispatcher( {
schema: model.schema
} );

Expand Down Expand Up @@ -143,17 +145,21 @@ export default class DataController {
const modelRange = ModelRange.createIn( modelElementOrFragment );

const viewDocumentFragment = new ViewDocumentFragment();

// Create separate ViewWriter 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 ViewWriter( new ViewDocument() );
this.mapper.bindElements( modelElementOrFragment, viewDocumentFragment );

this.downcastDispatcher.convertInsert( modelRange );
this.downcastDispatcher.convertInsert( modelRange, viewWriter );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make it symmetrical. Since downcastDispatcher do not have view as a property and change is called outside, upcastDispatcher may have no model and also get writer as a parameter.


if ( !modelElementOrFragment.is( 'documentFragment' ) ) {
// Then, if a document element is converted, convert markers.
// From all document markers, get those, which "intersect" with the converter element.
const markers = _getMarkersRelativeToElement( modelElementOrFragment );

for ( const [ name, range ] of markers ) {
this.downcastDispatcher.convertMarkerAdd( name, range );
this.downcastDispatcher.convertMarkerAdd( name, range, viewWriter );
}
}

Expand Down Expand Up @@ -221,7 +227,9 @@ export default class DataController {
* @returns {module:engine/model/documentfragment~DocumentFragment} Output document fragment.
*/
toModel( viewElementOrFragment, context = '$root' ) {
return this.upcastDispatcher.convert( viewElementOrFragment, context );
return this.model.change( writer => {
return this.upcastDispatcher.convert( viewElementOrFragment, writer, context );
} );
}

/**
Expand Down
39 changes: 21 additions & 18 deletions src/controller/editingcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import RootEditableElement from '../view/rooteditableelement';
import ViewDocument from '../view/document';
import View from '../view/view';
import Mapper from '../conversion/mapper';
import DowncastDispatcher from '../conversion/downcastdispatcher';
import {
Expand Down Expand Up @@ -49,12 +49,12 @@ export default class EditingController {
this.model = model;

/**
* View document.
* Editing view controller.
*
* @readonly
* @member {module:engine/view/document~Document}
* @member {module:engine/view/view~View}
*/
this.view = new ViewDocument();
this.view = new View();

/**
* Mapper which describes the model-view binding.
Expand All @@ -70,24 +70,23 @@ export default class EditingController {
* @readonly
* @member {module:engine/conversion/downcastdispatcher~DowncastDispatcher} #downcastDispatcher
*/
this.downcastDispatcher = new DowncastDispatcher( this.model, {
mapper: this.mapper,
viewSelection: this.view.selection
this.downcastDispatcher = new DowncastDispatcher( {
mapper: this.mapper
} );

const doc = this.model.document;
const selection = doc.selection;
const markers = this.model.markers;

this.listenTo( doc, 'change', () => {
this.downcastDispatcher.convertChanges( doc.differ );
}, { priority: 'low' } );

this.listenTo( model, '_change', () => {
this.downcastDispatcher.convertSelection( doc.selection );
this.view.render();
this.view.change( writer => {
this.downcastDispatcher.convertChanges( doc.differ, writer );
this.downcastDispatcher.convertSelection( selection, markers, writer );
} );
}, { priority: 'low' } );

// Convert selection from view to model.
this.listenTo( this.view, 'selectionChange', convertSelectionChange( this.model, this.mapper ) );
this.listenTo( this.view.document, 'selectionChange', convertSelectionChange( this.model, this.mapper ) );

// Attach default model converters.
this.downcastDispatcher.on( 'insert:$text', insertText(), { priority: 'lowest' } );
Expand Down Expand Up @@ -122,7 +121,9 @@ export default class EditingController {
if ( _operationAffectsMarker( operation, marker ) ) {
// And if the operation in any way modifies the marker, remove the marker from the view.
removedMarkers.add( marker.name );
this.downcastDispatcher.convertMarkerRemove( marker.name, markerRange );
this.view.change( writer => {
this.downcastDispatcher.convertMarkerRemove( marker.name, markerRange, writer );
} );

// TODO: This stinks but this is the safest place to have this code.
this.model.document.differ.bufferMarkerChange( marker.name, markerRange, markerRange );
Expand All @@ -135,7 +136,9 @@ export default class EditingController {
this.listenTo( model.markers, 'remove', ( evt, marker ) => {
if ( !removedMarkers.has( marker.name ) ) {
removedMarkers.add( marker.name );
this.downcastDispatcher.convertMarkerRemove( marker.name, marker.getRange() );
this.view.change( writer => {
this.downcastDispatcher.convertMarkerRemove( marker.name, marker.getRange(), writer );
} );
}
} );

Expand All @@ -147,7 +150,7 @@ export default class EditingController {
// Binds {@link module:engine/view/document~Document#roots view roots collection} to
// {@link module:engine/model/document~Document#roots model roots collection} so creating
// model root automatically creates corresponding view root.
this.view.roots.bindTo( this.model.document.roots ).using( root => {
this.view.document.roots.bindTo( this.model.document.roots ).using( root => {
// $graveyard is a special root that has no reflection in the view.
if ( root.rootName == '$graveyard' ) {
return null;
Expand All @@ -156,7 +159,7 @@ export default class EditingController {
const viewRoot = new RootEditableElement( root.name );

viewRoot.rootName = root.rootName;
viewRoot.document = this.view;
viewRoot._document = this.view.document;
this.mapper.bindElements( root, viewRoot );

return viewRoot;
Expand Down
Loading