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

Commit

Permalink
Changed _getNearestTextPosition to _getNearestVisibleTextPosition to …
Browse files Browse the repository at this point in the history
…handle hidden image captions.
  • Loading branch information
niegowski committed Apr 15, 2020
1 parent 9c6a8af commit eebd6f2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/tablenavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export default class TableNavigation extends Plugin {
_findTextRangeFromSelection( range, selection, isForward ) {
if ( isForward ) {
const position = selection.getLastPosition();
const lastRangePosition = this._getNearestTextPosition( range, 'backward' );
const lastRangePosition = this._getNearestVisibleTextPosition( range, 'backward' );

if ( !lastRangePosition || position.compareWith( lastRangePosition ) != 'before' ) {
return null;
Expand All @@ -290,7 +290,7 @@ export default class TableNavigation extends Plugin {
return new ModelRange( position, lastRangePosition );
} else {
const position = selection.getFirstPosition();
const firstRangePosition = this._getNearestTextPosition( range, 'forward' );
const firstRangePosition = this._getNearestVisibleTextPosition( range, 'forward' );

if ( !firstRangePosition || position.compareWith( firstRangePosition ) != 'after' ) {
return null;
Expand All @@ -302,21 +302,27 @@ export default class TableNavigation extends Plugin {

/**
* Basing on provided `boundaries` range, finds first/last (depending on `direction`) element
* that can contain `$text` (according to schema).
* that can contain `$text` (according to schema) and is visible in the view.
*
* @param {module:engine/model/range~Range} boundaries The range to find position in.
* @param {'forward'|'backward'} direction Search direction.
* @returns {module:engine/model/position~Position|null} Nearest selection range or `null` if one cannot be found.
*/
_getNearestTextPosition( boundaries, direction ) {
_getNearestVisibleTextPosition( boundaries, direction ) {
const schema = this.editor.model.schema;
const mapper = this.editor.editing.mapper;

const startPosition = direction == 'forward' ? boundaries.start : boundaries.end;

const treeWalker = new TreeWalker( { direction, boundaries, startPosition } );

for ( const { nextPosition } of treeWalker ) {
for ( const { nextPosition, item } of treeWalker ) {
if ( schema.checkChild( nextPosition, '$text' ) ) {
return nextPosition;
const viewElement = mapper.toViewElement( item );

if ( viewElement && !viewElement.hasClass( 'ck-hidden' ) ) {
return nextPosition;
}
}
}

Expand Down

0 comments on commit eebd6f2

Please sign in to comment.