This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #295 from ckeditor/i/6500
Feature: "Select entire column/row" added to table column and row dropdowns. Closes ckeditor/ckeditor5#6500.
- Loading branch information
Showing
12 changed files
with
1,139 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module table/commands/selectcolumncommand | ||
*/ | ||
|
||
import Command from '@ckeditor/ckeditor5-core/src/command'; | ||
|
||
import TableWalker from '../tablewalker'; | ||
import { findAncestor } from './utils'; | ||
import { getSelectionAffectedTableCells } from '../utils'; | ||
|
||
/** | ||
* The select column command. | ||
* | ||
* The command is registered by {@link module:table/tableediting~TableEditing} as the `'selectTableColumn'` editor command. | ||
* | ||
* To select the columns containing the selected cells, execute the command: | ||
* | ||
* editor.execute( 'selectTableColumn' ); | ||
* | ||
* @extends module:core/command~Command | ||
*/ | ||
export default class SelectColumnCommand extends Command { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
refresh() { | ||
const selectedCells = getSelectionAffectedTableCells( this.editor.model.document.selection ); | ||
|
||
this.isEnabled = selectedCells.length > 0; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
execute() { | ||
const model = this.editor.model; | ||
const referenceCells = getSelectionAffectedTableCells( model.document.selection ); | ||
const firstCell = referenceCells[ 0 ]; | ||
const lastCell = referenceCells.pop(); | ||
|
||
const tableUtils = this.editor.plugins.get( 'TableUtils' ); | ||
const startLocation = tableUtils.getCellLocation( firstCell ); | ||
const endLocation = tableUtils.getCellLocation( lastCell ); | ||
|
||
const startColumn = Math.min( startLocation.column, endLocation.column ); | ||
const endColumn = Math.max( startLocation.column, endLocation.column ); | ||
|
||
const rangesToSelect = []; | ||
|
||
for ( const cellInfo of new TableWalker( findAncestor( 'table', firstCell ) ) ) { | ||
if ( cellInfo.column >= startColumn && cellInfo.column <= endColumn ) { | ||
rangesToSelect.push( model.createRangeOn( cellInfo.cell ) ); | ||
} | ||
} | ||
|
||
model.change( writer => { | ||
writer.setSelection( rangesToSelect ); | ||
} ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license | ||
*/ | ||
|
||
/** | ||
* @module table/commands/selectrowcommand | ||
*/ | ||
|
||
import Command from '@ckeditor/ckeditor5-core/src/command'; | ||
|
||
import { findAncestor } from './utils'; | ||
import { getRowIndexes, getSelectionAffectedTableCells } from '../utils'; | ||
|
||
/** | ||
* The select row command. | ||
* | ||
* The command is registered by {@link module:table/tableediting~TableEditing} as the `'selectTableRow'` editor command. | ||
* | ||
* To select the rows containing the selected cells, execute the command: | ||
* | ||
* editor.execute( 'selectTableRow' ); | ||
* | ||
* @extends module:core/command~Command | ||
*/ | ||
export default class SelectRowCommand extends Command { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
refresh() { | ||
const selectedCells = getSelectionAffectedTableCells( this.editor.model.document.selection ); | ||
|
||
this.isEnabled = selectedCells.length > 0; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
execute() { | ||
const model = this.editor.model; | ||
const referenceCells = getSelectionAffectedTableCells( model.document.selection ); | ||
const rowIndexes = getRowIndexes( referenceCells ); | ||
|
||
const table = findAncestor( 'table', referenceCells[ 0 ] ); | ||
const rangesToSelect = []; | ||
|
||
for ( let rowIndex = rowIndexes.first; rowIndex <= rowIndexes.last; rowIndex++ ) { | ||
for ( const cell of table.getChild( rowIndex ).getChildren() ) { | ||
rangesToSelect.push( model.createRangeOn( cell ) ); | ||
} | ||
} | ||
|
||
model.change( writer => { | ||
writer.setSelection( rangesToSelect ); | ||
} ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.