Skip to content

edits can leave stale syntax highlighting below the edited line in Markdown and YAML documents #18472

Closed

Description

@kevinushey

System details

RStudio Edition : Desktop
RStudio Version : 2026.08.0-daily (long-standing)
OS Version      : all
R Version       : all

Steps to reproduce the problem

  1. Enable rainbow fenced divs (Tools > Global Options > R Markdown).

  2. Open a plain Markdown (.md) document containing many fenced divs, tall enough to scroll -- e.g. 40 copies of:

    ::: {#block}
    text
    :::
  3. At the very top of the document, insert a new (unclosed) opening fence, e.g. ::: {#outer}.

  4. Scroll down.

Describe the problem in detail

Every fenced div in the document is now nested one level deeper, so all fences should shift to the next rainbow color. Only the first couple of rows update; the rest of the document keeps the old colors indefinitely (confirmed by inspecting the background tokenizer's caches: after the edit, 79 of 81 fence rows in a 160-row document still held stale tokens).

The Ace background tokenizer re-tokenizes the row following an edited row only when the edited row's end state changes. Tokenizer contexts (an rstudio-ace extension used for rainbow parentheses and fenced divs, YAML multiline-string indents, and chunk fence widths) also flow into following rows, but context changes do not propagate invalidation -- so an edit that changes only context data leaves every following row's cached tokens stale.

In R, R Markdown, and Quarto documents this is masked by an unrelated mechanism: modes with a code-model scope tree rebuild the scope tree after every edit, and that path (TokenIterator.tokenizeUpToRow) force-retokenizes every row from the edit point to the end of the document. Modes without a scope tree -- plain Markdown, YAML -- have no such rebuild, and show the stale highlighting. The same applies to YAML multiline strings: re-indenting a | block-scalar opener does not re-highlight the lines below it.

Describe the behavior you expected

Rows below an edit are re-highlighted whenever the edit affects them, whether the dependency is carried by the tokenizer state or by the tokenizer context.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions