Esanders has uploaded a new change for review.

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

Change subject: Update VE implementation to use model-only inpsectors
......................................................................

Update VE implementation to use model-only inpsectors

As we can't access the view node we have to use stagin transactions
to apply changes to the real document node.

In all cases we can now bypass the parent teardown method as the
model has already been updated.

Depends on If1250402f266 being pulled through to the VE extension.

Bug: 63785
Change-Id: Ic42db8531a5119e8454fb26c80565cef656d3a80
---
M modules/VisualEditor/ve.ui.MWMathInspector.js
1 file changed, 23 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/33/125933/1

diff --git a/modules/VisualEditor/ve.ui.MWMathInspector.js 
b/modules/VisualEditor/ve.ui.MWMathInspector.js
index 7d0a198..ac62041 100644
--- a/modules/VisualEditor/ve.ui.MWMathInspector.js
+++ b/modules/VisualEditor/ve.ui.MWMathInspector.js
@@ -14,12 +14,11 @@
  * @extends ve.ui.MWExtensionInspector
  *
  * @constructor
- * @param {ve.ui.WindowSet} windowSet Window set this inspector is part of
  * @param {Object} [config] Configuration options
  */
-ve.ui.MWMathInspector = function VeUiMWMathInspector( windowSet, config ) {
+ve.ui.MWMathInspector = function VeUiMWMathInspector( config ) {
        // Parent constructor
-       ve.ui.MWExtensionInspector.call( this, windowSet, config );
+       ve.ui.MWExtensionInspector.call( this, config );
 
        this.onChangeHandler = ve.debounce( ve.bind( this.updatePreview, this 
), 250 );
 };
@@ -46,9 +45,13 @@
  * Update the math node rendering to reflect the content entered into the 
inspector.
  */
 ve.ui.MWMathInspector.prototype.updatePreview = function () {
-       var newsrc = this.input.getValue();
+       var mwData = ve.copy( this.node.getAttribute( 'mw' ) ),
+               newsrc = this.input.getValue();
+
+       mwData.body.extsrc = newsrc;
+
        if ( this.visible ) {
-               this.node.update( { 'extsrc': newsrc } );
+               this.getFragment().changeAttributes( { 'mw': mwData } );
        }
 };
 
@@ -59,28 +62,30 @@
        // Parent method
        ve.ui.MWExtensionInspector.prototype.setup.call( this, data );
 
-       var mw, surfaceModel = this.surface.getModel();
+       this.getFragment().getSurface().pushStaging();
 
-       this.node = this.surface.getView().getFocusedNode();
-       if ( !this.node ) {
+       var mwData;
+
+       this.node = this.getFragment().getSelectedNode();
+       if ( !this.node || !( this.node instanceof ve.dm.MWMathNode ) ) {
                // Create a dummy node, needed for live preview
-               mw = {
+               mwData = {
                        'name': 'math',
                        'attrs': {},
                        'body': {
                                'extsrc': ''
                        }
                };
-               surfaceModel.getFragment().collapseRangeToEnd().insertContent( [
+               this.getFragment().collapseRangeToEnd().insertContent( [
                        {
                                'type': 'mwMath',
                                'attributes': {
-                                       'mw': mw
+                                       'mw': mwData
                                }
                        },
                        { 'type': '/mwMath' }
                ] );
-               this.node = this.surface.getView().getFocusedNode();
+               this.node = this.getFragment().getSelectedNode();
        }
 
        this.input.on( 'change', this.onChangeHandler );
@@ -95,21 +100,20 @@
  */
 ve.ui.MWMathInspector.prototype.teardown = function ( data ) {
        var newsrc = this.input.getValue(),
-               surfaceModel = this.surface.getModel();
+               surfaceModel = this.getFragment().getSurface();
 
        this.input.off( 'change', this.onChangeHandler );
 
-       if ( newsrc !== '' ) {
-               // Parent method
-               ve.ui.MWExtensionInspector.prototype.teardown.call( this, data 
);
-       } else {
+       this.getFragment().getSurface().applyStaging();
+
+       if ( newsrc === '' ) {
                // The user tried to empty the node, remove it
                surfaceModel.change( ve.dm.Transaction.newFromRemoval(
                        surfaceModel.getDocument(), this.node.getOuterRange()
                ) );
-               // Grandparent method; we're overriding the parent behavior in 
this case
-               ve.ui.Inspector.prototype.teardown.call( this, data );
        }
+       // Grandparent method; we're overriding the parent behavior with 
applyStaging
+       ve.ui.Inspector.prototype.teardown.call( this, data );
 };
 
 /* Registration */

-- 
To view, visit https://gerrit.wikimedia.org/r/125933
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic42db8531a5119e8454fb26c80565cef656d3a80
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to