8
0
Просмотр исходного кода

Handle multi-cell selection in table cell properties UI.

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
4c50a2e869

+ 4 - 1
packages/ckeditor5-table/src/ui/utils.js

@@ -82,7 +82,10 @@ export function getBalloonTablePositionData( editor ) {
  */
  */
 export function getBalloonCellPositionData( editor ) {
 export function getBalloonCellPositionData( editor ) {
 	const firstPosition = editor.model.document.selection.getFirstPosition();
 	const firstPosition = editor.model.document.selection.getFirstPosition();
-	const modelTableCell = findAncestor( 'tableCell', firstPosition );
+	const nodeAfter = firstPosition.nodeAfter;
+
+	const isTableCellSelected = nodeAfter && nodeAfter.is( 'tableCell' );
+	const modelTableCell = isTableCellSelected ? nodeAfter : findAncestor( 'tableCell', firstPosition );
 	const viewTableCell = editor.editing.mapper.toViewElement( modelTableCell );
 	const viewTableCell = editor.editing.mapper.toViewElement( modelTableCell );
 
 
 	return {
 	return {

+ 15 - 1
packages/ckeditor5-table/tests/tablecellproperties/tablecellpropertiesui.js

@@ -8,7 +8,7 @@
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
-import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import { getData as getModelData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 
 import Undo from '@ckeditor/ckeditor5-undo/src/undo';
 import Undo from '@ckeditor/ckeditor5-undo/src/undo';
 import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
 import Batch from '@ckeditor/ckeditor5-engine/src/model/batch';
@@ -21,6 +21,7 @@ import TableCellPropertiesEditing from '../../src/tablecellproperties/tablecellp
 import TableCellPropertiesUI from '../../src/tablecellproperties/tablecellpropertiesui';
 import TableCellPropertiesUI from '../../src/tablecellproperties/tablecellpropertiesui';
 import TableCellPropertiesUIView from '../../src/tablecellproperties/ui/tablecellpropertiesview';
 import TableCellPropertiesUIView from '../../src/tablecellproperties/ui/tablecellpropertiesview';
 import { defaultColors } from '../../src/ui/utils';
 import { defaultColors } from '../../src/ui/utils';
+import { modelTable } from '../_utils/utils';
 
 
 describe( 'table cell properties', () => {
 describe( 'table cell properties', () => {
 	describe( 'TableCellPropertiesUI', () => {
 	describe( 'TableCellPropertiesUI', () => {
@@ -529,6 +530,19 @@ describe( 'table cell properties', () => {
 				expect( firstBatch ).to.not.equal( secondBatch );
 				expect( firstBatch ).to.not.equal( secondBatch );
 			} );
 			} );
 
 
+			it( 'should show the ui for multi-cell selection', () => {
+				setData( editor.model, modelTable( [ [ '01', '02' ] ] ) );
+				editor.model.change( writer => {
+					writer.setSelection( [
+						writer.createRangeOn( editor.model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] ) ),
+						writer.createRangeOn( editor.model.document.getRoot().getNodeByPath( [ 0, 0, 1 ] ) )
+					], 0 );
+				} );
+
+				tableCellPropertiesButton.fire( 'execute' );
+				expect( contextualBalloon.visibleView ).to.equal( tableCellPropertiesView );
+			} );
+
 			describe( 'initial data', () => {
 			describe( 'initial data', () => {
 				it( 'should be set from the command values', () => {
 				it( 'should be set from the command values', () => {
 					editor.commands.get( 'tableCellBorderStyle' ).value = 'a';
 					editor.commands.get( 'tableCellBorderStyle' ).value = 'a';