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

Commit

Permalink
Merge pull request #264 from ckeditor/i/6364
Browse files Browse the repository at this point in the history
Internal: Replaced the `getRangeContainedElement()` helper with `Range#getContainedElement()`. See [ckeditor/ckeditor5#6364](ckeditor/ckeditor5#6364).
  • Loading branch information
mlewand committed Mar 10, 2020
2 parents edbaf3a + f54ab64 commit 9ab3750
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/commands/insertcolumncommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import Command from '@ckeditor/ckeditor5-core/src/command';
import { getRangeContainedElement, findAncestor } from './utils';
import { findAncestor } from './utils';

/**
* The insert column command.
Expand Down Expand Up @@ -75,7 +75,7 @@ export default class InsertColumnCommand extends Command {
const referencePosition = insertBefore ? selection.getFirstPosition() : selection.getLastPosition();
const referenceRange = insertBefore ? selection.getFirstRange() : selection.getLastRange();

const tableCell = getRangeContainedElement( referenceRange ) || findAncestor( 'tableCell', referencePosition );
const tableCell = referenceRange.getContainedElement() || findAncestor( 'tableCell', referencePosition );
const table = tableCell.parent.parent;

const { column } = tableUtils.getCellLocation( tableCell );
Expand Down
4 changes: 2 additions & 2 deletions src/commands/insertrowcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import Command from '@ckeditor/ckeditor5-core/src/command';
import { getRangeContainedElement, findAncestor } from './utils';
import { findAncestor } from './utils';

/**
* The insert row command.
Expand Down Expand Up @@ -74,7 +74,7 @@ export default class InsertRowCommand extends Command {
const referencePosition = insertAbove ? selection.getFirstPosition() : selection.getLastPosition();
const referenceRange = insertAbove ? selection.getFirstRange() : selection.getLastRange();

const tableCell = getRangeContainedElement( referenceRange ) || findAncestor( 'tableCell', referencePosition );
const tableCell = referenceRange.getContainedElement() || findAncestor( 'tableCell', referencePosition );
const tableRow = tableCell.parent;
const table = tableRow.parent;

Expand Down
13 changes: 0 additions & 13 deletions src/commands/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ export function findAncestor( parentName, positionOrElement ) {
}
}

/**
* Returns an element contained by a range, if it's the only one element contained by the range and if it's fully contained.
*
* @param {module:engine/model/range~Range} range
* @returns {module:engine/model/element~Element|null}
*/
export function getRangeContainedElement( range ) {
const nodeAfterStart = range.start.nodeAfter;
const nodeBeforeEnd = range.end.nodeBefore;

return ( nodeAfterStart && nodeAfterStart.is( 'element' ) && nodeAfterStart == nodeBeforeEnd ) ? nodeAfterStart : null;
}

/**
* A common method to update the numeric value. If a value is the default one, it will be unset.
*
Expand Down
4 changes: 1 addition & 3 deletions src/tableselection/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* @module table/tableselection/utils
*/

import { getRangeContainedElement } from '../commands/utils';

/**
* Clears contents of the passed table cells.
*
Expand Down Expand Up @@ -40,7 +38,7 @@ export function getTableCellsInSelection( selection ) {
const cells = [];

for ( const range of selection.getRanges() ) {
const element = getRangeContainedElement( range );
const element = range.getContainedElement();

if ( element && element.is( 'tableCell' ) ) {
cells.push( element );
Expand Down

0 comments on commit 9ab3750

Please sign in to comment.