2012-05-03 20:21:13 +00:00
|
|
|
/**
|
|
|
|
* DataModel surface.
|
2012-05-03 23:02:21 +00:00
|
|
|
*
|
2012-05-03 20:21:13 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-05-03 23:02:21 +00:00
|
|
|
* @extends {ve.EventEmitter}
|
2012-05-03 20:21:13 +00:00
|
|
|
* @param {ve.dm.Document} doc Document model to create surface for
|
|
|
|
*/
|
|
|
|
ve.dm.Surface = function( doc ) {
|
2012-05-03 23:02:21 +00:00
|
|
|
// Inheritance
|
|
|
|
ve.EventEmitter.call( this );
|
2012-05-03 20:21:13 +00:00
|
|
|
// Properties
|
|
|
|
this.documentModel = doc;
|
2012-05-03 23:02:21 +00:00
|
|
|
this.selection = null;
|
2012-05-03 20:21:13 +00:00
|
|
|
};
|
2012-05-03 23:02:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the document model of the surface.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.dm.DocumentNode} Document model of the surface
|
|
|
|
*/
|
|
|
|
ve.dm.Surface.prototype.getDocument = function() {
|
2012-05-04 22:20:14 +00:00
|
|
|
return this.documentModel;
|
2012-05-03 23:02:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the selection
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.Range} Current selection
|
|
|
|
*/
|
|
|
|
ve.dm.Surface.prototype.getSelection = function() {
|
|
|
|
return this.selection;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the selection
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.dm.Surface.prototype.setSelection = function( selection ) {
|
|
|
|
this.selection = selection;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the selection.
|
|
|
|
*
|
|
|
|
* If changing the selection at a high frequency (such as while dragging) use the combine argument
|
|
|
|
* to avoid them being split up into multiple history items
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.Range} selection
|
|
|
|
* @param {Boolean} isManual Whether this selection was the result of a user action, and thus should
|
|
|
|
* be recorded in history...?
|
|
|
|
*/
|
|
|
|
ve.dm.Surface.prototype.select = function( selection, isManual ) {
|
|
|
|
selection.normalize();
|
|
|
|
/*if (
|
|
|
|
( ! this.selection ) || ( ! this.selection.equals( selection ) )
|
|
|
|
) {*/
|
|
|
|
if ( isManual ) {
|
|
|
|
this.breakpoint();
|
|
|
|
}
|
|
|
|
// check if the last thing is a selection, if so, swap it.
|
|
|
|
this.selection = selection;
|
|
|
|
this.emit( 'select', this.selection.clone() );
|
|
|
|
//}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies a series of transactions to the content data.
|
|
|
|
*
|
|
|
|
* If committing multiple transactions which are the result of a single user action and need to be
|
|
|
|
* part of a single history item, use the isPartial argument for all but the last one to avoid them
|
|
|
|
* being split up into multple history items.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.Transaction} transactions Tranasction to apply to the document
|
|
|
|
* @param {boolean} isPartial whether this transaction is part of a larger logical grouping of
|
|
|
|
* transactions (such as when replacing - delete, then insert)
|
|
|
|
*/
|
|
|
|
ve.dm.Surface.prototype.transact = function( transaction ) {
|
|
|
|
//this.bigStack = this.bigStack.slice( 0, this.bigStack.length - this.undoIndex );
|
|
|
|
//this.undoIndex = 0;
|
|
|
|
//this.smallStack.push( transaction );
|
|
|
|
this.doc.commit( transaction );
|
|
|
|
this.emit( 'transact', transaction );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.dm.Surface, ve.EventEmitter );
|