From d354b34fa6250539246968fcef5298b5ab53beeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 25 Jan 2021 23:41:35 +0100 Subject: [PATCH] CommentController: Even better handle clicking links while already commenting If the user is clicking on a new topic link, and a reply widget is open, attempt to close it instead of doing nothing. Bug: T272545 Change-Id: I1903f5ae4c9e98c4b3a4703ad0e44d772894592a --- modules/controller.js | 9 +++++++++ modules/dt.ui.ReplyWidget.js | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/controller.js b/modules/controller.js index 945ee7600..e586cbb49 100644 --- a/modules/controller.js +++ b/modules/controller.js @@ -312,6 +312,15 @@ function init( $container, state ) { return; } + // If this is a new topic link, and a reply widget is open, attempt to close it first. + if ( activeController && c instanceof NewTopicController ) { + activeController.replyWidget.tryTeardown().then( function () { + activeController = c; + c.setup(); + } ); + return; + } + // If another reply widget is open (or opening), do nothing. if ( activeController ) { return; diff --git a/modules/dt.ui.ReplyWidget.js b/modules/dt.ui.ReplyWidget.js index 801fd3edd..6935eaeb3 100644 --- a/modules/dt.ui.ReplyWidget.js +++ b/modules/dt.ui.ReplyWidget.js @@ -472,7 +472,7 @@ ReplyWidget.prototype.afterSetup = function () { * Try to teardown the widget, prompting the user if unsaved changes will be lost. * * @chainable - * @return {ReplyWidget} + * @return {jQuery.Promise} Resolves if widget was torn down, rejects if it wasn't */ ReplyWidget.prototype.tryTeardown = function () { var promise, @@ -498,10 +498,10 @@ ReplyWidget.prototype.tryTeardown = function () { type: 'nochange' } ); } - promise.then( function () { + promise = promise.then( function () { widget.teardown( true ); } ); - return this; + return promise; }; /**