Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/155619
Change subject: Fallback to node position when getting selection rectangle
......................................................................
Fallback to node position when getting selection rectangle
Another common case on get(Start|End)DocumentPos failing is when
you are inside an empty paragraph. If focusNode is an element, just
use the left/right border of the element bounding rectangle as the
cursor position (depending on directionality).
Bug: 69122
Change-Id: I3c5087dff981868a8c5919b580990d8ae899e3c3
---
M src/ce/ve.ce.Surface.js
1 file changed, 23 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/19/155619/1
diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 6dbadea..430b1d5 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -273,7 +273,7 @@
* @returns {Object|null} { start: { x: ..., y: ... }, end: { x: ..., y: ... }
}
*/
ve.ce.Surface.prototype.getSelectionRect = function () {
- var sel, boundingRect;
+ var sel, x, rtl, boundingRect;
if ( this.focusedNode ) {
boundingRect = this.focusedNode.getBoundingRect();
@@ -300,15 +300,34 @@
return null;
}
- // Calling get(Start|End)DocumentPos() sometimes fails in Firefox on
page load
- // when the address bar is still focused
+ // Calling get(Start|End)DocumentPos() sometimes fails:
+ // * in Firefox on page load when the address bar is still focused
+ // * in empty paragraphs
try {
return {
start: sel.getStartDocumentPos(),
end: sel.getEndDocumentPos()
};
} catch ( e ) {
- return null;
+ // When possible, pretend the cursor is the left/right border
of the node
+ // (depending on directionality) as a fallback.
+ if ( sel.focusNode && sel.focusNode.nodeType ===
Node.ELEMENT_NODE ) {
+ boundingRect = sel.focusNode.getBoundingClientRect();
+ rtl = this.getModel().getDocument().getDir() === 'rtl';
+ x = rtl ? boundingRect.right : boundingRect.left;
+ return {
+ start: {
+ x: x,
+ y: boundingRect.top
+ },
+ end: {
+ x: x,
+ y: boundingRect.bottom
+ }
+ };
+ } else {
+ return null;
+ }
}
};
--
To view, visit https://gerrit.wikimedia.org/r/155619
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c5087dff981868a8c5919b580990d8ae899e3c3
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits