Catrope has uploaded a new change for review. https://gerrit.wikimedia.org/r/124890
Change subject: Revert "'The great ' + getRandom(classList) + ' rewrite of ' + new Date().getFullYear();" ...................................................................... Revert "'The great ' + getRandom(classList) + ' rewrite of ' + new Date().getFullYear();" Temporarily reverting for dependency hell reasons. Will reintroduce soon. This reverts commit 7203025af78dd42bffd3345d5270c1f0e7a91b80. Change-Id: I303dba9d13a1b296e9316d903d5192d7dfe62daa --- M modules/ve/dm/ve.dm.SurfaceFragment.js M modules/ve/ui/actions/ve.ui.DialogAction.js M modules/ve/ui/actions/ve.ui.InspectorAction.js M modules/ve/ui/dialogs/ve.ui.CommandHelpDialog.js M modules/ve/ui/inspectors/ve.ui.AnnotationInspector.js M modules/ve/ui/inspectors/ve.ui.LanguageInspector.js M modules/ve/ui/inspectors/ve.ui.LinkInspector.js M modules/ve/ui/inspectors/ve.ui.SpecialCharacterInspector.js M modules/ve/ui/ve.ui.Context.js M modules/ve/ui/ve.ui.Dialog.js M modules/ve/ui/ve.ui.Inspector.js M modules/ve/ui/ve.ui.Surface.js M modules/ve/ui/ve.ui.WindowSet.js 13 files changed, 87 insertions(+), 133 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/90/124890/1 diff --git a/modules/ve/dm/ve.dm.SurfaceFragment.js b/modules/ve/dm/ve.dm.SurfaceFragment.js index f5479c4..6047326 100644 --- a/modules/ve/dm/ve.dm.SurfaceFragment.js +++ b/modules/ve/dm/ve.dm.SurfaceFragment.js @@ -380,19 +380,6 @@ }; /** - * Get the node selected by a range, i.e. the range matches the node's range exactly - * - * @returns {ve.dm.Node|null} The node selected by the range, or null if a node is not selected - */ -ve.dm.SurfaceFragment.prototype.getSelectedNode = function () { - var range = this.getRange(), - nodes = this.document.selectNodes( range, 'covered' ), - node = nodes.length === 1 && nodes[0].node ? nodes[0].node : null; - - return node && node.getOuterRange().equalsSelection( range ) ? node : null; -}; - -/** * Get nodes covered by the fragment. * * Does not descend into nodes that are entirely covered by the range. The result is diff --git a/modules/ve/ui/actions/ve.ui.DialogAction.js b/modules/ve/ui/actions/ve.ui.DialogAction.js index 789a20c..42886da 100644 --- a/modules/ve/ui/actions/ve.ui.DialogAction.js +++ b/modules/ve/ui/actions/ve.ui.DialogAction.js @@ -40,18 +40,12 @@ * Open a Dialog. * * @method - * @param {string} name Symbolic name of dialog to open - * @param {Object} [data] Dialog opening data + * @param {string} name Symbolic name of Dialog to open + * @param {Object} [config] Configuration options for dialog setup */ -ve.ui.DialogAction.prototype.open = function ( name, data ) { - var fragment = this.surface.getModel().getFragment( null, true ); - - data = ve.extendObject( { - 'dir': this.surface.getView().documentView.getDirectionFromRange( fragment.getRange() ), - }, data ); - +ve.ui.DialogAction.prototype.open = function ( name, config ) { this.surface.getView().getDocument().getDocumentNode().$element[0].blur(); - this.surface.getDialogs().getWindow( name ).open( fragment, data ); + this.surface.getDialogs().getWindow( name ).open( config ); }; /* Registration */ diff --git a/modules/ve/ui/actions/ve.ui.InspectorAction.js b/modules/ve/ui/actions/ve.ui.InspectorAction.js index 9e51c63..99f9426 100644 --- a/modules/ve/ui/actions/ve.ui.InspectorAction.js +++ b/modules/ve/ui/actions/ve.ui.InspectorAction.js @@ -41,16 +41,10 @@ * * @method * @param {string} name Symbolic name of inspector to open - * @param {Object} [data] Inspector opening data + * @param {Object} [config] Configuration options for inspector setup */ -ve.ui.InspectorAction.prototype.open = function ( name, data ) { - var fragment = this.surface.getModel().getFragment( null, true ); - - data = ve.extendObject( { - 'dir': this.surface.getView().documentView.getDirectionFromRange( fragment.getRange() ), - }, data ); - - this.surface.getContext().getInspector( name ).open( fragment, data ); +ve.ui.InspectorAction.prototype.open = function ( name, config ) { + this.surface.getContext().getInspector( name ).open( config ); }; /* Registration */ diff --git a/modules/ve/ui/dialogs/ve.ui.CommandHelpDialog.js b/modules/ve/ui/dialogs/ve.ui.CommandHelpDialog.js index 0bf0b13..da497ad 100644 --- a/modules/ve/ui/dialogs/ve.ui.CommandHelpDialog.js +++ b/modules/ve/ui/dialogs/ve.ui.CommandHelpDialog.js @@ -12,14 +12,15 @@ * @extends ve.ui.Dialog * * @constructor + * @param {ve.ui.Surface} surface Surface inspector is for * @param {Object} [config] Configuration options */ -ve.ui.CommandHelpDialog = function VeUiCommandHelpDialog( config ) { +ve.ui.CommandHelpDialog = function VeUiCommandHelpDialog( surface, config ) { // Configuration initialization config = ve.extendObject( { 'footless': true }, config ); // Parent constructor - ve.ui.Dialog.call( this, config ); + ve.ui.Dialog.call( this, surface, config ); }; /* Inheritance */ diff --git a/modules/ve/ui/inspectors/ve.ui.AnnotationInspector.js b/modules/ve/ui/inspectors/ve.ui.AnnotationInspector.js index f7fdbd5..579710b 100644 --- a/modules/ve/ui/inspectors/ve.ui.AnnotationInspector.js +++ b/modules/ve/ui/inspectors/ve.ui.AnnotationInspector.js @@ -13,11 +13,12 @@ * @extends ve.ui.Inspector * * @constructor + * @param {ve.ui.Surface} surface Surface inspector is for * @param {Object} [config] Configuration options */ -ve.ui.AnnotationInspector = function VeUiAnnotationInspector( config ) { +ve.ui.AnnotationInspector = function VeUiAnnotationInspector( surface, config ) { // Parent constructor - ve.ui.Inspector.call( this, config ); + ve.ui.Inspector.call( this, surface, config ); // Properties this.previousSelection = null; @@ -128,7 +129,7 @@ ve.ui.Inspector.prototype.setup.call( this, data ); var expandedFragment, trimmedFragment, truncatedFragment, initialCoveringAnnotation, - fragment = this.getFragment(), + fragment = this.surface.getModel().getFragment( null, true ), annotation = this.getMatchingAnnotations( fragment, true ).get( 0 ); this.previousSelection = fragment.getRange(); @@ -194,9 +195,9 @@ set = false, annotation = this.getAnnotation(), remove = this.shouldRemoveAnnotation() || data.action === 'remove', - surfaceModel = this.getFragment().getSurface(), + surfaceModel = this.surface.getModel(), fragment = surfaceModel.getFragment( this.initialSelection, false ), - selection = this.getFragment().getRange(); + selection = surfaceModel.getSelection(); if ( remove ) { clear = true; @@ -227,7 +228,7 @@ } if ( undo ) { // Go back to before we added an annotation - surfaceModel.undo(); + this.surface.execute( 'history', 'undo' ); } if ( clear ) { // Clear all existing annotations @@ -248,7 +249,7 @@ // Restore selection to what it was before we expanded it selection = this.previousSelection; } - surfaceModel.setSelection( selection ); + this.surface.execute( 'content', 'select', selection ); if ( add ) { surfaceModel.addInsertionAnnotations( annotation ); diff --git a/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js b/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js index 2340172..595d38c 100644 --- a/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js +++ b/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js @@ -12,11 +12,12 @@ * @extends ve.ui.AnnotationInspector * * @constructor + * @param {ve.ui.Surface} surface Surface inspector is for * @param {Object} [config] Configuration options */ -ve.ui.LanguageInspector = function VeUiLanguageInspector( config ) { +ve.ui.LanguageInspector = function VeUiLanguageInspector( surface, config ) { // Parent constructor - ve.ui.AnnotationInspector.call( this, config ); + ve.ui.AnnotationInspector.call( this, surface, config ); }; /* Inheritance */ diff --git a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js index 1d8e8a9..41b222f 100644 --- a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js +++ b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js @@ -12,11 +12,12 @@ * @extends ve.ui.AnnotationInspector * * @constructor + * @param {ve.ui.Surface} surface Surface inspector is for * @param {Object} [config] Configuration options */ -ve.ui.LinkInspector = function VeUiLinkInspector( config ) { +ve.ui.LinkInspector = function VeUiLinkInspector( surface, config ) { // Parent constructor - ve.ui.AnnotationInspector.call( this, config ); + ve.ui.AnnotationInspector.call( this, surface, config ); // Properties this.linkNode = null; @@ -98,7 +99,7 @@ // Properties this.targetInput = new this.constructor.static.linkTargetInputWidget( { - '$': this.$, '$overlay': this.$contextOverlay || this.$overlay + '$': this.$, '$overlay': this.surface.context.$element } ); // Initialization @@ -109,13 +110,13 @@ * @inheritdoc */ ve.ui.LinkInspector.prototype.setup = function ( data ) { - var focusedNode = this.getFragment().getSelectedNode(); + var focusedNode = this.surface.getView().getFocusedNode(); if ( focusedNode && - ve.isInstanceOfAny( focusedNode, this.constructor.static.modelClasses ) + ve.isInstanceOfAny( focusedNode.getModel(), this.constructor.static.modelClasses ) ) { - this.linkNode = focusedNode; + this.linkNode = focusedNode.getModel(); // Call grandparent method, skipping AnnotationInspector ve.ui.Inspector.prototype.setup.call( this, data ); } else { @@ -125,7 +126,7 @@ } // Disable surface until animation is complete; will be reenabled in ready() - this.getFragment().getSurface().disable(); + this.surface.disable(); }; /** @@ -149,14 +150,14 @@ this.targetInput.setAnnotation( this.initialAnnotation ); } this.targetInput.$input.select(); - this.getFragment().getSurface().enable(); + this.surface.enable(); }; /** * @inheritdoc */ ve.ui.LinkInspector.prototype.teardown = function ( data ) { - var changes, remove, replace, nodeRange, surfaceModel = this.getFragment().getSurface(); + var changes, remove, replace, nodeRange, surfaceModel = this.surface.getModel(); if ( this.linkNode ) { nodeRange = this.linkNode.getOuterRange(); changes = this.getNodeChanges(); diff --git a/modules/ve/ui/inspectors/ve.ui.SpecialCharacterInspector.js b/modules/ve/ui/inspectors/ve.ui.SpecialCharacterInspector.js index c5960d8..f9c3b7b 100644 --- a/modules/ve/ui/inspectors/ve.ui.SpecialCharacterInspector.js +++ b/modules/ve/ui/inspectors/ve.ui.SpecialCharacterInspector.js @@ -12,17 +12,18 @@ * @extends ve.ui.Inspector * * @constructor - * @param {ve.dm.SurfaceFragment} fragment Surface fragment the inspector is for + * @param {ve.ui.Surface} surface Surface inspector is for * @param {Object} [config] Configuration options */ -ve.ui.SpecialCharacterInspector = function VeUiSpecialCharacterInspector( fragment, config ) { +ve.ui.SpecialCharacterInspector = function VeUiSpecialCharacterInspector( surface, config ) { // Parent constructor - ve.ui.Inspector.call( this, fragment, config ); + ve.ui.Inspector.call( this, surface, config ); this.characters = null; this.$buttonDomList = null; this.initialSelection = null; + this.addedChar = null; this.categories = null; // Fallback character list in case no list is found anywhere @@ -108,7 +109,7 @@ // Preserve initial selection so we can collapse cursor position // after we're done adding - this.initialSelection = this.getFragment().getRange(); + this.initialSelection = this.surface.getModel().getSelection(); // Don't request the character list again if we already have it if ( !this.characters ) { @@ -183,13 +184,31 @@ * Handle the click event on the list */ ve.ui.SpecialCharacterInspector.prototype.onListClick = function ( e ) { - var character = $( e.target ).data( 'character' ); + var fragment, character = $( e.target ).data( 'character' ); if ( character !== undefined ) { - this.getFragment().insertContent( character, false ).collapseRangeToEnd().select(); + fragment = this.surface.getModel().getFragment( null, true ); + fragment.insertContent( character, false ); + this.addedChar = character; } }; +/** + * @inheritdoc + */ +ve.ui.SpecialCharacterInspector.prototype.teardown = function ( data ) { + var selection; + // Collapse selection after the inserted content + if ( this.addedChar ) { + selection = new ve.Range( this.initialSelection.start + this.addedChar.length ); + this.surface.execute( 'content', 'select', selection ); + } + // Reset + this.addedChar = null; + // Parent method + ve.ui.Inspector.prototype.teardown.call( this, data ); +}; + /* Registration */ ve.ui.inspectorFactory.register( ve.ui.SpecialCharacterInspector ); diff --git a/modules/ve/ui/ve.ui.Context.js b/modules/ve/ui/ve.ui.Context.js index 88832d8..7148e9c 100644 --- a/modules/ve/ui/ve.ui.Context.js +++ b/modules/ve/ui/ve.ui.Context.js @@ -22,7 +22,7 @@ // Properties this.surface = surface; - this.inspectors = new ve.ui.WindowSet( ve.ui.inspectorFactory, { '$': this.$, '$contextOverlay': this.$element } ); + this.inspectors = new ve.ui.WindowSet( surface, ve.ui.inspectorFactory ); }; /* Inheritance */ diff --git a/modules/ve/ui/ve.ui.Dialog.js b/modules/ve/ui/ve.ui.Dialog.js index 96f4a27..7ab24c6 100644 --- a/modules/ve/ui/ve.ui.Dialog.js +++ b/modules/ve/ui/ve.ui.Dialog.js @@ -6,54 +6,24 @@ */ /** - * Dialog with an associated surface fragment. + * Dialog with an associated surface. * * @class * @abstract * @extends OO.ui.Dialog * * @constructor + * @param {ve.ui.Surface} surface Surface inspector is for * @param {Object} [config] Configuration options */ -ve.ui.Dialog = function VeUiDialog( config ) { +ve.ui.Dialog = function VeUiDialog( surface, config ) { // Parent constructor OO.ui.Dialog.call( this, config ); // Properties - this.fragment = null; + this.surface = surface; }; /* Inheritance */ OO.inheritClass( ve.ui.Dialog, OO.ui.Dialog ); - -/** - * @param {ve.dm.SurfaceFragment} fragment Surface fragment - * @param {Object} data Dialog opening data - * @param {string} data.dir Directionality of fragment - */ -ve.ui.Dialog.prototype.open = function ( fragment, data ) { - this.fragment = fragment; - - // Parent method - OO.ui.Dialog.prototype.open.call( this, data ); -}; - -/** - * @inheritdoc - */ -ve.ui.Dialog.prototype.teardown = function () { - // Parent method - OO.ui.Dialog.prototype.teardown.apply( this, arguments ); - - this.fragment = null; -}; - -/** - * Get the surface fragment the dialog is for - * - * @returns {ve.dm.SurfaceFragment|null} Surface fragment the dialog is for, null if the dialog is closed - */ -ve.ui.Dialog.prototype.getFragment = function () { - return this.fragment; -}; diff --git a/modules/ve/ui/ve.ui.Inspector.js b/modules/ve/ui/ve.ui.Inspector.js index e609f0f..9d03f62 100644 --- a/modules/ve/ui/ve.ui.Inspector.js +++ b/modules/ve/ui/ve.ui.Inspector.js @@ -13,16 +13,15 @@ * @extends OO.ui.Window * * @constructor + * @param {ve.ui.Surface} surface Surface inspector is for * @param {Object} [config] Configuration options - * @cfg {jQuery} [$contextOverlay] Context overlay layer */ -ve.ui.Inspector = function VeUiInspector( config ) { +ve.ui.Inspector = function VeUiInspector( surface, config ) { // Parent constructor OO.ui.Window.call( this, config ); // Properties - this.$contextOverlay = config.$contextOverlay; - this.fragment = null; + this.surface = surface; // Initialization this.$element.addClass( 've-ui-inspector' ); @@ -54,37 +53,6 @@ ve.ui.Inspector.static.removable = true; /* Methods */ - -/** - * @param {ve.dm.SurfaceFragment} fragment Surface fragment - * @param {Object} data Inspector opening data - * @param {string} data.dir Directionality of fragment - */ -ve.ui.Inspector.prototype.open = function ( fragment, data ) { - this.fragment = fragment; - - // Parent method - OO.ui.Window.prototype.open.call( this, data ); -}; - -/** - * @inheritdoc - */ -ve.ui.Inspector.prototype.close = function () { - // Parent method - OO.ui.Window.prototype.close.apply( this, arguments ); - - this.fragment = null; -}; - -/** - * Get the surface fragment the inspector is for - * - * @returns {ve.dm.SurfaceFragment|null} Surface fragment the inspector is for, null if the inspector is closed - */ -ve.ui.Inspector.prototype.getFragment = function () { - return this.fragment; -}; /** * Handle close button click events. diff --git a/modules/ve/ui/ve.ui.Surface.js b/modules/ve/ui/ve.ui.Surface.js index 5fd6448..0171e35 100644 --- a/modules/ve/ui/ve.ui.Surface.js +++ b/modules/ve/ui/ve.ui.Surface.js @@ -42,7 +42,7 @@ } this.model = new ve.dm.Surface( documentModel ); this.view = new ve.ce.Surface( this.model, this, { '$': this.$ } ); - this.dialogs = new ve.ui.WindowSet( ve.ui.dialogFactory, { '$': this.$ } ); + this.dialogs = new ve.ui.WindowSet( this, ve.ui.dialogFactory, { '$': this.$ } ); this.commands = {}; this.triggers = {}; this.pasteRules = {}; diff --git a/modules/ve/ui/ve.ui.WindowSet.js b/modules/ve/ui/ve.ui.WindowSet.js index 2d60378..14081b0 100644 --- a/modules/ve/ui/ve.ui.WindowSet.js +++ b/modules/ve/ui/ve.ui.WindowSet.js @@ -15,15 +15,16 @@ * constructors accept a surface argument before the config object. * * @constructor + * @param {ve.ui.Surface} surface * @param {OO.Factory} factory Window factory * @param {Object} [config] Configuration options - * @cfg {jQuery} [$contextOverlay] Context overlay layer */ -ve.ui.WindowSet = function VeUiWindowSet( factory, config ) { +ve.ui.WindowSet = function VeUiWindowSet( surface, factory, config ) { // Parent constructor OO.ui.WindowSet.call( this, factory, config ); - this.$contextOverlay = config.$contextOverlay; + // Properties + this.surface = surface; // Initialization this.$element.addClass( 've-ui-windowSet' ); @@ -38,6 +39,23 @@ /** * @inheritdoc */ +ve.ui.WindowSet.prototype.onWindowClose = function ( win, accept ) { + OO.ui.WindowSet.prototype.onWindowClose.call( this, win, accept ); +}; + +/** + * Get the surface. + * + * @method + * @returns {ve.ui.Surface} Surface + */ +ve.ui.WindowSet.prototype.getSurface = function () { + return this.surface; +}; + +/** + * @inheritdoc + */ ve.ui.WindowSet.prototype.createWindow = function ( name ) { - return this.factory.create( name, { '$': this.$, '$contextOverlay': this.$contextOverlay } ); + return this.factory.create( name, this.surface, { '$': this.$ } ); }; -- To view, visit https://gerrit.wikimedia.org/r/124890 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I303dba9d13a1b296e9316d903d5192d7dfe62daa Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Catrope <roan.katt...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits