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

Commit

Permalink
Merge 2ef1319 into a8e0f37
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Dec 21, 2017
2 parents a8e0f37 + 2ef1319 commit 430f12c
Show file tree
Hide file tree
Showing 14 changed files with 594 additions and 615 deletions.
129 changes: 0 additions & 129 deletions src/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ import { convertText, convertToModelFragment } from '../conversion/view-to-model
import ViewDocumentFragment from '../view/documentfragment';

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

import insertContent from './insertcontent';
import deleteContent from './deletecontent';
import modifySelection from './modifyselection';
import getSelectedContent from './getselectedcontent';

/**
* Controller for the data pipeline. The data pipeline controls how data is retrieved from the document
Expand Down Expand Up @@ -116,9 +110,6 @@ export default class DataController {
this.viewToModel.on( 'text', convertText(), { priority: 'lowest' } );
this.viewToModel.on( 'element', convertToModelFragment(), { priority: 'lowest' } );
this.viewToModel.on( 'documentFragment', convertToModelFragment(), { priority: 'lowest' } );

[ 'insertContent', 'deleteContent', 'modifySelection', 'getSelectedContent' ]
.forEach( methodName => this.decorate( methodName ) );
}

/**
Expand Down Expand Up @@ -240,126 +231,6 @@ export default class DataController {
* Removes all event listeners set by the DataController.
*/
destroy() {}

/**
* See {@link module:engine/controller/insertcontent.insertContent}.
*
* @fires insertContent
* @param {module:engine/model/documentfragment~DocumentFragment|module:engine/model/item~Item} content The content to insert.
* @param {module:engine/model/selection~Selection} selection Selection into which the content should be inserted.
*/
insertContent( content, selection ) {
insertContent( this, content, selection );
}

/**
* See {@link module:engine/controller/deletecontent.deleteContent}.
*
* Note: For the sake of predictability, the resulting selection should always be collapsed.
* In cases where a feature wants to modify deleting behavior so selection isn't collapsed
* (e.g. a table feature may want to keep row selection after pressing <kbd>Backspace</kbd>),
* then that behavior should be implemented in the view's listener. At the same time, the table feature
* will need to modify this method's behavior too, e.g. to "delete contents and then collapse
* the selection inside the last selected cell" or "delete the row and collapse selection somewhere near".
* That needs to be done in order to ensure that other features which use `deleteContent()` will work well with tables.
*
* @fires deleteContent
* @param {module:engine/model/selection~Selection} selection Selection of which the content should be deleted.
* @param {Object} options See {@link module:engine/controller/deletecontent~deleteContent}'s options.
*/
deleteContent( selection, options ) {
deleteContent( this, selection, options );
}

/**
* See {@link module:engine/controller/modifyselection.modifySelection}.
*
* @fires modifySelection
* @param {module:engine/model/selection~Selection} selection The selection to modify.
* @param {Object} options See {@link module:engine/controller/modifyselection~modifySelection}'s options.
*/
modifySelection( selection, options ) {
modifySelection( this, selection, options );
}

/**
* See {@link module:engine/controller/getselectedcontent.getSelectedContent}.
*
* @fires module:engine/controller/datacontroller~DataController#getSelectedContent
* @param {module:engine/model/selection~Selection} selection The selection of which content will be retrieved.
* @returns {module:engine/model/documentfragment~DocumentFragment} Document fragment holding the clone of the selected content.
*/
getSelectedContent( selection ) {
return getSelectedContent( this, selection );
}

/**
* Checks whether given {@link module:engine/model/range~Range range} or {@link module:engine/model/element~Element element}
* has any content.
*
* Content is any text node or element which is registered in {@link module:engine/model/schema~Schema schema}.
*
* @param {module:engine/model/range~Range|module:engine/model/element~Element} rangeOrElement Range or element to check.
* @returns {Boolean}
*/
hasContent( rangeOrElement ) {
if ( rangeOrElement instanceof ModelElement ) {
rangeOrElement = ModelRange.createIn( rangeOrElement );
}

if ( rangeOrElement.isCollapsed ) {
return false;
}

for ( const item of rangeOrElement.getItems() ) {
// Remember, `TreeWalker` returns always `textProxy` nodes.
if ( item.is( 'textProxy' ) || this.model.schema.objects.has( item.name ) ) {
return true;
}
}

return false;
}
}

mix( DataController, ObservableMixin );

/**
* Event fired when {@link #insertContent} method is called.
*
* The {@link #insertContent default action of that method} is implemented as a
* listener to this event so it can be fully customized by the features.
*
* @event insertContent
* @param {Array} args The arguments passed to the original method.
*/

/**
* Event fired when {@link #deleteContent} method is called.
*
* The {@link #deleteContent default action of that method} is implemented as a
* listener to this event so it can be fully customized by the features.
*
* @event deleteContent
* @param {Array} args The arguments passed to the original method.
*/

/**
* Event fired when {@link #modifySelection} method is called.
*
* The {@link #modifySelection default action of that method} is implemented as a
* listener to this event so it can be fully customized by the features.
*
* @event modifySelection
* @param {Array} args The arguments passed to the original method.
*/

/**
* Event fired when {@link #getSelectedContent} method is called.
*
* The {@link #getSelectedContent default action of that method} is implemented as a
* listener to this event so it can be fully customized by the features.
*
* @event getSelectedContent
* @param {Array} args The arguments passed to the original method.
*/
25 changes: 0 additions & 25 deletions src/model/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
* @module engine/model/document
*/

// Load all basic deltas and transformations, they register themselves.
import './delta/basic-deltas';
import './delta/basic-transformations';

import Range from './range';
import Position from './position';
import RootElement from './rootelement';
import History from './history';
import DocumentSelection from './documentselection';
import TreeWalker from './treewalker';
import deltaTransform from './delta/transform';
import clone from '@ckeditor/ckeditor5-utils/src/lib/lodash/clone';
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
Expand Down Expand Up @@ -283,26 +278,6 @@ export default class Document {
return null;
}

/**
* Transforms two sets of deltas by themselves. Returns both transformed sets.
*
* @param {Array.<module:engine/model/delta/delta~Delta>} deltasA Array with the first set of deltas to transform. These
* deltas are considered more important (than `deltasB`) when resolving conflicts.
* @param {Array.<module:engine/model/delta/delta~Delta>} deltasB Array with the second set of deltas to transform. These
* deltas are considered less important (than `deltasA`) when resolving conflicts.
* @param {Boolean} [useContext=false] When set to `true`, transformation will store and use additional context
* information to guarantee more expected results. Should be used whenever deltas related to already applied
* deltas are transformed (for example when undoing changes).
* @returns {Object}
* @returns {Array.<module:engine/model/delta/delta~Delta>} return.deltasA The first set of deltas transformed
* by the second set of deltas.
* @returns {Array.<module:engine/model/delta/delta~Delta>} return.deltasB The second set of deltas transformed
* by the first set of deltas.
*/
transformDeltas( deltasA, deltasB, useContext = false ) {
return deltaTransform.transformDeltaSets( deltasA, deltasB, useContext ? this : null );
}

/**
* Custom toJSON method to solve child-parent circular dependencies.
*
Expand Down
Loading

0 comments on commit 430f12c

Please sign in to comment.