Shrink long comments instead of growing the comment box
The comment box is capped at about five lines (--comment-max). A comment that does not fit is set smaller step by step (Comments.fit(), also on resize) instead of being cut off or pushing the slide off screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bbe3dfcc8e
commit
b5ea4e70c8
3 files changed
+32
-2
No files matched your search
@@ -392,6 +392,29 @@
|
||||
return node;
|
||||
},
|
||||
|
||||
/**
|
||||
* The box has a maximum height (CSS --comment-max); a comment that does not fit is set
|
||||
* smaller step by step instead of being cut off. The invisible sizers are capped the same
|
||||
* way, so a single long comment does not make the box huge.
|
||||
*/
|
||||
fit: function () {
|
||||
var node = Comments.node;
|
||||
if (!node || !document.body.contains(node)) {
|
||||
return;
|
||||
}
|
||||
var current = node.querySelector('.comments__current');
|
||||
var text = node.querySelector('[data-comment-text]');
|
||||
var size = 1;
|
||||
text.style.fontSize = '';
|
||||
while (current.scrollHeight > current.clientHeight + 1 && size > Comments.MIN_FONT) {
|
||||
size = Math.max(Comments.MIN_FONT, size - 0.05);
|
||||
text.style.fontSize = 'calc(' + size + ' * var(--comment-size))';
|
||||
}
|
||||
},
|
||||
|
||||
// Smallest font size (factor) for a long comment.
|
||||
MIN_FONT: 0.5,
|
||||
|
||||
step: function (delta) {
|
||||
var n = Comments.items.length;
|
||||
Comments.index = (Comments.index + delta + n) % n;
|
||||
@@ -472,6 +495,8 @@
|
||||
void text.offsetWidth; // restart the CSS animation
|
||||
text.classList.add('is-entering');
|
||||
}
|
||||
// Measure once the box is in the document (render() calls this before it is attached).
|
||||
requestAnimationFrame(Comments.fit);
|
||||
var toggle = node.querySelector('[data-comment-action="toggle"]');
|
||||
if (toggle) {
|
||||
var label = Comments.paused ? 'Kommentare automatisch weiterblättern' : 'Automatisches Weiterblättern anhalten';
|
||||
@@ -483,6 +508,8 @@
|
||||
Comments.progress();
|
||||
}
|
||||
};
|
||||
// A different width changes the line breaks: fit the comment again.
|
||||
window.addEventListener('resize', function () { Comments.fit(); });
|
||||
|
||||
// ------------------------------------------------------------------ results
|
||||
|
||||
|
||||
Reference in new issue
Block a user