diff --git a/modules/dt-ve/CommentTarget.js b/modules/dt-ve/CommentTarget.js index c4b925641..10ca4e6bc 100644 --- a/modules/dt-ve/CommentTarget.js +++ b/modules/dt-ve/CommentTarget.js @@ -88,21 +88,30 @@ if ( OO.ui.isMobile() ) { CommentTarget.static.importRules = ve.copy( CommentTarget.static.importRules ); -CommentTarget.static.importRules.external.conversions = ve.extendObject( - {}, - CommentTarget.static.importRules.external.conversions, - { - mwHeading: 'paragraph' - } -); - CommentTarget.static.importRules.external.blacklist = ve.extendObject( {}, CommentTarget.static.importRules.external.blacklist, { // Annotations // Allow pasting external links - 'link/mwExternal': false, + 'link/mwExternal': false + } +); + +CommentTarget.static.importRulesForReplyTool = ve.copy( CommentTarget.static.importRules ); + +CommentTarget.static.importRulesForReplyTool.external.conversions = ve.extendObject( + {}, + CommentTarget.static.importRulesForReplyTool.external.conversions, + { + mwHeading: 'paragraph' + } +); + +CommentTarget.static.importRulesForReplyTool.external.blacklist = ve.extendObject( + {}, + CommentTarget.static.importRulesForReplyTool.external.blacklist, + { // Strip all table structure mwTable: true, tableSection: true, @@ -122,8 +131,10 @@ CommentTarget.prototype.getSurfaceConfig = function ( config ) { config = ve.extendObject( { mode: this.defaultMode }, config ); return CommentTarget.super.prototype.getSurfaceConfig.call( this, ve.extendObject( { commandRegistry: config.mode === 'source' ? registries.wikitextCommandRegistry : registries.commandRegistry, - sequenceRegistry: config.mode === 'source' ? registries.wikitextSequenceRegistry : registries.sequenceRegistry, + sequenceRegistry: config.mode === 'source' ? registries.wikitextSequenceRegistry : + this.replyWidget.isNewTopic ? registries.sequenceRegistry : registries.sequenceRegistryForReplyTool, dataTransferHandlerFactory: config.mode === 'source' ? ve.ui.wikitextDataTransferHandlerFactory : ve.ui.dataTransferHandlerFactory, + importRules: this.replyWidget.isNewTopic ? this.constructor.static.importRules : this.constructor.static.importRulesForReplyTool, // eslint-disable-next-line no-jquery/no-global-selector $overlayContainer: $( '#content' ) }, config ) ); diff --git a/modules/dt-ve/CommentTargetWidget.js b/modules/dt-ve/CommentTargetWidget.js index e43c12741..52bb9d2ae 100644 --- a/modules/dt-ve/CommentTargetWidget.js +++ b/modules/dt-ve/CommentTargetWidget.js @@ -11,8 +11,23 @@ var CommentTarget = require( './CommentTarget.js' ); * @param {Object} [config] Configuration options */ function CommentTargetWidget( replyWidget, config ) { - config = $.extend( {}, { - excludeCommands: [ + var excludeCommands = [ + 'blockquoteWrap', // T258194 + // Disable to allow Tab/Shift+Tab to move focus out of the widget (T172694) + 'indent', + 'outdent', + // Save commands get loaded from articletarget module, which we load + // to get the edit switching tool for mobile + 'showSave', + 'showChanges', + 'showPreview', + 'saveMinoredit', + 'saveWatchthis' + ]; + + if ( !replyWidget.isNewTopic ) { + excludeCommands = excludeCommands.concat( [ + // Disable commands for things whose wikitext markup doesn't work when indented 'heading1', 'heading2', 'heading3', @@ -21,20 +36,12 @@ function CommentTargetWidget( replyWidget, config ) { 'heading6', 'insertTable', 'transclusionFromSequence', // T253667 - 'blockquoteWrap', // T258194 - // Disable to allow Tab/Shift+Tab to move focus out of the widget (T172694) - 'indent', - 'outdent', - // Disable preformatted - 'preformatted', - // Save commands get loaded from articletarget module, which we load - // to get the edit switching tool for mobile - 'showSave', - 'showChanges', - 'showPreview', - 'saveMinoredit', - 'saveWatchthis' - ] + 'preformatted' + ] ); + } + + config = $.extend( {}, { + excludeCommands: excludeCommands }, config ); this.replyWidget = replyWidget; diff --git a/modules/dt-ve/dt.ui.registries.js b/modules/dt-ve/dt.ui.registries.js index 7e4eb2a5e..c8f289b53 100644 --- a/modules/dt-ve/dt.ui.registries.js +++ b/modules/dt-ve/dt.ui.registries.js @@ -57,43 +57,46 @@ sequenceRegistry.register( // TODO: Show a warning when typing ~~~~ in wikitext mode? -// Show wikitext warnings for disabled sequences (disabled via excludeCommand): +// Show wikitext warnings for disabled sequences (disabled via excludeCommands): +var sequenceRegistryForReplyTool = new ve.ui.SequenceRegistry(); +importRegistry( sequenceRegistry, sequenceRegistryForReplyTool ); // insertTable -sequenceRegistry.register( - new ve.ui.Sequence( 'wikitextTable', 'mwWikitextWarning', '{|' ) +sequenceRegistryForReplyTool.unregister( 'wikitextTable' ); +sequenceRegistryForReplyTool.register( + new ve.ui.Sequence( 'wikitextTableWarning', 'mwWikitextWarning', '{|' ) ); -ve.ui.commandHelpRegistry.unregister( 'table' ); // transclusionFromSequence -sequenceRegistry.register( - new ve.ui.Sequence( 'wikitextTemplate', 'mwWikitextWarning', '{{' ) +sequenceRegistryForReplyTool.unregister( 'wikitextTemplate' ); +sequenceRegistryForReplyTool.register( + new ve.ui.Sequence( 'wikitextTemplateWarning', 'mwWikitextWarning', '{{' ) ); -ve.ui.commandHelpRegistry.unregister( 'template' ); -// blockquoteWrap +// blockquoteWrap - note, this one applies to `sequenceRegistry` as well +sequenceRegistry.unregister( 'wikitextDescription' ); sequenceRegistry.register( - new ve.ui.Sequence( 'wikitextDescription', 'mwWikitextWarning', [ { type: 'paragraph' }, ':' ] ) + new ve.ui.Sequence( 'wikitextDescriptionWarning', 'mwWikitextWarning', [ { type: 'paragraph' }, ':' ] ) ); -ve.ui.commandHelpRegistry.unregister( 'blockquote' ); // heading1-6 // This sequence doesn't usually have a command as we don't know what // heading level is required, but for warnings this doesn't matter. -sequenceRegistry.register( - new ve.ui.Sequence( 'wikitextHeading', 'mwWikitextWarning', [ { type: 'paragraph' }, '=', '=' ] ) +sequenceRegistryForReplyTool.unregister( 'wikitextHeading' ); +sequenceRegistryForReplyTool.register( + new ve.ui.Sequence( 'wikitextHeadingWarning', 'mwWikitextWarning', [ { type: 'paragraph' }, '=', '=' ] ) ); -ve.ui.commandHelpRegistry.unregister( 'heading2' ); // horizontal rule -sequenceRegistry.register( - new ve.ui.Sequence( 'horizontalRule', 'mwWikitextWarning', [ { type: 'paragraph' }, '-', '-', '-', '-' ] ) +sequenceRegistryForReplyTool.unregister( 'horizontalRule' ); +sequenceRegistryForReplyTool.register( + new ve.ui.Sequence( 'horizontalRuleWarning', 'mwWikitextWarning', [ { type: 'paragraph' }, '-', '-', '-', '-' ] ) ); -ve.ui.commandHelpRegistry.unregister( 'horizontalRule' ); module.exports = { commandRegistry: commandRegistry, sequenceRegistry: sequenceRegistry, + sequenceRegistryForReplyTool: sequenceRegistryForReplyTool, wikitextCommandRegistry: wikitextCommandRegistry, wikitextSequenceRegistry: wikitextSequenceRegistry };