CommentController#showAndFocus: Use replyWidgetPromise

We shouldn't assume callers of this method have waited
for the replyWidget to be built.

Bug: T354292
Change-Id: Ic66b4f04b8786b07f520e329adda37efcf498dad
This commit is contained in:
Ed Sanders 2024-01-05 15:26:19 +00:00
parent 555cfcc622
commit 811dce7bf7
2 changed files with 10 additions and 4 deletions

View file

@ -345,12 +345,19 @@ CommentController.prototype.focus = function () {
this.replyWidget.focus();
};
/**
* Scroll the widget into view and focus it
*/
CommentController.prototype.showAndFocus = function () {
var commentController = this;
this.replyWidget.scrollElementIntoView( { padding: scrollPadding } )
.then( function () {
commentController.focus();
if ( this.replyWidgetPromise ) {
this.replyWidgetPromise.then( function ( replyWidget ) {
replyWidget.scrollElementIntoView( { padding: scrollPadding } )
.then( function () {
commentController.focus();
} );
} );
}
};
CommentController.prototype.teardown = function ( mode ) {

View file

@ -430,7 +430,6 @@ function init( $container, state ) {
// 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 ( activeCommentId === commentId ) {
activeController.showAndFocus();
return;