Opened 8 years ago

Last modified 8 years ago

#14760 confirmed Bug

ScrollIntoView also expands selection to entire paragraph

Reported by: David Pidcock Owned by:
Priority: Normal Milestone:
Component: General Version: 4.0
Keywords: Cc:

Description

Steps to reproduce

  1. With the example page, select some text (anywhere seems to work).
  2. Hit the button -- which runs the following code :
       function scroll() {
          var selection = editor.getSelection();
          selection.scrollIntoView();
        } 
    

Expected result

The selection is scrolled into view, but remains the same selected text.

Actual result

The selection expands to the enclosing paragraph.

Other details (browser, OS, CKEditor version, installed plugins)

Tested on Chrome

Attachments (1)

test_scrollIntoView.html (8.3 KB) - added by David Pidcock 8 years ago.
Minimum test example

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by David Pidcock

Attachment: test_scrollIntoView.html added

Minimum test example

comment:1 Changed 8 years ago by David Pidcock

One extra detail : the problem doesn't appear if the very first character in the paragraph is the start of the selection.

comment:2 Changed 8 years ago by David Pidcock

Preliminary investigation shows that the range is expanding to the paragraph at this line:

https://github.com/ckeditor/ckeditor-dev/blob/master/core/dom/range.js#L2744

I can work around this bug by restoring the selection manually.

function scroll() {
      var selection = editor.getSelection();
      var ranges = selection.getRanges();
      selection.scrollIntoView();
      selection.selectRanges(ranges);
    }

comment:3 Changed 8 years ago by Jakub Ś

Status: newconfirmed
Version: 4.5.10 (GitHub - master)4.0

Problem can be reproduced from CKEditor 4.0 at least in all browsers.

Your workaround is currently the only solution:

function scroll() {
   var selection = editor.getSelection();
   var ranges = selection.getRanges();
   selection.scrollIntoView();
   selection.selectRanges(ranges);
}
//or
function scroll() {
   var selection = editor.getSelection();
   var range = selection.getRanges()[0];
   selection.scrollIntoView();
   range.select();
}


Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy