|
@@ -9,6 +9,8 @@
|
|
|
|
|
|
|
|
import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
|
import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
|
|
import Selection from '@ckeditor/ckeditor5-engine/src/model/selection';
|
|
|
|
|
+import Element from '@ckeditor/ckeditor5-engine/src/model/element';
|
|
|
|
|
+import Position from '@ckeditor/ckeditor5-engine/src/model/position';
|
|
|
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
|
import ChangeBuffer from './changebuffer';
|
|
import ChangeBuffer from './changebuffer';
|
|
|
import count from '@ckeditor/ckeditor5-utils/src/count';
|
|
import count from '@ckeditor/ckeditor5-utils/src/count';
|
|
@@ -106,11 +108,9 @@ export default class DeleteCommand extends Command {
|
|
|
*
|
|
*
|
|
|
* But, if the user pressed and released the key, we want to replace the entire content with a paragraph if:
|
|
* But, if the user pressed and released the key, we want to replace the entire content with a paragraph if:
|
|
|
*
|
|
*
|
|
|
- * * the entire content is selected,
|
|
|
|
|
- * * the paragraph is allowed in the common ancestor,
|
|
|
|
|
- * * other paragraph does not occur in the editor.
|
|
|
|
|
- *
|
|
|
|
|
- * Rest of the checks are done in {@link module:engine/controller/datacontroller~DataController#deleteContent} method.
|
|
|
|
|
|
|
+ * * the entire content is selected,
|
|
|
|
|
+ * * the paragraph is allowed in the common ancestor,
|
|
|
|
|
+ * * other paragraph does not occur in the editor.
|
|
|
*
|
|
*
|
|
|
* @private
|
|
* @private
|
|
|
* @param {Number} sequence A number describing which subsequent delete event it is without the key being released.
|
|
* @param {Number} sequence A number describing which subsequent delete event it is without the key being released.
|
|
@@ -124,10 +124,23 @@ export default class DeleteCommand extends Command {
|
|
|
|
|
|
|
|
const document = this.editor.document;
|
|
const document = this.editor.document;
|
|
|
const selection = document.selection;
|
|
const selection = document.selection;
|
|
|
- const commonAncestor = selection.getFirstRange().getCommonAncestor();
|
|
|
|
|
|
|
+ const limitElement = getLimitElement( document.schema, selection );
|
|
|
|
|
+ const limitStartPosition = Position.createAt( limitElement );
|
|
|
|
|
+ const limitEndPosition = Position.createAt( limitElement, 'end' );
|
|
|
|
|
+
|
|
|
|
|
+ if (
|
|
|
|
|
+ !limitStartPosition.isTouching( selection.getFirstPosition() ) ||
|
|
|
|
|
+ !limitEndPosition.isTouching( selection.getLastPosition() )
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ( !document.schema.check( { name: 'paragraph', inside: limitElement.name } ) ) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Does nothing if editor already contains an empty paragraph.
|
|
// Does nothing if editor already contains an empty paragraph.
|
|
|
- if ( commonAncestor.name === 'paragraph' ) {
|
|
|
|
|
|
|
+ if ( selection.getFirstRange().getCommonAncestor().name === 'paragraph' ) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -140,13 +153,15 @@ export default class DeleteCommand extends Command {
|
|
|
* @private
|
|
* @private
|
|
|
*/
|
|
*/
|
|
|
_replaceEntireContentWithParagraph() {
|
|
_replaceEntireContentWithParagraph() {
|
|
|
- const editor = this.editor;
|
|
|
|
|
- const document = editor.document;
|
|
|
|
|
|
|
+ const document = this.editor.document;
|
|
|
const selection = document.selection;
|
|
const selection = document.selection;
|
|
|
const limitElement = getLimitElement( document.schema, selection );
|
|
const limitElement = getLimitElement( document.schema, selection );
|
|
|
|
|
+ const paragraph = new Element( 'paragraph' );
|
|
|
|
|
+
|
|
|
|
|
+ this._buffer.batch.remove( Range.createIn( limitElement ) );
|
|
|
|
|
+ this._buffer.batch.insert( Position.createAt( limitElement ), paragraph );
|
|
|
|
|
|
|
|
- selection.setRanges( [ Range.createIn( limitElement ) ], selection.isBackward );
|
|
|
|
|
- editor.data.deleteContent( selection, this._buffer.batch, { skipParentsCheck: true } );
|
|
|
|
|
|
|
+ selection.collapse( paragraph );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|