ckeditor / ckeditor4

The best enterprise-grade WYSIWYG editor. Fully customizable with countless features and plugins.
https://ckeditor.com/ckeditor-4
Other
5.8k stars 2.48k forks source link

range.scrollIntoView() modify range of text selection #1956

Open msamsel opened 6 years ago

msamsel commented 6 years ago

Are you reporting a feature request or a bug?

BUG

Provide detailed reproduction steps (if any)

  1. range.scrollIntoView for selected text node modifies its range, because set new text of node: https://github.com/ckeditor/ckeditor-dev/blob/c413b2d33d3fc67c111c2db2f485020afaeeaa60/core/dom/range.js#L2812-L2815

Expected result

range remain unchanged

Actual result

range is changed

Other details

Jamby93 commented 2 years ago

Still present as of CKEditor 4.19.0... scrollIntoView seems completely unusable with this issue. See https://plnkr.co/edit/js7F4RMPzMYi59ak as a minimal example. Try select a word then click "Scroll into view": whole paragraph is highlighted. If you simply place the cursor in the middle of any paragraph, after scrollIntoView, the cursor is moved to the start of the paragraph.

It can be worked around using something like this: const selection = editor.getSelection(); const ranges = selection.getRanges(); selection.scrollIntoView(); selection.selectRanges(ranges);

It still feels a pretty odd way to preserve ranges.