/** * VisualEditor IndentationAction class. * * @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ /** * Indentation action. * * @class * @constructor * @extends {ve.Action} * @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 Members */ /** * List of allowed methods for this action. * * @static * @member */ ve.IndentationAction.static.methods = ['increase', 'decrease']; /* Methods */ /** * Increases indentation level. * * 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.getOuterRange(), 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 + 1 ) ); } selected.select(); return increased; }; /** * Decreses indentation level. * * 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.getOuterRange(), true ) ); decreased = true; } } // Process each fragment (their ranges are automatically adjusted on change) for ( i = 0; i < fragments.length; i++ ) { this.outdentListItem( documentModel.getNodeFromOffset( fragments[i].getRange().start + 1 ) ); } selected.select(); return decreased; }; /** * TODO: Refactor functionality into {ve.dm.SurfaceFragment}. */ ve.IndentationAction.prototype.indentListItem = function ( listItem ) { /* * Indenting a list item is done as follows: * 1. Wrap the listItem in a list and a listItem (
  • -->