|
|
@@ -5,13 +5,11 @@
|
|
|
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
-import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
-import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
|
-import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
|
|
|
+import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
|
import TableEditing from '../src/tableediting';
|
|
|
import TableSelection from '../src/tableselection';
|
|
|
-import { modelTable, viewTable } from './_utils/utils';
|
|
|
+import { modelTable } from './_utils/utils';
|
|
|
|
|
|
describe( 'table selection', () => {
|
|
|
let editor, model, tableSelection, modelRoot;
|
|
|
@@ -50,14 +48,21 @@ describe( 'table selection', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'setSelectingTo()', () => {
|
|
|
- it( 'should not change model selection if selection is not started', () => {
|
|
|
+ it( 'should set model selection on passed cell if startSelectingFrom() was not used', () => {
|
|
|
const spy = sinon.spy();
|
|
|
|
|
|
model.document.selection.on( 'change', spy );
|
|
|
|
|
|
+ tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
|
|
|
|
|
|
- sinon.assert.notCalled( spy );
|
|
|
+ sinon.assert.calledOnce( spy );
|
|
|
+
|
|
|
+ assertSelectedCells( [
|
|
|
+ [ 1, 1, 0 ],
|
|
|
+ [ 0, 0, 0 ],
|
|
|
+ [ 0, 0, 0 ]
|
|
|
+ ] );
|
|
|
} );
|
|
|
|
|
|
it( 'should change model selection if valid selection will be set', () => {
|
|
|
@@ -223,15 +228,6 @@ describe( 'table selection', () => {
|
|
|
sinon.assert.notCalled( spy );
|
|
|
} );
|
|
|
|
|
|
- it( 'should stop selecting mode', () => {
|
|
|
- tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
- tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
|
|
|
-
|
|
|
- tableSelection.clearSelection();
|
|
|
-
|
|
|
- expect( tableSelection.isSelecting ).to.be.false;
|
|
|
- } );
|
|
|
-
|
|
|
it( 'should not reset model selections', () => {
|
|
|
tableSelection.startSelectingFrom( modelRoot.getNodeByPath( [ 0, 0, 0 ] ) );
|
|
|
tableSelection.setSelectingTo( modelRoot.getNodeByPath( [ 0, 0, 1 ] ) );
|
|
|
@@ -301,337 +297,6 @@ describe( 'table selection', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- describe( 'mouse selection', () => {
|
|
|
- let view, domEvtDataStub;
|
|
|
-
|
|
|
- beforeEach( () => {
|
|
|
- view = editor.editing.view;
|
|
|
-
|
|
|
- domEvtDataStub = {
|
|
|
- domEvent: {
|
|
|
- buttons: 1
|
|
|
- },
|
|
|
- target: undefined,
|
|
|
- preventDefault: sinon.spy(),
|
|
|
- stopPropagation: sinon.spy()
|
|
|
- };
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should not start table selection when mouse move is inside one table cell', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 0 );
|
|
|
-
|
|
|
- view.document.fire( 'mousedown', domEvtDataStub );
|
|
|
-
|
|
|
- assertEqualMarkup( getModelData( model ), modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- assertEqualMarkup( getModelData( model ), modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should start table selection when mouse move expands over two cells', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 0 );
|
|
|
- view.document.fire( 'mousedown', domEvtDataStub );
|
|
|
-
|
|
|
- assertEqualMarkup( getModelData( model ), modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 1 );
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- assertSelectedCells( [
|
|
|
- [ 1, 1 ],
|
|
|
- [ 0, 0 ]
|
|
|
- ] );
|
|
|
-
|
|
|
- assertEqualMarkup( getViewData( view ), viewTable( [
|
|
|
- [ { contents: '00', class: 'selected', isSelected: true }, { contents: '01', class: 'selected', isSelected: true } ],
|
|
|
- [ '10', '11' ]
|
|
|
- ], { asWidget: true } ) );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should select rectangular table cells when mouse moved to diagonal cell (up -> down)', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 0 );
|
|
|
- view.document.fire( 'mousedown', domEvtDataStub );
|
|
|
-
|
|
|
- assertEqualMarkup( getModelData( model ), modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 1, 1 );
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- assertSelectedCells( [
|
|
|
- [ 1, 1 ],
|
|
|
- [ 1, 1 ]
|
|
|
- ] );
|
|
|
-
|
|
|
- assertEqualMarkup( getViewData( view ), viewTable( [
|
|
|
- [ { contents: '00', class: 'selected', isSelected: true }, { contents: '01', class: 'selected', isSelected: true } ],
|
|
|
- [ { contents: '10', class: 'selected', isSelected: true }, { contents: '11', class: 'selected', isSelected: true } ]
|
|
|
- ], { asWidget: true } ) );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should select rectangular table cells when mouse moved to diagonal cell (down -> up)', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ '00', '01' ],
|
|
|
- [ '10', '[]11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 1, 1 );
|
|
|
- view.document.fire( 'mousedown', domEvtDataStub );
|
|
|
-
|
|
|
- assertEqualMarkup( getModelData( model ), modelTable( [
|
|
|
- [ '00', '01' ],
|
|
|
- [ '10', '[]11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 0 );
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- assertSelectedCells( [
|
|
|
- [ 1, 1 ],
|
|
|
- [ 1, 1 ]
|
|
|
- ] );
|
|
|
-
|
|
|
- assertEqualMarkup( getViewData( view ), viewTable( [
|
|
|
- [ { contents: '00', class: 'selected', isSelected: true }, { contents: '01', class: 'selected', isSelected: true } ],
|
|
|
- [ { contents: '10', class: 'selected', isSelected: true }, { contents: '11', class: 'selected', isSelected: true } ]
|
|
|
- ], { asWidget: true } ) );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should update view selection after changing selection rect', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ '[]00', '01', '02' ],
|
|
|
- [ '10', '11', '12' ],
|
|
|
- [ '20', '21', '22' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 0 );
|
|
|
- view.document.fire( 'mousedown', domEvtDataStub );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 2, 2 );
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- assertSelectedCells( [
|
|
|
- [ 1, 1, 1 ],
|
|
|
- [ 1, 1, 1 ],
|
|
|
- [ 1, 1, 1 ]
|
|
|
- ] );
|
|
|
-
|
|
|
- assertEqualMarkup( getViewData( view ), viewTable( [
|
|
|
- [
|
|
|
- { contents: '00', class: 'selected', isSelected: true },
|
|
|
- { contents: '01', class: 'selected', isSelected: true },
|
|
|
- { contents: '02', class: 'selected', isSelected: true }
|
|
|
- ],
|
|
|
- [
|
|
|
- { contents: '10', class: 'selected', isSelected: true },
|
|
|
- { contents: '11', class: 'selected', isSelected: true },
|
|
|
- { contents: '12', class: 'selected', isSelected: true }
|
|
|
- ],
|
|
|
- [
|
|
|
- { contents: '20', class: 'selected', isSelected: true },
|
|
|
- { contents: '21', class: 'selected', isSelected: true },
|
|
|
- { contents: '22', class: 'selected', isSelected: true }
|
|
|
- ]
|
|
|
- ], { asWidget: true } ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 1, 1 );
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- assertSelectedCells( [
|
|
|
- [ 1, 1, 0 ],
|
|
|
- [ 1, 1, 0 ],
|
|
|
- [ 0, 0, 0 ]
|
|
|
- ] );
|
|
|
-
|
|
|
- assertEqualMarkup( getViewData( view ), viewTable( [
|
|
|
- [
|
|
|
- { contents: '00', class: 'selected', isSelected: true },
|
|
|
- { contents: '01', class: 'selected', isSelected: true },
|
|
|
- '02'
|
|
|
- ],
|
|
|
- [
|
|
|
- { contents: '10', class: 'selected', isSelected: true },
|
|
|
- { contents: '11', class: 'selected', isSelected: true },
|
|
|
- '12'
|
|
|
- ],
|
|
|
- [
|
|
|
- '20',
|
|
|
- '21',
|
|
|
- '22'
|
|
|
- ]
|
|
|
- ], { asWidget: true } ) );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should stop selecting after "mouseup" event', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 0 );
|
|
|
- view.document.fire( 'mousedown', domEvtDataStub );
|
|
|
-
|
|
|
- assertEqualMarkup( getModelData( model ), modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 1 );
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- view.document.fire( 'mouseup', domEvtDataStub );
|
|
|
-
|
|
|
- assertSelectedCells( [
|
|
|
- [ 1, 1 ],
|
|
|
- [ 0, 0 ]
|
|
|
- ] );
|
|
|
-
|
|
|
- assertEqualMarkup( getViewData( view ), viewTable( [
|
|
|
- [ { contents: '00', class: 'selected', isSelected: true }, { contents: '01', class: 'selected', isSelected: true } ],
|
|
|
- [ '10', '11' ]
|
|
|
- ], { asWidget: true } ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 1, 1 );
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- assertSelectedCells( [
|
|
|
- [ 1, 1 ],
|
|
|
- [ 0, 0 ]
|
|
|
- ] );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should stop selection mode on "mouseleve" event', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 0 );
|
|
|
- view.document.fire( 'mousedown', domEvtDataStub );
|
|
|
-
|
|
|
- assertEqualMarkup( getModelData( model ), modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 1 );
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- view.document.fire( 'mouseleave', domEvtDataStub );
|
|
|
-
|
|
|
- assertSelectedCells( [
|
|
|
- [ 1, 1 ],
|
|
|
- [ 0, 0 ]
|
|
|
- ] );
|
|
|
-
|
|
|
- assertEqualMarkup( getViewData( view ), viewTable( [
|
|
|
- [ { contents: '00', class: 'selected', isSelected: true }, { contents: '01', class: 'selected', isSelected: true } ],
|
|
|
- [ '10', '11' ]
|
|
|
- ], { asWidget: true } ) );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 1, 1 );
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- assertSelectedCells( [
|
|
|
- [ 1, 1 ],
|
|
|
- [ 0, 0 ]
|
|
|
- ] );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should do nothing on "mouseleve" event', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- view.document.fire( 'mouseleave', domEvtDataStub );
|
|
|
-
|
|
|
- assertSelectedCells( [
|
|
|
- [ 0, 0 ],
|
|
|
- [ 0, 0 ]
|
|
|
- ] );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should do nothing on "mousedown" event over ui element (click on selection handle)', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) );
|
|
|
-
|
|
|
- domEvtDataStub.target = view.document.getRoot()
|
|
|
- .getChild( 0 )
|
|
|
- .getChild( 0 ); // selection handler;
|
|
|
-
|
|
|
- view.document.fire( 'mousedown', domEvtDataStub );
|
|
|
-
|
|
|
- assertEqualMarkup( getModelData( model ), '[' + modelTable( [
|
|
|
- [ '00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) + ']' );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should clear view table selection after mouse click outside table', () => {
|
|
|
- setModelData( model, modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) + '<paragraph>foo</paragraph>' );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 0 );
|
|
|
- view.document.fire( 'mousedown', domEvtDataStub );
|
|
|
-
|
|
|
- assertEqualMarkup( getModelData( model ), modelTable( [
|
|
|
- [ '[]00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ] ) + '<paragraph>foo</paragraph>' );
|
|
|
-
|
|
|
- markTableCellAsSelectedInEvent( domEvtDataStub, view, 0, 0, 0, 1 );
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
-
|
|
|
- domEvtDataStub.target = view.document.getRoot().getChild( 1 );
|
|
|
-
|
|
|
- view.document.fire( 'mousemove', domEvtDataStub );
|
|
|
- view.document.fire( 'mousedown', domEvtDataStub );
|
|
|
- view.document.fire( 'mouseup', domEvtDataStub );
|
|
|
-
|
|
|
- // The click in the DOM would trigger selection change and it will set the selection:
|
|
|
- model.change( writer => {
|
|
|
- writer.setSelection( writer.createRange( writer.createPositionAt( model.document.getRoot().getChild( 1 ), 0 ) ) );
|
|
|
- } );
|
|
|
-
|
|
|
- assertEqualMarkup( getViewData( view ), viewTable( [
|
|
|
- [ '00', '01' ],
|
|
|
- [ '10', '11' ]
|
|
|
- ], { asWidget: true } ) + '<p>{}foo</p>' );
|
|
|
- } );
|
|
|
- } );
|
|
|
-
|
|
|
// Helper method for asserting selected table cells.
|
|
|
//
|
|
|
// To check if a table has expected cells selected pass two dimensional array of truthy and falsy values:
|
|
|
@@ -676,12 +341,3 @@ describe( 'table selection', () => {
|
|
|
expect( selectionRanges.every( range => !range.containsItem( node ) ), `Expected node [${ path }] to be not selected` ).to.be.true;
|
|
|
}
|
|
|
} );
|
|
|
-
|
|
|
-function markTableCellAsSelectedInEvent( domEvtDataStub, view, tableIndex, sectionIndex, rowInSectionIndex, tableCellIndex ) {
|
|
|
- domEvtDataStub.target = view.document.getRoot()
|
|
|
- .getChild( tableIndex )
|
|
|
- .getChild( 1 ) // Table is second in widget
|
|
|
- .getChild( sectionIndex )
|
|
|
- .getChild( rowInSectionIndex )
|
|
|
- .getChild( tableCellIndex );
|
|
|
-}
|