#13069 closed Bug (fixed)
editable.insertHtml and editable.insertElement behave different with and without range parameter
| Reported by: | Piotr Jasiun | Owned by: | Piotr Jasiun |
|---|---|---|---|
| Priority: | Normal | Milestone: | CKEditor 4.5.0 Beta |
| Component: | General | Version: | 4.3 Beta |
| Keywords: | Cc: |
Description
If we pass range parameter to editable.insertHtml or editable.insertElement these methods use editable.insert*IntoRange which are low level methods (do not save snapshot, do not focus editor, do not scroll view). If we do not add the range parameter then editable.insert*IntoSelection methods are used which are high level methods (focus editor, save snapshot, scroll view). Because editable.insert*IntoRange and editable.insert*IntoSelection are different level API, this does not make sens that insert* works differently depending on the third parameter. It is unclear that editor will not do the snapshot if you give the range parameter and unclear how to use these methods (what addition operations should be done if range parameter is passed). To solve this problem editable.insertHtml and editable.insertElement should save snapshot (and do the rest of the needed operations) does not matter if range is passed or not.
Since this weird behavior is not documented I report this ticket as a bug.
Change History (4)
comment:1 Changed 11 years ago by
| Owner: | set to Piotr Jasiun |
|---|---|
| Status: | new → review |
comment:2 Changed 11 years ago by
| Milestone: | CKEditor 4.5.0 → CKEditor 4.5.0 Beta |
|---|
comment:3 Changed 11 years ago by
| Resolution: | → fixed |
|---|---|
| Status: | review → closed |
I removed the insertHtmlIntoSelection method and marked insertElementIntoSelection as deprecated.
Merged to major with git:b06d8e3.

After changes we have 4 cases:
insert[Element|Html]IntoRange- low level methods which just insert data into given range and do nothing more,insert[Element|Html](without range parameter) - which insert data into current selection, select it and do undo snapshot,insert[Element|Html](with range parameter) - which insert data into the given range, select it and do undo snapshot; note that this is totally different case theninsert[Element|Html]IntoRange, here the range parameter is only to handle situation where we can not select range where we want to insert HTML,insert[Element|Html]IntoSelection- which are just aliases for theinsert[Element|Html]; in my opinion these methods may be marked as deprecated (actually one of then, the other could be removed, because it was introduced in 4.5).Working on these changes I realized that there was in fact a mess. The only red test after changes was about
intoRangeparameter of theafterInsertHtml. This parameter was set when user useinsertHtmlwith the range parameter what did not make sense when user wanted to have that range selected (intoRangewas created to mark that insertion is not in the current selection and the inserted content (eg. widget) should not be selected).The only change which is not backward compatible is that
insertElementwith therangedo additional operations. To keep the previous behavior user need to useinsertElementIntoRange.Changes in t/13069.