Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Do not show table toolbar when other widget is selected inside table.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Dec 6, 2018
1 parent 5717f60 commit 56adacf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export function isTableWidgetSelected( selection ) {
* @returns {Boolean}
*/
export function isTableContentSelected( selection ) {
const selectedElement = selection.getSelectedElement();
const isInnerWidgetSelected = selectedElement && isWidget( selectedElement );

const parentTable = findAncestor( 'table', selection.getFirstPosition() );

return !!( parentTable && isTableWidget( parentTable.parent ) );
return !isInnerWidgetSelected && !!( parentTable && isTableWidget( parentTable.parent ) );
}
38 changes: 37 additions & 1 deletion tests/tabletoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import View from '@ckeditor/ckeditor5-ui/src/view';
import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import WidgetToolbarRepository from '@ckeditor/ckeditor5-widget/src/widgettoolbarrepository';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar';
import Image from '@ckeditor/ckeditor5-image/src/image';
import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle';

describe( 'TableToolbar', () => {
testUtils.createSinonSandbox();
Expand All @@ -29,7 +32,10 @@ describe( 'TableToolbar', () => {

return ClassicTestEditor
.create( editorElement, {
plugins: [ Paragraph, Table, TableToolbar, FakeButton ],
plugins: [ Paragraph, Image, ImageStyle, ImageToolbar, Table, TableToolbar, FakeButton ],
image: {
toolbar: [ 'imageStyle:full', 'imageStyle:side' ]
},
table: {
contentToolbar: [ 'fake_button' ]
}
Expand Down Expand Up @@ -154,6 +160,36 @@ describe( 'TableToolbar', () => {
expect( balloon.visibleView ).to.equal( toolbar );
} );

it( 'should not show the toolbar on ui#update when the image inside table is selected', () => {
setData(
model,
'<paragraph>[foo]</paragraph>' +
'<table><tableRow><tableCell><paragraph>foo</paragraph><image src=""></image></tableCell></tableRow></table>'
);

expect( balloon.visibleView ).to.be.null;

const imageToolbar = widgetToolbarRepository._toolbars.get( 'image' ).view;

model.change( writer => {
// Select the <tableCell><paragraph></paragraph>[<image></image>]</tableCell>
const nodeByPath = doc.getRoot().getNodeByPath( [ 1, 0, 0, 1 ] );

writer.setSelection( nodeByPath, 'on' );
} );

expect( balloon.visibleView ).to.equal( imageToolbar );

model.change( writer => {
// Select the <tableCell><paragraph>[]</paragraph><image></image></tableCell>
writer.setSelection(
writer.createPositionAt( doc.getRoot().getNodeByPath( [ 1, 0, 0, 0 ] ), 0 )
);
} );

expect( balloon.visibleView ).to.equal( toolbar );
} );

it( 'should not engage when the toolbar is in the balloon yet invisible', () => {
setData( model, '<table><tableRow><tableCell><paragraph>x[y]z</paragraph></tableCell></tableRow></table>' );

Expand Down

0 comments on commit 56adacf

Please sign in to comment.