Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

Description

Folded markdown cells in notebooks display their preview content on reopen, causing visual overlap. This occurs because cells render before folding state is restored—previews are created when getHiddenRanges() returns empty, then persist when folding is applied.

Changes

Two-part fix in markupCell.ts:

  1. Trigger view update on folding state change - When foldingStateChanged fires (including during state restoration), call viewUpdate() to re-evaluate preview visibility with current hidden ranges

  2. Check hidden ranges before creating preview - In viewUpdatePreview(), check if cell is in a folded region using populated getHiddenRanges(). If hidden, call hideMarkupPreviews() instead of createMarkupPreview()

// In viewUpdatePreview()
const viewModel = this.notebookEditor.getViewModel();
if (viewModel) {
    const modelIndex = viewModel.getCellIndex(this.viewCell);
    const foldedRanges = viewModel.getHiddenRanges();
    const isHidden = foldedRanges.some(range => 
        modelIndex >= range.start && modelIndex <= range.end);
    
    if (isHidden) {
        this.notebookEditor.hideMarkupPreviews([this.viewCell]);
        return;
    }
}

This retroactively hides previews created during initialization once hidden ranges are available.

Original prompt

This section details on the original issue you should resolve

<issue_title>folded markdown cell will show the preview when the file reopened but the cell is still folded</issue_title>
<issue_description>### Applies To

  • Notebooks (.ipynb files)
  • Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

  1. fold a markdown cell and close vscode
  2. open the vscode with the notebook
  3. the folded markdown cell show the preview automatically and the preview overlap with other texts

But after disable this extension, the notebook will work normal(don't show the preview of folded markdown cell)

This bug often occurs when opening .ipynb files for the first time. Occasionally appearing when switching to an open .ipynb file after a long period of time

this is the screenshot of the bug
overlap with other texts

VS Code Version

版本: 1.97.0 (user setup) 提交: 33fc5a9 日期: 2025-02-04T22:41:26.688Z Electron: 32.2.7 ElectronBuildId: 10660205 Chromium: 128.0.6613.186 Node.js: 20.18.1 V8: 12.8.374.38-electron.0 OS: Windows_NT x64 10.0.22631

Jupyter Extension Version

v2024.11.0

Jupyter logs

Coding Language and Runtime Version

Python 3.12.2

Language Extension Version (if applicable)

v2025.0.0

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

Local</issue_description>

<agent_instructions>Understand how notebook layout works specially for markdown cells.
Then read the code and perform a root cause analysis before finally attempting to fix this</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@DonJayamanne Sorry you are running into this issue and thank you for sharing this. Please can you share this exact same notebook so I can try to repro this at my end as well. Thank ou.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 10, 2025 02:49
- Added check in viewUpdatePreview() to hide preview if cell is in a folded region
- Call viewUpdate() when foldingStateChanged event fires to update preview visibility
- This ensures previews are hidden when folding state is restored after notebook opens

Co-authored-by: DonJayamanne <1948812+DonJayamanne@users.noreply.github.com>
Co-authored-by: DonJayamanne <1948812+DonJayamanne@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix folded markdown cell preview overlap issue Fix folded markdown cells showing preview on notebook reopen Dec 10, 2025
Copilot AI requested a review from DonJayamanne December 10, 2025 02:57
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.

folded markdown cell will show the preview when the file reopened but the cell is still folded

2 participants