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

Commit aea6119

Browse files
authored
Merge pull request #1215 from ckeditor/t/1208
Other: Cleaned up the model, document and controllers API. Closes #1208.
2 parents a8e0f37 + f864e43 commit aea6119

File tree

14 files changed

+598
-619
lines changed

14 files changed

+598
-619
lines changed

src/controller/datacontroller.js

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ import { convertText, convertToModelFragment } from '../conversion/view-to-model
2121
import ViewDocumentFragment from '../view/documentfragment';
2222

2323
import ModelRange from '../model/range';
24-
import ModelElement from '../model/element';
25-
26-
import insertContent from './insertcontent';
27-
import deleteContent from './deletecontent';
28-
import modifySelection from './modifyselection';
29-
import getSelectedContent from './getselectedcontent';
3024

3125
/**
3226
* Controller for the data pipeline. The data pipeline controls how data is retrieved from the document
@@ -116,9 +110,6 @@ export default class DataController {
116110
this.viewToModel.on( 'text', convertText(), { priority: 'lowest' } );
117111
this.viewToModel.on( 'element', convertToModelFragment(), { priority: 'lowest' } );
118112
this.viewToModel.on( 'documentFragment', convertToModelFragment(), { priority: 'lowest' } );
119-
120-
[ 'insertContent', 'deleteContent', 'modifySelection', 'getSelectedContent' ]
121-
.forEach( methodName => this.decorate( methodName ) );
122113
}
123114

124115
/**
@@ -240,126 +231,6 @@ export default class DataController {
240231
* Removes all event listeners set by the DataController.
241232
*/
242233
destroy() {}
243-
244-
/**
245-
* See {@link module:engine/controller/insertcontent.insertContent}.
246-
*
247-
* @fires insertContent
248-
* @param {module:engine/model/documentfragment~DocumentFragment|module:engine/model/item~Item} content The content to insert.
249-
* @param {module:engine/model/selection~Selection} selection Selection into which the content should be inserted.
250-
*/
251-
insertContent( content, selection ) {
252-
insertContent( this, content, selection );
253-
}
254-
255-
/**
256-
* See {@link module:engine/controller/deletecontent.deleteContent}.
257-
*
258-
* Note: For the sake of predictability, the resulting selection should always be collapsed.
259-
* In cases where a feature wants to modify deleting behavior so selection isn't collapsed
260-
* (e.g. a table feature may want to keep row selection after pressing <kbd>Backspace</kbd>),
261-
* then that behavior should be implemented in the view's listener. At the same time, the table feature
262-
* will need to modify this method's behavior too, e.g. to "delete contents and then collapse
263-
* the selection inside the last selected cell" or "delete the row and collapse selection somewhere near".
264-
* That needs to be done in order to ensure that other features which use `deleteContent()` will work well with tables.
265-
*
266-
* @fires deleteContent
267-
* @param {module:engine/model/selection~Selection} selection Selection of which the content should be deleted.
268-
* @param {Object} options See {@link module:engine/controller/deletecontent~deleteContent}'s options.
269-
*/
270-
deleteContent( selection, options ) {
271-
deleteContent( this, selection, options );
272-
}
273-
274-
/**
275-
* See {@link module:engine/controller/modifyselection.modifySelection}.
276-
*
277-
* @fires modifySelection
278-
* @param {module:engine/model/selection~Selection} selection The selection to modify.
279-
* @param {Object} options See {@link module:engine/controller/modifyselection~modifySelection}'s options.
280-
*/
281-
modifySelection( selection, options ) {
282-
modifySelection( this, selection, options );
283-
}
284-
285-
/**
286-
* See {@link module:engine/controller/getselectedcontent.getSelectedContent}.
287-
*
288-
* @fires module:engine/controller/datacontroller~DataController#getSelectedContent
289-
* @param {module:engine/model/selection~Selection} selection The selection of which content will be retrieved.
290-
* @returns {module:engine/model/documentfragment~DocumentFragment} Document fragment holding the clone of the selected content.
291-
*/
292-
getSelectedContent( selection ) {
293-
return getSelectedContent( this, selection );
294-
}
295-
296-
/**
297-
* Checks whether given {@link module:engine/model/range~Range range} or {@link module:engine/model/element~Element element}
298-
* has any content.
299-
*
300-
* Content is any text node or element which is registered in {@link module:engine/model/schema~Schema schema}.
301-
*
302-
* @param {module:engine/model/range~Range|module:engine/model/element~Element} rangeOrElement Range or element to check.
303-
* @returns {Boolean}
304-
*/
305-
hasContent( rangeOrElement ) {
306-
if ( rangeOrElement instanceof ModelElement ) {
307-
rangeOrElement = ModelRange.createIn( rangeOrElement );
308-
}
309-
310-
if ( rangeOrElement.isCollapsed ) {
311-
return false;
312-
}
313-
314-
for ( const item of rangeOrElement.getItems() ) {
315-
// Remember, `TreeWalker` returns always `textProxy` nodes.
316-
if ( item.is( 'textProxy' ) || this.model.schema.objects.has( item.name ) ) {
317-
return true;
318-
}
319-
}
320-
321-
return false;
322-
}
323234
}
324235

