This repository was 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
Added SelectRowCommand and SelectColumnCommand. #295
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c9145ed
Added SelectRowCommand and SelectColumnCommand.
niegowski d7ff85e
Update tests/commands/selectcolumncommand.js
niegowski 36c5119
Update tests/commands/selectrowcommand.js
niegowski dabdfa9
Update tests/commands/selectcolumncommand.js
niegowski 17d9209
Update tests/commands/selectcolumncommand.js
niegowski 5017b98
Update tests/commands/selectcolumncommand.js
niegowski 1cd3376
Update tests/commands/selectrowcommand.js
niegowski 87eb778
Update tests/commands/selectrowcommand.js
niegowski c14342e
Changed button label (Select row/column).
niegowski 861c7d6
Added usage example for assertSelectedCells.
niegowski a771d71
Optimised SelectRowCommand and SelectColumnCommand.
niegowski 302526b
Added more tests with row/col-spanned cells.
niegowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This note is important here. I think that it could be improved but there's must be info about this IMO.