Skip to content

Commit

Permalink
Merge pull request #8797 from ckeditor/i/8092
Browse files Browse the repository at this point in the history
Other (link): Fake selection marker for collapsed and non-collapsed selections for link UI should be converted separately. Closes #8092.
  • Loading branch information
scofalik authored Jan 15, 2021
2 parents dffc1eb + d154cc9 commit be55f91
Showing 1 changed file with 5 additions and 27 deletions.
32 changes: 5 additions & 27 deletions packages/ckeditor5-link/src/linkui.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,13 +664,15 @@ export default class LinkUI extends Plugin {
writer.updateMarker( VISUAL_SELECTION_MARKER_NAME, { range } );
} else {
if ( range.start.isAtEnd ) {
const focus = model.document.selection.focus;
const nextValidRange = getNextValidRange( range, focus, writer );
const startPosition = range.start.getLastMatchingPosition(
( { item } ) => !model.schema.isContent( item ),
{ boundaries: range }
);

writer.addMarker( VISUAL_SELECTION_MARKER_NAME, {
usingOperation: false,
affectsData: false,
range: nextValidRange
range: writer.createRange( startPosition, range.end )
} );
} else {
writer.addMarker( VISUAL_SELECTION_MARKER_NAME, {
Expand Down Expand Up @@ -707,27 +709,3 @@ export default class LinkUI extends Plugin {
function findLinkElementAncestor( position ) {
return position.getAncestors().find( ancestor => isLinkElement( ancestor ) );
}

// Returns next valid range for the fake visual selection marker.
//
// @private
// @param {module:engine/model/range~Range} range Current range.
// @param {module:engine/model/position~Position} focus Selection focus.
// @param {module:engine/model/writer~Writer} writer Writer.
// @returns {module:engine/model/range~Range} New valid range for the fake visual selection marker.
function getNextValidRange( range, focus, writer ) {
const nextStartPath = [ range.start.path[ 0 ] + 1, 0 ];
const nextStartPosition = writer.createPositionFromPath( range.start.root, nextStartPath, 'toNext' );
const nextRange = writer.createRange( nextStartPosition, range.end );

// Block creating a potential next valid range over the current range end.
if ( nextRange.start.path[ 0 ] > range.end.path[ 0 ] ) {
return writer.createRange( focus );
}

if ( nextStartPosition.isAtStart && nextStartPosition.isAtEnd ) {
return getNextValidRange( nextRange, focus, writer );
}

return nextRange;
}

0 comments on commit be55f91

Please sign in to comment.