Skip to content

Commit

Permalink
[BUGFIX] Preserve selection ranges in RteLinkBrowser
Browse files Browse the repository at this point in the history
When the RteLinkBrowser is opened, any active ranges are now backed up
and reused later when an element gets linked. This fixes clashes with
the browser's internal search feature that overrides the `Selection`
object.

Resolves: #90952
Releases: master, 9.5
Change-Id: I155157e808370cd5ff05076a6c82f09da3b0cb3c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63985
Tested-by: Josef Glatz <josefglatz@gmail.com>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Josef Glatz <josefglatz@gmail.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
  • Loading branch information
andreaskienast committed Apr 5, 2020
1 parent 2a8ca70 commit d16e72e
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -20,12 +20,13 @@ define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser', 'TYPO3/CMS/Backend/Modal']

/**
*
* @type {{plugin: null, CKEditor: null, siteUrl: string}}
* @type {{plugin: null, CKEditor: null, ranges: null, siteUrl: string}}
* @exports TYPO3/CMS/RteCkeditor/RteLinkBrowser
*/
var RteLinkBrowser = {
plugin: null,
CKEditor: null,
ranges: null,
siteUrl: ''
};

Expand All @@ -51,6 +52,9 @@ define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser', 'TYPO3/CMS/Backend/Modal']
});
}

// Backup all ranges that are active when the Link Browser is requested
RteLinkBrowser.ranges = RteLinkBrowser.CKEditor.getSelection().getRanges();

// siteUrl etc are added as data attributes to the body tag
$.extend(RteLinkBrowser, $('body').data());

Expand Down Expand Up @@ -116,6 +120,7 @@ define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser', 'TYPO3/CMS/Backend/Modal']
linkElement.setAttribute('href', link);

var selection = RteLinkBrowser.CKEditor.getSelection();
selection.selectRanges(RteLinkBrowser.ranges);
if (selection && selection.getSelectedText() === '') {
selection.selectElement(selection.getStartElement());
}
Expand Down

0 comments on commit d16e72e

Please sign in to comment.