325236
mix( DataController, ObservableMixin );
326-
327-
/**
328-
* Event fired when {@link #insertContent} method is called.
329-
*
330-
* The {@link #insertContent default action of that method} is implemented as a
331-
* listener to this event so it can be fully customized by the features.
332-
*
333-
* @event insertContent
334-
* @param {Array} args The arguments passed to the original method.
335-
*/
336-
337-
/**
338-
* Event fired when {@link #deleteContent} method is called.
339-
*
340-
* The {@link #deleteContent default action of that method} is implemented as a
341-
* listener to this event so it can be fully customized by the features.
342-
*
343-
* @event deleteContent
344-
* @param {Array} args The arguments passed to the original method.
345-
*/
346-
347-
/**
348-
* Event fired when {@link #modifySelection} method is called.
349-
*
350-
* The {@link #modifySelection default action of that method} is implemented as a
351-
* listener to this event so it can be fully customized by the features.
352-
*
353-
* @event modifySelection
354-
* @param {Array} args The arguments passed to the original method.
355-
*/
356-
357-
/**
358-
* Event fired when {@link #getSelectedContent} method is called.
359-
*
360-
* The {@link #getSelectedContent default action of that method} is implemented as a
361-
* listener to this event so it can be fully customized by the features.
362-
*
363-
* @event getSelectedContent
364-
* @param {Array} args The arguments passed to the original method.
365-
*/

src/model/document.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@
77
* @module engine/model/document
88
*/
99

10-
// Load all basic deltas and transformations, they register themselves.
11-
import './delta/basic-deltas';
12-
import './delta/basic-transformations';
13-
1410
import Range from './range';
1511
import Position from './position';
1612
import RootElement from './rootelement';
1713
import History from './history';
1814
import DocumentSelection from './documentselection';
1915
import TreeWalker from './treewalker';
20-
import deltaTransform from './delta/transform';
2116
import clone from '@ckeditor/ckeditor5-utils/src/lib/lodash/clone';
2217
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
2318
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
@@ -283,26 +278,6 @@ export default class Document {
283278
return null;
284279
}
285280

286-
/**
287-
* Transforms two sets of deltas by themselves. Returns both transformed sets.
288-
*
289-
* @param {Array.<module:engine/model/delta/delta~Delta>} deltasA Array with the first set of deltas to transform. These
290-
* deltas are considered more important (than `deltasB`) when resolving conflicts.
291-
* @param {Array.<module:engine/model/delta/delta~Delta>} deltasB Array with the second set of deltas to transform. These
292-
* deltas are considered less important (than `deltasA`) when resolving conflicts.
293-
* @param {Boolean} [useContext=false] When set to `true`, transformation will store and use additional context
294-
* information to guarantee more expected results. Should be used whenever deltas related to already applied
295-
* deltas are transformed (for example when undoing changes).
296-
* @returns {Object}
297-
* @returns {Array.<module:engine/model/delta/delta~Delta>} return.deltasA The first set of deltas transformed
298-
* by the second set of deltas.
299-
* @returns {Array.<module:engine/model/delta/delta~Delta>} return.deltasB The second set of deltas transformed
300-
* by the first set of deltas.
301-
*/
302-
transformDeltas( deltasA, deltasB, useContext = false ) {
303-
return deltaTransform.transformDeltaSets( deltasA, deltasB, useContext ? this : null );
304-
}
305-
306281
/**
307282
* Custom toJSON method to solve child-parent circular dependencies.
308283
*

0 commit comments

Comments
 (0)