Last modified: 2013-05-06 17:37:10 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T49772, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 47772 - VisualEditor: ve.ce.Surface.getSelectionRect() throws errors in Opera
VisualEditor: ve.ce.Surface.getSelectionRect() throws errors in Opera
Status: RESOLVED FIXED
Product: VisualEditor
Classification: Unclassified
ContentEditable (Other open bugs)
unspecified
All All
: Lowest normal
: VE-deploy-2013-05-13
Assigned To: Bartosz Dziewoński
:
Depends on:
Blocks: 36000 37861
  Show dependency treegraph
 
Reported: 2013-04-27 12:33 UTC by Bartosz Dziewoński
Modified: 2013-05-06 17:37 UTC (History)
5 users (show)

See Also:
Web browser: Opera
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Bartosz Dziewoński 2013-04-27 12:33:52 UTC
ve.ce.Surface.getSelectionRect() throws errors in Opera. I think this is the root cause of bug 37861 and likely various other issues.

It seems that rangySel.get{Start,End}DocumentPos consistently fails in Opera, because nativeRange.getClientRects() inside of the private createClientBoundaryPosGetter() function returns an empty collection. This causes the "Cannot get position for range ..." error to be thrown.

I'm still investigating the why, I'm just putting this here. Changing getSelectionRect() to just always return some static value seems to work (or at least not fail miserably anymore).
Comment 1 Bartosz Dziewoński 2013-04-27 13:06:35 UTC
So, what happens is that in Opera, for zero-length ranges (ie, just a caret, no selection):

* .getSelection().getRangeAt(0) returns a Range
* but then .getClientRects() returns an empty ClientRectList
* and .getBoundingClientRect() returns a rectangle with all values being 0
Comment 2 Bartosz Dziewoński 2013-04-27 13:34:22 UTC
This seems to work:

>>> range = document.getSelection().getRangeAt(0)
Range 
>>> span = document.createElement('span')
<span/>
>>> range.getClientRects()
ClientRectList []
>>> range.surroundContents(span)
undefined
>>> $(span).offset()
{ left: 352, top: 1025 }

Now we just have to substract window.scrollY from the 'top' value and remove the <span> from the DOM again. (And don't call .getClientRects() on that Range again, as it returns a completely bonkers huge list of values.)
Comment 3 Gerrit Notification Bot 2013-04-27 17:00:13 UTC
Related URL: https://gerrit.wikimedia.org/r/61190 (Gerrit Change I4bad882d1d6fb83bcdcfd0de3bfc9af52960c2ff)
Comment 4 Bartosz Dziewoński 2013-04-28 16:03:22 UTC
Hmm, apparently this also happens for non-empty selections in some cases. We're gonna need a larger workaround...
Comment 5 Bartosz Dziewoński 2013-04-28 17:02:30 UTC
(Done is PS2.)
Comment 6 Bartosz Dziewoński 2013-05-03 15:37:21 UTC
The fix is merged now. Marking as fixed.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links