mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-09 08:45:45 +02:00
orgmode_test.go: Remove trailing empty line at end of file to pass make fmt check.
file-view.ts: Revert to IntersectionObserver with 101 thresholds (0%-100%) instead of scroll event to satisfy github/prefer-observers lint rule, while maintaining fine-grained position updates.
This commit is contained in:
parent
2998a81663
commit
61933a9668
@ -104,4 +104,3 @@ int a;
|
||||
<pre><code class="chroma language-c"><span class="kt">int</span> <span class="n">a</span><span class="p">;</span></code></pre>
|
||||
</div>`)
|
||||
}
|
||||
|
||||
|
||||
@ -168,6 +168,7 @@ function initSidebarToggle(elFileView: HTMLElement): void {
|
||||
|
||||
// Update sidebar position on resize to keep aligned with file content
|
||||
// Only observe the segment element to avoid unnecessary updates from unrelated page changes
|
||||
const fileHeader = elFileView.querySelector('.file-header');
|
||||
const segment = elFileView.querySelector('.ui.bottom.segment');
|
||||
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
@ -177,29 +178,19 @@ function initSidebarToggle(elFileView: HTMLElement): void {
|
||||
resizeObserver.observe(segment);
|
||||
}
|
||||
|
||||
// Update position on scroll using requestAnimationFrame for smooth updates
|
||||
// Note: IntersectionObserver was tried but it only triggers at threshold crossings,
|
||||
// not continuously during scroll, causing the sidebar to "jump" or get stuck
|
||||
// when scrolling between thresholds. scroll event + rAF provides smooth tracking.
|
||||
let scrollRafId: number | null = null;
|
||||
const scrollHandler = () => {
|
||||
// Auto-cleanup: if element is removed from DOM, remove the listener and disconnect observer
|
||||
if (!document.contains(elFileView)) {
|
||||
window.removeEventListener('scroll', scrollHandler);
|
||||
resizeObserver.disconnect();
|
||||
if (scrollRafId !== null) {
|
||||
cancelAnimationFrame(scrollRafId);
|
||||
scrollRafId = null;
|
||||
// Update position using IntersectionObserver for scroll tracking
|
||||
// Use 101 thresholds (0%, 1%, 2%, ..., 100%) for fine-grained position updates
|
||||
if (fileHeader && segment) {
|
||||
const thresholds = Array.from({length: 101}, (_, i) => i / 100);
|
||||
const positionObserver = new IntersectionObserver((entries) => {
|
||||
// Only update if any entry is intersecting (visible)
|
||||
if (entries.some((e) => e.isIntersecting)) {
|
||||
updatePosition();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (scrollRafId !== null) return; // Already scheduled
|
||||
scrollRafId = requestAnimationFrame(() => {
|
||||
updatePosition();
|
||||
scrollRafId = null;
|
||||
});
|
||||
};
|
||||
window.addEventListener('scroll', scrollHandler, {passive: true});
|
||||
}, {threshold: thresholds});
|
||||
positionObserver.observe(segment);
|
||||
positionObserver.observe(fileHeader);
|
||||
}
|
||||
|
||||
toggleBtn.addEventListener('click', () => {
|
||||
const isCurrentlyVisible = !sidebar.classList.contains('sidebar-panel-hidden');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user