You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to ask is it possible to change selection dynamically. I have a case where I need to modify a link through a dialog, but when clicked on the dialog inputs, the selection is reset and I can't seem to modify it again to be the same.
editor.RichTextEditor.add('my-link', {
icon: '<i class="fas fa-link"></i>',
attributes: {title: 'Link'},
result: rte => {
window.rte = rte;
let selection = rte.selection();
// save the initial state of the selection
window.initialSelection = {
anchorNode: selection.anchorNode,
anchorOffset: selection.anchorOffset,
focusNode: selection.focusNode,
focusOffset: selection.focusOffset,
rangeCount: selection.rangeCount,
type: selection.type,
};
openLinkModal(rte.selection());
return false;
}
And then when I have to insert the link:
let addLink = () => {
let linkValue = $('#linkValue').val();
let linkText = $('#linkText').val();
let selection = window.rte.selection();
// Set the selection state to the initial one ?
selection.focusNode = window.initialSelection.focusNode;
selection.anchorOffset = window.initialSelection.anchorOffset;
selection.focusOffset = window.initialSelection.anchorOffset;
selection.rangeCount = window.initialSelection.rangeCount;
selection.type = window.initialSelection.type;
window.rte.insertHTML(`<a href="${linkValue}">${selection}</a>`)
$('#linkModal').modal('hide');
}
Is there an API or something with which I can set the selection's focusNode, offsets, etc. since I can't seem to find one and the above is not working ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello and thanks for the great editor.
I want to ask is it possible to change selection dynamically. I have a case where I need to modify a link through a dialog, but when clicked on the dialog inputs, the selection is reset and I can't seem to modify it again to be the same.
And then when I have to insert the link:
Is there an API or something with which I can set the selection's focusNode, offsets, etc. since I can't seem to find one and the above is not working ?
Beta Was this translation helpful? Give feedback.
All reactions