Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/106707
Change subject: Move initial selection to first content offset
......................................................................
Move initial selection to first content offset
This stops weird selections when the document starts with an
image or other block element.
Bug: 58248
Change-Id: Ia58535cf50f578f6dc8ed599281fd6ef9f1568c4
---
M modules/ve/ui/ve.ui.Surface.js
1 file changed, 9 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/07/106707/1
diff --git a/modules/ve/ui/ve.ui.Surface.js b/modules/ve/ui/ve.ui.Surface.js
index 27902e7..f60afcb 100644
--- a/modules/ve/ui/ve.ui.Surface.js
+++ b/modules/ve/ui/ve.ui.Surface.js
@@ -100,15 +100,17 @@
* This must be called after the surface has been attached to the DOM.
*/
ve.ui.Surface.prototype.initialize = function () {
- this.view.$element.after( this.$localOverlay );
+ var firstOffset;
+ this.getView().$element.after( this.$localOverlay );
this.$( 'body' ).append( this.$globalOverlay );
- this.view.initialize();
- // By re-asserting the current selection and forcing a poll we force
selection to be something
- // reasonable - otherwise in Firefox, the initial selection is (0,0),
causing bug 42277
- this.model.getFragment().select();
- this.view.surfaceObserver.pollOnce();
- this.model.startHistoryTracking();
+ this.getView().initialize();
+ // Go to the first content offset, or offset 1 if not found (returns -1)
+ firstOffset =
this.getModel().getDocument().data.getNearestContentOffset( 0, 1 );
+ this.getModel().setSelection(
+ new ve.Range( firstOffset !== -1 ? firstOffset : 1 )
+ );
+ this.getModel().startHistoryTracking();
};
/**
--
To view, visit https://gerrit.wikimedia.org/r/106707
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia58535cf50f578f6dc8ed599281fd6ef9f1568c4
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