summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Florent <cheap.glitch@gmail.com> 2021-10-14 12:49:30 +0200
committerGravatar GitHub <noreply@github.com> 2021-10-14 12:49:30 +0200
commit9e2bf1a28f4471b65be17f42d0e1fb1aee2a44fc (patch)
tree3da6d9e93fed099ff131f24144467a93474aed05
parentff74497c08232f700c82a03e025f3c5f11928ce5 (diff)
downloadrefined-github-9e2bf1a28f4471b65be17f42d0e1fb1aee2a44fc.tar.gz
refined-github-9e2bf1a28f4471b65be17f42d0e1fb1aee2a44fc.tar.zst
refined-github-9e2bf1a28f4471b65be17f42d0e1fb1aee2a44fc.zip
Fix `preview-hidden-comments` on review comments (#4915)
-rw-r--r--source/features/preview-hidden-comments.css2
-rw-r--r--source/features/preview-hidden-comments.tsx21
2 files changed, 14 insertions, 9 deletions
diff --git a/source/features/preview-hidden-comments.css b/source/features/preview-hidden-comments.css
index fb23397e..94ccbe73 100644
--- a/source/features/preview-hidden-comments.css
+++ b/source/features/preview-hidden-comments.css
@@ -1,5 +1,5 @@
/* Truncate hidden comment preview text with ellipsis */
-.rgh-preview-hidden-comments :is(.discussion-item-copy, .timeline-comment-header-text) {
+.rgh-preview-hidden-comments :is(.timeline-comment-header-text, summary h3) {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
diff --git a/source/features/preview-hidden-comments.tsx b/source/features/preview-hidden-comments.tsx
index 8dcce777..ebc61f31 100644
--- a/source/features/preview-hidden-comments.tsx
+++ b/source/features/preview-hidden-comments.tsx
@@ -6,18 +6,21 @@ import * as pageDetect from 'github-url-detection';
import features from '.';
import {upperCaseFirst} from '../github-helpers';
-const init = (): void => {
- for (const details of select.all('.minimized-comment:not(.d-none) > details:not(.rgh-preview-hidden-comments)')) {
+function init(): void {
+ // We target `.comment-body` directly because hidden review comments are only loaded when first expanded, except when opening a link
+ // pointing to another review comment in the same thread (e.g. https://github.com/refined-github/refined-github/pull/4520#discussion_r659341139) #4915
+ for (const comment of select.all('.minimized-comment:not(.d-none) > details:not(.rgh-preview-hidden-comments) .comment-body')) {
+ const details = comment.closest('details')!;
details.classList.add('rgh-preview-hidden-comments');
- const commentText = select('.comment-body', details)!.textContent!.trim();
+ const commentText = comment.textContent!.trim();
if (commentText.length === 0) {
continue;
}
const header = select([
- 'summary .timeline-comment-header-text', // Issue and commit comments
- '.discussion-item-icon + div', // Review Comments
+ '.timeline-comment-header-text', // Issue and commit comments
+ 'summary h3', // Review Comments
], details)!;
const reason = /off-topic|hidden/.exec(header.textContent!)?.[0];
@@ -25,12 +28,14 @@ const init = (): void => {
continue;
}
+ // Hidden review comments that have been preloaded have their header text wrapped in an extra <div>
+ const headerTextWrapper = header.tagName === 'H3' ? select(':scope > .d-inline-block:last-child', header) : undefined;
header.append(
- <span className="Details-content--open">{header.firstChild}</span>,
- <span className="Details-content--closed">{`${upperCaseFirst(reason)} — ${commentText}`}</span>,
+ <span className="Details-content--open">{headerTextWrapper ?? header.firstChild}</span>,
+ <span className="Details-content--closed">{`${upperCaseFirst(reason)} — ${commentText.slice(0, 100)}`}</span>,
);
}
-};
+}
void features.add(__filebasename, {
include: [