-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show visual selection on a text when the contextual balloon is displa…
…yed. As asked for link in ckeditor/ckeditor5#4721.
- Loading branch information
Showing
4 changed files
with
85 additions
and
2 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,57 @@ | ||
export const VISUAL_SELECTION_MARKER_NAME = 'aeness-insert-image'; | ||
|
||
/** | ||
* Create a fake visual selection when the contextual balloon is displayed. | ||
* | ||
* This adds a 'aeness-insert-image' marker into the document that is rendered as a highlight on selected text fragment. | ||
*/ | ||
export function createFakeVisualSelection(model) { | ||
model.change( writer => { | ||
const range = model.document.selection.getFirstRange(); | ||
|
||
if ( model.markers.has( VISUAL_SELECTION_MARKER_NAME ) ) { | ||
writer.updateMarker( VISUAL_SELECTION_MARKER_NAME, { range } ); | ||
} else { | ||
writer.addMarker( VISUAL_SELECTION_MARKER_NAME, { | ||
usingOperation: false, | ||
affectsData: false, | ||
range | ||
} ); | ||
} | ||
} ); | ||
} | ||
|
||
/** | ||
* Render the fake visual selection created in {@link #createFakeVisualSelection}. | ||
*/ | ||
export function renderFakeVisualSelection(editor) { | ||
// Renders a fake visual selection marker on an expanded selection. | ||
editor.conversion.for( 'editingDowncast' ).markerToHighlight( { | ||
model: VISUAL_SELECTION_MARKER_NAME, | ||
view: { | ||
classes: [ 'ck-fake-insert-image-aeness-selection' ] | ||
} | ||
} ); | ||
|
||
// Renders a fake visual selection marker on a collapsed selection. | ||
editor.conversion.for( 'editingDowncast' ).markerToElement( { | ||
model: VISUAL_SELECTION_MARKER_NAME, | ||
view: { | ||
name: 'span', | ||
classes: [ 'ck-fake-insert-image-aeness-selection', 'ck-fake-insert-image-aeness-selection_collapsed' ] | ||
} | ||
} ); | ||
} | ||
|
||
|
||
/** | ||
* Hides the fake visual selection created in {@link #createFakeVisualSelection}. | ||
*/ | ||
export function hideFakeVisualSelection(model) { | ||
|
||
if ( model.markers.has( VISUAL_SELECTION_MARKER_NAME ) ) { | ||
model.change( writer => { | ||
writer.removeMarker( VISUAL_SELECTION_MARKER_NAME ); | ||
} ); | ||
} | ||
} |
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