# Description

https://test2.wikipedia.org/w/index.php?title=User:RYasmeen_(WMF)/sandbox&oldid=87309

Change the first image from Thumbnail to Basic and click on "Apply Changes"
The following error appears in the console and cannot save page or cancel editing the page with VE.

Uncaught Error: Offset could not be translated to a DOM element and offset: 55

Version: unspecified
Severity: normal

# Details

Reference
bz66604
bzimport raised the priority of this task from to Normal.
bzimport set Reference to bz66604.

The problem seems to be in ve.ce.Document.prototype.getNodeAndOffset() where the stack ends up empty but the element is not a slug.

I am pretty certain this happens due to the image with the complex caption that includes {{Cite}} $<ref> and another image inside it. My attempts to sanitize the wikitext and try everything one-by-one failed when I added that piece: [[File:MO-supp-K.svg|thumb]] [[File:MO-supp-K.svg|thumb]] [[File:IMA-johnson1.jpg|right|frameless|caption <ref>{{Cite web|url = http://yahoo.com|title = }}</ref> <ref>reference</ref>{{Citation needed}} [itex]\pi$
[[File:S.M.R.JPG|thumb]]

{{Cite web|url = http://yahoo.com|title = }}

]]

This is the minimum wikitext required to reproduce this issue:
[[File:MO-supp-K.svg|thumb]]
[[File:IMA-johnson1.jpg|right|frameless|

[[File:S.M.R.JPG|thumb]]
{{Cite web|url = http://yahoo.com|title = }}

]]

https://test2.wikipedia.org/wiki/Test66604?veaction=edit

Found the steps to reproduce it from VE :D

1.Open a page with VE
2.Insert an image, keep it thumbnail-right
3.Go to next line of the added image by pressing enter
4.Add another image on the next line, make it frameless right
5.Now in the caption of the second image : Add another image and go to the next line of this image by pressing enter
6.Add anything on the next line of the caption
7.Apply changes
8.Save Page
7.Reopen the page
8.Try to make the first image Thumbnail to Basic

Observed Result:

Uncaught Error: Offset could not be translated to a DOM element and offset: 55
appears in the console and cannot cancel the edit or save the page in VE

I... can no longer reproduce this. I tried the steps in comment 3 as well as the wiki page in comment 2. Maybe this got fixed by Ed's selection-after-deletion fix? Because when we change an image from block to inline, we delete the old image and insert a new one.

Marking as theoretically fixed, then. :-)

On test 2 wiki:
the first case still throws an exception
the second 'minimal' case results in the image being deleted

first case works perfectly in master
second case still results in the image being deleted

Skip over nested handlesOwnChildren nodes in getRelativeOffset

https://gerrit.wikimedia.org/r/144004

Change 144004 merged by jenkins-bot:
Skip over nested handlesOwnChildren nodes in getRelativeOffset

https://gerrit.wikimedia.org/r/144004

Fixes to getRelativeOffset and getRelativeRange

https://gerrit.wikimedia.org/r/144136

Change 144136 merged by jenkins-bot:
Fixes to getRelativeOffset and getRelativeRange

https://gerrit.wikimedia.org/r/144136

Now if I follow the minimal wikitext or the steps to reproduce in a page and try to change the first image from thumbnail to Basic, it moves the image inside the caption of the second image.

Is that how we want it now?

Jdforrester-WMF removed Esanders as the assignee of this task.Sep 16 2015, 11:54 PM
Jdforrester-WMF set Security to None.
Jdforrester-WMF edited a custom field.
Restricted Application added a subscriber: Aklapper. Sep 16 2015, 11:54 PM