From 26cd9e3a13cd21b1d128eb85d6fb2b787834055c Mon Sep 17 00:00:00 2001 From: Bauke Date: Sun, 12 Jan 2020 22:17:45 +0100 Subject: [PATCH] Fix: Uncollapse all comments when the target is invisible (fixes #8). --- source/ts/scripts/jump-to-new-comment.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/ts/scripts/jump-to-new-comment.ts b/source/ts/scripts/jump-to-new-comment.ts index 247bd06..586c82c 100644 --- a/source/ts/scripts/jump-to-new-comment.ts +++ b/source/ts/scripts/jump-to-new-comment.ts @@ -27,8 +27,15 @@ function clickHandler(): void { // Scroll to the first new comment and remove the `.is-comment-new` class // from it. const newestComment: HTMLElement = querySelector('.comment.is-comment-new'); - // TODO: Check if the new comment is collapsed or is inside a collapsed - // comment and uncollapse it if so. + if (newestComment.offsetParent === null) { + // TODO: Instead of expanding all comments, only expand the ones necessary + // to make the comment visible. + const expandAllButton: HTMLButtonElement = querySelector( + '[data-js-comment-expand-all-button]' + ); + expandAllButton.click(); + } + newestComment.scrollIntoView({behavior: 'smooth'}); // TODO: Don't immediately remove the class after scrolling to it. But remove // it when scrolling to the next new comment after this one. I've decided to