From 2798ee73f4fd38ce912f5f450d05ce62d1a44a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Tue, 19 Jan 2021 20:45:42 +0100 Subject: [PATCH] CommentController: Better handle clicking links while already commenting Bug: T272389 Change-Id: If28a6cce250dca4810de3f51c0a2a4587d00649e --- modules/CommentController.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/CommentController.js b/modules/CommentController.js index ac594c7b3..67ccc81e1 100644 --- a/modules/CommentController.js +++ b/modules/CommentController.js @@ -109,15 +109,33 @@ CommentController.prototype.onReplyLinkClick = function ( e ) { // Only handle keypresses on the "Enter" or "Space" keys return; } - // TODO: Allow users to use multiple reply widgets simultaneously. - // Currently submitting a reply from one widget would also destroy the other ones. - // eslint-disable-next-line no-jquery/no-class-state - if ( this.$pageContainer.hasClass( 'dt-init-replylink-open' ) ) { - // Support: IE 11 - // On other browsers, the link is made unclickable using 'pointer-events' in CSS + if ( e.type === 'click' && ( e.which !== OO.ui.MouseButtons.LEFT || e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ) ) { + // Only handle unmodified left clicks return; } + e.preventDefault(); + + // TODO: Allow users to use multiple reply widgets simultaneously. + // Currently submitting a reply from one widget would also destroy the other ones. + + // If the reply widget is already open, activate it. + // Reply links are also made unclickable using 'pointer-events' in CSS, but that doesn't happen + // for new section links, because we don't have a good way of visually disabling them. + // (And it also doesn't work on IE 11.) + if ( this.opened ) { + // Show and focus the widget + this.replyWidget.scrollElementIntoView( { padding: scrollPadding } ); + this.focus(); + return; + } + + // If another reply widget is open (or opening), do nothing. + // eslint-disable-next-line no-jquery/no-class-state + if ( this.$pageContainer.hasClass( 'dt-init-replylink-open' ) ) { + return; + } + this.setup(); }; @@ -224,6 +242,7 @@ CommentController.prototype.setupReplyWidget = function ( replyWidget, data ) { replyWidget.setup( data ); this.replyWidget = replyWidget; + this.opened = true; }; /** @@ -250,6 +269,7 @@ CommentController.prototype.teardown = function ( abandoned ) { } modifier.removeAddedListItem( this.newListItem ); this.newListItem = null; + this.opened = false; if ( abandoned ) { this.$replyLink.trigger( 'focus' ); }