/*! * VisualEditor IndentationAction class. * * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ /** * Indentation action. * * @class * @extends ve.Action * @constructor * @param {ve.Surface} surface Surface to act on */ ve.IndentationAction = function VeIndentationAction( surface ) { // Parent constructor ve.Action.call( this, surface ); }; /* Inheritance */ ve.inheritClass( ve.IndentationAction, ve.Action ); /* Static Properties */ /** * List of allowed methods for the action. * * @static * @property */ ve.IndentationAction.static.methods = ['increase', 'decrease']; /* Methods */ /** * Indent content. * * TODO: Refactor functionality into {ve.dm.SurfaceFragment}. * * @method * @returns {boolean} Indentation increase occured */ ve.IndentationAction.prototype.increase = function () { var i, group, fragments = [], increased = false, surfaceModel = this.surface.getModel(), documentModel = surfaceModel.getDocument(), selected = surfaceModel.getFragment(), groups = documentModel.getCoveredSiblingGroups( selected.getRange() ); // Build fragments from groups (we need their ranges since the nodes will be rebuilt on change) for ( i = 0; i < groups.length; i++ ) { group = groups[i]; if ( group.grandparent && group.grandparent.getType() === 'list' ) { fragments.push( surfaceModel.getFragment( group.parent.getRange(), true ) ); increased = true; } } // Process each fragment (their ranges are automatically adjusted on change) for ( i = 0; i < fragments.length; i++ ) { this.indentListItem( documentModel.getNodeFromOffset( fragments[i].getRange().start ) ); } selected.select(); return increased; }; /** * Unindent content. * * TODO: Refactor functionality into {ve.dm.SurfaceFragment}. * * @method * @returns {boolean} Indentation decrease occured */ ve.IndentationAction.prototype.decrease = function () { var i, group, fragments = [], decreased = false, surfaceModel = this.surface.getModel(), documentModel = surfaceModel.getDocument(), selected = surfaceModel.getFragment(), groups = documentModel.getCoveredSiblingGroups( selected.getRange() ); // Build fragments from groups (we need their ranges since the nodes will be rebuilt on change) for ( i = 0; i < groups.length; i++ ) { group = groups[i]; if ( group.grandparent && group.grandparent.getType() === 'list' ) { fragments.push( surfaceModel.getFragment( group.parent.getRange(), true ) ); decreased = true; } } // Process each fragment (their ranges are automatically adjusted on change) for ( i = 0; i < fragments.length; i++ ) { this.unindentListItem( documentModel.getNodeFromOffset( fragments[i].getRange().start ) ); } selected.select(); return decreased; }; /** * Indent a list item. * * TODO: Refactor functionality into {ve.dm.SurfaceFragment}. * * @method * @param {ve.dm.ListItemNode} listItem List item to indent * @throws {Error} listItem must be a ve.dm.ListItemNode */ ve.IndentationAction.prototype.indentListItem = function ( listItem ) { if ( !( listItem instanceof ve.dm.ListItemNode ) ) { throw new Error( 'listItem must be a ve.dm.ListItemNode' ); } /* * Indenting a list item is done as follows: * 1. Wrap the listItem in a list and a listItem (
  • -->