|
@@ -1,34 +1,34 @@
|
|
|
/**
|
|
/**
|
|
|
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
|
|
|
|
|
|
|
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
|
|
|
* For licensing, see LICENSE.md.
|
|
* For licensing, see LICENSE.md.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
|
|
import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
|
|
|
-import Document from '@ckeditor/ckeditor5-engine/src/model/document';
|
|
|
|
|
|
|
+import Model from '@ckeditor/ckeditor5-engine/src/model/model';
|
|
|
import IndentCommand from '../src/indentcommand';
|
|
import IndentCommand from '../src/indentcommand';
|
|
|
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
|
import Position from '@ckeditor/ckeditor5-engine/src/model/position';
|
|
import Position from '@ckeditor/ckeditor5-engine/src/model/position';
|
|
|
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
|
|
|
describe( 'IndentCommand', () => {
|
|
describe( 'IndentCommand', () => {
|
|
|
- let editor, doc, root;
|
|
|
|
|
|
|
+ let editor, model, doc, root;
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
editor = new Editor();
|
|
editor = new Editor();
|
|
|
- editor.document = new Document();
|
|
|
|
|
|
|
+ editor.model = new Model();
|
|
|
|
|
|
|
|
- doc = editor.document;
|
|
|
|
|
|
|
+ model = editor.model;
|
|
|
|
|
+ doc = model.document;
|
|
|
root = doc.createRoot();
|
|
root = doc.createRoot();
|
|
|
|
|
|
|
|
- doc.schema.registerItem( 'listItem', '$block' );
|
|
|
|
|
- doc.schema.registerItem( 'paragraph', '$block' );
|
|
|
|
|
-
|
|
|
|
|
- doc.schema.allow( { name: '$block', inside: '$root' } );
|
|
|
|
|
- doc.schema.allow( { name: 'listItem', attributes: [ 'type', 'indent' ], inside: '$root' } );
|
|
|
|
|
- doc.schema.allow( { name: 'paragraph', inside: '$root' } );
|
|
|
|
|
|
|
+ model.schema.register( 'listItem', {
|
|
|
|
|
+ inheritAllFrom: '$block',
|
|
|
|
|
+ allowAttributes: [ 'type', 'indent' ]
|
|
|
|
|
+ } );
|
|
|
|
|
+ model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
|
|
|
|
|
|
|
|
setData(
|
|
setData(
|
|
|
- doc,
|
|
|
|
|
|
|
+ model,
|
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
'<listItem indent="0" type="bulleted">b</listItem>' +
|
|
'<listItem indent="0" type="bulleted">b</listItem>' +
|
|
|
'<listItem indent="1" type="bulleted">c</listItem>' +
|
|
'<listItem indent="1" type="bulleted">c</listItem>' +
|
|
@@ -52,16 +52,16 @@ describe( 'IndentCommand', () => {
|
|
|
|
|
|
|
|
describe( 'isEnabled', () => {
|
|
describe( 'isEnabled', () => {
|
|
|
it( 'should be true if selection starts in list item', () => {
|
|
it( 'should be true if selection starts in list item', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 5 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 5 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
expect( command.isEnabled ).to.be.true;
|
|
expect( command.isEnabled ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should be false if selection starts in first list item', () => {
|
|
it( 'should be false if selection starts in first list item', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 0 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 0 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
expect( command.isEnabled ).to.be.false;
|
|
expect( command.isEnabled ).to.be.false;
|
|
@@ -70,7 +70,7 @@ describe( 'IndentCommand', () => {
|
|
|
// Reported in PR #53.
|
|
// Reported in PR #53.
|
|
|
it( 'should be false if selection starts in first list item #2', () => {
|
|
it( 'should be false if selection starts in first list item #2', () => {
|
|
|
setData(
|
|
setData(
|
|
|
- doc,
|
|
|
|
|
|
|
+ model,
|
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
'<listItem indent="1" type="bulleted">b</listItem>' +
|
|
'<listItem indent="1" type="bulleted">b</listItem>' +
|
|
|
'<listItem indent="0" type="bulleted">c</listItem>' +
|
|
'<listItem indent="0" type="bulleted">c</listItem>' +
|
|
@@ -84,7 +84,7 @@ describe( 'IndentCommand', () => {
|
|
|
// Reported in PR #53.
|
|
// Reported in PR #53.
|
|
|
it( 'should be false if selection starts in first list item #3', () => {
|
|
it( 'should be false if selection starts in first list item #3', () => {
|
|
|
setData(
|
|
setData(
|
|
|
- doc,
|
|
|
|
|
|
|
+ model,
|
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
'<listItem indent="1" type="bulleted">b</listItem>' +
|
|
'<listItem indent="1" type="bulleted">b</listItem>' +
|
|
|
'<listItem indent="0" type="numbered">c</listItem>' +
|
|
'<listItem indent="0" type="numbered">c</listItem>' +
|
|
@@ -97,7 +97,7 @@ describe( 'IndentCommand', () => {
|
|
|
|
|
|
|
|
it( 'should be false if selection starts in first list item of top level list with different type than previous list', () => {
|
|
it( 'should be false if selection starts in first list item of top level list with different type than previous list', () => {
|
|
|
setData(
|
|
setData(
|
|
|
- doc,
|
|
|
|
|
|
|
+ model,
|
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
'<listItem indent="0" type="numbered">[]b</listItem>'
|
|
'<listItem indent="0" type="numbered">[]b</listItem>'
|
|
|
);
|
|
);
|
|
@@ -106,8 +106,8 @@ describe( 'IndentCommand', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should be false if selection starts in a list item that has bigger indent than it\'s previous sibling', () => {
|
|
it( 'should be false if selection starts in a list item that has bigger indent than it\'s previous sibling', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 2 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 2 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
expect( command.isEnabled ).to.be.false;
|
|
expect( command.isEnabled ).to.be.false;
|
|
@@ -116,23 +116,37 @@ describe( 'IndentCommand', () => {
|
|
|
// Edge case but may happen that some other blocks will also use the indent attribute
|
|
// Edge case but may happen that some other blocks will also use the indent attribute
|
|
|
// and before we fixed it the command was enabled in such a case.
|
|
// and before we fixed it the command was enabled in such a case.
|
|
|
it( 'should be false if selection starts in a paragraph with indent attribute', () => {
|
|
it( 'should be false if selection starts in a paragraph with indent attribute', () => {
|
|
|
- doc.schema.allow( { name: 'paragraph', attributes: [ 'indent' ], inside: '$root' } );
|
|
|
|
|
|
|
+ model.schema.extend( 'paragraph', { allowAttributes: 'indent' } );
|
|
|
|
|
|
|
|
- setData( doc, '<listItem indent="0">a</listItem><paragraph indent="0">b[]</paragraph>' );
|
|
|
|
|
|
|
+ setData( model, '<listItem indent="0">a</listItem><paragraph indent="0">b[]</paragraph>' );
|
|
|
|
|
|
|
|
expect( command.isEnabled ).to.be.false;
|
|
expect( command.isEnabled ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'execute()', () => {
|
|
describe( 'execute()', () => {
|
|
|
|
|
+ it( 'should use parent batch', () => {
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 5 ), 0 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ expect( writer.batch.deltas.length ).to.equal( 0 );
|
|
|
|
|
+
|
|
|
|
|
+ command.execute();
|
|
|
|
|
+
|
|
|
|
|
+ expect( writer.batch.deltas.length ).to.be.above( 0 );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should increment indent attribute by 1', () => {
|
|
it( 'should increment indent attribute by 1', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 5 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 5 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
command.execute();
|
|
command.execute();
|
|
|
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model, { withoutSelection: true } ) ).to.equal(
|
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
'<listItem indent="0" type="bulleted">b</listItem>' +
|
|
'<listItem indent="0" type="bulleted">b</listItem>' +
|
|
|
'<listItem indent="1" type="bulleted">c</listItem>' +
|
|
'<listItem indent="1" type="bulleted">c</listItem>' +
|
|
@@ -144,13 +158,13 @@ describe( 'IndentCommand', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should increment indent of all sub-items of indented item', () => {
|
|
it( 'should increment indent of all sub-items of indented item', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 1 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 1 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
command.execute();
|
|
command.execute();
|
|
|
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model, { withoutSelection: true } ) ).to.equal(
|
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
'<listItem indent="1" type="bulleted">b</listItem>' +
|
|
'<listItem indent="1" type="bulleted">b</listItem>' +
|
|
|
'<listItem indent="2" type="bulleted">c</listItem>' +
|
|
'<listItem indent="2" type="bulleted">c</listItem>' +
|
|
@@ -162,16 +176,16 @@ describe( 'IndentCommand', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should increment indent of all selected item when multiple items are selected', () => {
|
|
it( 'should increment indent of all selected item when multiple items are selected', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setRanges( [ new Range(
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( new Range(
|
|
|
new Position( root.getChild( 1 ), [ 0 ] ),
|
|
new Position( root.getChild( 1 ), [ 0 ] ),
|
|
|
new Position( root.getChild( 3 ), [ 1 ] )
|
|
new Position( root.getChild( 3 ), [ 1 ] )
|
|
|
- ) ] );
|
|
|
|
|
|
|
+ ) );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
command.execute();
|
|
command.execute();
|
|
|
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model, { withoutSelection: true } ) ).to.equal(
|
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
'<listItem indent="1" type="bulleted">b</listItem>' +
|
|
'<listItem indent="1" type="bulleted">b</listItem>' +
|
|
|
'<listItem indent="2" type="bulleted">c</listItem>' +
|
|
'<listItem indent="2" type="bulleted">c</listItem>' +
|
|
@@ -181,49 +195,6 @@ describe( 'IndentCommand', () => {
|
|
|
'<listItem indent="0" type="bulleted">g</listItem>'
|
|
'<listItem indent="0" type="bulleted">g</listItem>'
|
|
|
);
|
|
);
|
|
|
} );
|
|
} );
|
|
|
-
|
|
|
|
|
- it( 'should fix list type when item is intended #1', () => {
|
|
|
|
|
- setData(
|
|
|
|
|
- doc,
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="bulleted">b</listItem>' +
|
|
|
|
|
- '<listItem indent="2" type="numbered">c</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="bulleted">[]d</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- command.execute();
|
|
|
|
|
-
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="bulleted">b</listItem>' +
|
|
|
|
|
- '<listItem indent="2" type="numbered">c</listItem>' +
|
|
|
|
|
- '<listItem indent="2" type="numbered">d</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- // Not only boundary list items has to be fixed, but also items in the middle of selection.
|
|
|
|
|
- it( 'should fix list type when item is intended #2', () => {
|
|
|
|
|
- setData(
|
|
|
|
|
- doc,
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">b</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">[c</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="bulleted">d</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">e]</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="bulleted">f</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- command.execute();
|
|
|
|
|
-
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">b</listItem>' +
|
|
|
|
|
- '<listItem indent="2" type="numbered">c</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">d</listItem>' +
|
|
|
|
|
- '<listItem indent="2" type="numbered">e</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="bulleted">f</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
- } );
|
|
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -240,8 +211,8 @@ describe( 'IndentCommand', () => {
|
|
|
|
|
|
|
|
describe( 'isEnabled', () => {
|
|
describe( 'isEnabled', () => {
|
|
|
it( 'should be true if selection starts in list item', () => {
|
|
it( 'should be true if selection starts in list item', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 5 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 5 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
expect( command.isEnabled ).to.be.true;
|
|
expect( command.isEnabled ).to.be.true;
|
|
@@ -249,8 +220,8 @@ describe( 'IndentCommand', () => {
|
|
|
|
|
|
|
|
it( 'should be true if selection starts in first list item', () => {
|
|
it( 'should be true if selection starts in first list item', () => {
|
|
|
// This is in contrary to forward indent command.
|
|
// This is in contrary to forward indent command.
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 0 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 0 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
expect( command.isEnabled ).to.be.true;
|
|
expect( command.isEnabled ).to.be.true;
|
|
@@ -258,8 +229,8 @@ describe( 'IndentCommand', () => {
|
|
|
|
|
|
|
|
it( 'should be true if selection starts in a list item that has bigger indent than it\'s previous sibling', () => {
|
|
it( 'should be true if selection starts in a list item that has bigger indent than it\'s previous sibling', () => {
|
|
|
// This is in contrary to forward indent command.
|
|
// This is in contrary to forward indent command.
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 2 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 2 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
expect( command.isEnabled ).to.be.true;
|
|
expect( command.isEnabled ).to.be.true;
|
|
@@ -268,13 +239,13 @@ describe( 'IndentCommand', () => {
|
|
|
|
|
|
|
|
describe( 'execute()', () => {
|
|
describe( 'execute()', () => {
|
|
|
it( 'should decrement indent attribute by 1 (if it is bigger than 0)', () => {
|
|
it( 'should decrement indent attribute by 1 (if it is bigger than 0)', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 5 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 5 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
command.execute();
|
|
command.execute();
|
|
|
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model, { withoutSelection: true } ) ).to.equal(
|
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
'<listItem indent="0" type="bulleted">b</listItem>' +
|
|
'<listItem indent="0" type="bulleted">b</listItem>' +
|
|
|
'<listItem indent="1" type="bulleted">c</listItem>' +
|
|
'<listItem indent="1" type="bulleted">c</listItem>' +
|
|
@@ -286,13 +257,13 @@ describe( 'IndentCommand', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should rename listItem to paragraph (if indent is equal to 0)', () => {
|
|
it( 'should rename listItem to paragraph (if indent is equal to 0)', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 0 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 0 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
command.execute();
|
|
command.execute();
|
|
|
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model, { withoutSelection: true } ) ).to.equal(
|
|
|
'<paragraph indent="0" type="bulleted">a</paragraph>' +
|
|
'<paragraph indent="0" type="bulleted">a</paragraph>' +
|
|
|
'<listItem indent="0" type="bulleted">b</listItem>' +
|
|
'<listItem indent="0" type="bulleted">b</listItem>' +
|
|
|
'<listItem indent="1" type="bulleted">c</listItem>' +
|
|
'<listItem indent="1" type="bulleted">c</listItem>' +
|
|
@@ -304,13 +275,13 @@ describe( 'IndentCommand', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should decrement indent of all sub-items of outdented item', () => {
|
|
it( 'should decrement indent of all sub-items of outdented item', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setCollapsedAt( root.getChild( 1 ) );
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( root.getChild( 1 ), 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
command.execute();
|
|
command.execute();
|
|
|
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model, { withoutSelection: true } ) ).to.equal(
|
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
'<paragraph indent="0" type="bulleted">b</paragraph>' +
|
|
'<paragraph indent="0" type="bulleted">b</paragraph>' +
|
|
|
'<listItem indent="0" type="bulleted">c</listItem>' +
|
|
'<listItem indent="0" type="bulleted">c</listItem>' +
|
|
@@ -322,16 +293,16 @@ describe( 'IndentCommand', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should outdent all selected item when multiple items are selected', () => {
|
|
it( 'should outdent all selected item when multiple items are selected', () => {
|
|
|
- doc.enqueueChanges( () => {
|
|
|
|
|
- doc.selection.setRanges( [ new Range(
|
|
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.setSelection( new Range(
|
|
|
new Position( root.getChild( 1 ), [ 0 ] ),
|
|
new Position( root.getChild( 1 ), [ 0 ] ),
|
|
|
new Position( root.getChild( 3 ), [ 1 ] )
|
|
new Position( root.getChild( 3 ), [ 1 ] )
|
|
|
- ) ] );
|
|
|
|
|
|
|
+ ) );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
command.execute();
|
|
command.execute();
|
|
|
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
|
|
+ expect( getData( model, { withoutSelection: true } ) ).to.equal(
|
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
'<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
'<paragraph indent="0" type="bulleted">b</paragraph>' +
|
|
'<paragraph indent="0" type="bulleted">b</paragraph>' +
|
|
|
'<listItem indent="0" type="bulleted">c</listItem>' +
|
|
'<listItem indent="0" type="bulleted">c</listItem>' +
|
|
@@ -341,105 +312,6 @@ describe( 'IndentCommand', () => {
|
|
|
'<listItem indent="0" type="bulleted">g</listItem>'
|
|
'<listItem indent="0" type="bulleted">g</listItem>'
|
|
|
);
|
|
);
|
|
|
} );
|
|
} );
|
|
|
-
|
|
|
|
|
- it( 'should fix list type when item is outdented #1', () => {
|
|
|
|
|
- setData(
|
|
|
|
|
- doc,
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="bulleted">b</listItem>' +
|
|
|
|
|
- '<listItem indent="2" type="numbered">[]c</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- command.execute();
|
|
|
|
|
-
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="bulleted">b</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="bulleted">c</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- // Look at next siblings if, after outdenting, a list item is a first item in it's list (list item "c").
|
|
|
|
|
- it( 'should fix list type when item is outdented #2', () => {
|
|
|
|
|
- setData(
|
|
|
|
|
- doc,
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">[]b</listItem>' +
|
|
|
|
|
- '<listItem indent="2" type="bulleted">c</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">d</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- command.execute();
|
|
|
|
|
-
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="bulleted">b</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">c</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">d</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- // Reported in #53.
|
|
|
|
|
- it( 'should fix list type when item is outdented #3', () => {
|
|
|
|
|
- setData(
|
|
|
|
|
- doc,
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">[b</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">c</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">d]</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- command.execute();
|
|
|
|
|
-
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="bulleted">b</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="bulleted">c</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="bulleted">d</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should fix list type when item is outdented to top level (if needed)', () => {
|
|
|
|
|
- setData(
|
|
|
|
|
- doc,
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">[]b</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="numbered">c</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- command.execute();
|
|
|
|
|
-
|
|
|
|
|
- // Another possible behaviour would be that "b" list item becomes first list item of a top level
|
|
|
|
|
- // numbered list (so it does not change it's type) but it seems less correct from UX standpoint.
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="bulleted">b</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="numbered">c</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should not fix nested list items\' type when not needed', () => {
|
|
|
|
|
- // There was a bug that the nested sub-list changed it's type because for a while, it was on same indent
|
|
|
|
|
- // level as the originally outdented element.
|
|
|
|
|
- setData(
|
|
|
|
|
- doc,
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">b</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">[]c</listItem>' +
|
|
|
|
|
- '<listItem indent="2" type="bulleted">d</listItem>' +
|
|
|
|
|
- '<listItem indent="2" type="bulleted">e</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- command.execute();
|
|
|
|
|
-
|
|
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal(
|
|
|
|
|
- '<listItem indent="0" type="bulleted">a</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="numbered">b</listItem>' +
|
|
|
|
|
- '<listItem indent="0" type="bulleted">c</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="bulleted">d</listItem>' +
|
|
|
|
|
- '<listItem indent="1" type="bulleted">e</listItem>'
|
|
|
|
|
- );
|
|
|
|
|
- } );
|
|
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|