/**
* @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
'use strict';
import LivePosition from '../liveposition.js';
import Position from '../position.js';
import compareArrays from '../../../utils/comparearrays.js';
/**
* Delete contents of the selection and merge siblings. The resulting selection is always collapsed.
*
* @method engine.model.composer.deleteContents
* @param {engine.model.Batch} batch Batch to which the deltas will be added.
* @param {engine.model.Selection} selection Selection of which the content should be deleted.
* @param {Object} [options]
* @param {Boolean} [options.merge=false] Merge elements after removing the contents of the selection.
* For example, `
y]y
` will become: `y
` without it. */ export default function deleteContents( batch, selection, options = {} ) { if ( selection.isCollapsed ) { return; } const selRange = selection.getFirstRange(); const startPos = selRange.start; const endPos = LivePosition.createFromPosition( selRange.end ); // 1. Remove the contents if there are any. if ( !selRange.isEmpty ) { batch.remove( selRange ); } // 2. Merge elements in the right branch to the elements in the left branch. // The only reasonable (in terms of data and selection correctness) case in which we need to do that is: // //