Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 13, 2025

Problem

When scrolling through a notebook, sticky scroll headers would appear too late or not at all. For example, a header in cell 0 would not be revealed as sticky until much later when scrolling through content under that header.

Root Cause

The computeContent function in notebookEditorStickyScroll.ts was limited to searching for headers only within the visible range of cells. It would start looking from visibleRange.start - 1 and search forward, missing headers that were far above the viewport but still relevant to the current section.

Solution

Modified the algorithm to search backwards from the first visible cell (visibleRange.start) to find the most recent header, instead of searching forward from visibleRange.start - 1.

Before:

// Only looked from visible range backwards by 1
const startIndex = visibleRange.start - 1;
for (let currentIndex = startIndex; currentIndex < visibleRange.end; currentIndex++) {
    // Would miss headers far above viewport
}

After:

// Search backwards from first visible cell to find relevant headers
for (let i = visibleRange.start; i >= 0; i--) {
    const candidateEntry = NotebookStickyScroll.getVisibleOutlineEntry(i, notebookOutlineEntries);
    if (candidateEntry && candidateEntry.level < 7) {
        cellEntry = candidateEntry;
        break;
    }
}

Testing

Added test8 that reproduces the scenario where a header at cell 0 should be sticky when viewing cells 4-7, ensuring headers far from the viewport are properly detected.

The fix is minimal and focused - it reduces code complexity (6 additions, 32 deletions) while addressing the core issue.

Fixes #251415.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • electronjs.org
    • Triggering command: node-gyp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits June 13, 2025 18:01
Co-authored-by: Yoyokrazy <12552271+Yoyokrazy@users.noreply.github.com>
Co-authored-by: Yoyokrazy <12552271+Yoyokrazy@users.noreply.github.com>
Copilot AI changed the title [WIP] copilot -- Notebook sticky scroll does not show correct element based viewport Fix notebook sticky scroll headers appearing too late when scrolling Jun 13, 2025
Copilot AI requested a review from Yoyokrazy June 13, 2025 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

copilot -- Notebook sticky scroll does not show correct element based viewport

2 participants