Opened 10 years ago

Closed 10 years ago

#10685 closed defect (fixed)

Selection restore issues in Editor on IE

Reported by: Jared Jurkiewicz Owned by: Jared Jurkiewicz
Priority: high Milestone: 1.5
Component: Editor Version: 1.4.0
Keywords: Cc: bill, liucougar, Douglas Hays
Blocked By: Blocking:

Description

This is reported from a co-worker of mine:
================================================
When changing font or size on text selected in the Editor, the styling gets applied to the wrong text.

To reproduce:

  1. Copy the following into an editor. I used the test_Editor.html page from the dijit/tests directory.


Ana Alex Arlene Alberto Andrea Arthur
Ana Alex Arlene Alberto Andrea Arthur
Ana Alex Arlene Alberto Andrea Arthur
Ana Alex Arlene Alberto Andrea Arthur
Ana Alex Arlene Alberto Andrea Arthur

  1. Highlight the 4th "Alex".
  2. Change the size to "xx-large".

You will see the character size of 4th "Alex" is changed.

  1. Then change the size to "xx-small".

Problem:
This procedure should change the character size of 4th "Alex".
However, the character size of 3rd "Alex" is changed.

Changing the size yet again, alters the size of the 2nd "Alex".

This also occurs when changing the fonts.

====================================================

After much debugging I identified this as a problem in IE itself with its moveToBookmark native code. There are cases where IE gets it flat wrong and restores selection to the wrong text. This is one of those cases.

I spoke with Liu Cougar about it and he suggested patching in and using the dijit.range code in place of the IE native bookmark code where possible in the editor to bypass the IE native bookmarks as much as possible. I did that and after a lot of debug and work, I believe I have it working correctly and the selection restores correctly now.

Furthermore, I also verified that our editor behaves much like CKEditor does in IE. Particularly the odd restore behavior if the above text were in a <PRE> tag is exactly duplicated now ... so it seems this approach works as good as the CKEditor, which is a pretty good thing since it is a really good web RTE to compare behavior with.
==============
That all said, it has one drawback. There are cases where selection will not restore right and that case is when IE itself alters the dom on setValue() of editor (innerHTML setting). Sometimes IE decides to add <p> wrappers to root level text, which causes the range code problems as the offsets no longer line up. This is most common when using the undo/redo functions ofeditor. The good news on that, though, is the native bookmark code of IE would have similar issues locating and restoring selection anyway. So it is no worse off than it was as best I can tell. in undo/redo, it restores best it can still ... and with this patch up the failure scneario above is resolved. I will attach a patch soon I would like both Liu Cougar and Bill to review.

Attachments (1)

wc3Range_selectionCodeIE.patch (6.8 KB) - added by Jared Jurkiewicz 10 years ago.
Code that makes use of the dijit.range wc3 API when it can for selection restore on IE. Works better than native bookmarks in many cases.

Download all attachments as: .zip

Change History (5)

Changed 10 years ago by Jared Jurkiewicz

Code that makes use of the dijit.range wc3 API when it can for selection restore on IE. Works better than native bookmarks in many cases.

comment:1 Changed 10 years ago by Jared Jurkiewicz

The patch passes all current unit tests, which is good as many do use the selection restore code paths.

comment:2 Changed 10 years ago by Jared Jurkiewicz

Owner: set to Jared Jurkiewicz

comment:3 Changed 10 years ago by liucougar

I suggest to remove the following if/else block

// Check to see if the selection/bookmark is outside our edit area, if it is, 
// then we need to ignore it.
if...
else...

and instead, add a try{}catch around this if block:

if(b.mark && b.mark.startContainer){ ...

because if the start/endContainer is not within editor.editNode, dijit.range.getIndex will fail

comment:4 Changed 10 years ago by Jared Jurkiewicz

Resolution: fixed
Status: newclosed

(In [21280]) Fixing selection restore issue in IE, native bookmarks are too innacurate. fixes #10685

Note: See TracTickets for help on using tickets.