#5580·marktext

Find Next / Find Previous re-renders every matching block on each step

Author: ycyc0421Created Sep 28, 2026Updated Sep 28, 2026

Description

In a document with many search matches, each Find Next / Find Previous step (Enter in the search box, the ↑/↓ buttons, or the Edit menu items) takes time proportional to the number of matches in the whole document.

Search#find (packages/muya/src/search/index.ts:122) only moves this.index, then calls _updateMatches(true) and _updateMatches(). Each call walks every block that contains a match and calls block.update() on it, so one step re-renders every matched block twice. Only the block holding the previous active match and the block holding the new one actually change.

Related: #3211 (search and editing are slow in large documents). This issue is the find next/previous part of it.

Steps to Reproduce

  1. Create a test file:
    bash
    for i in $(seq 2000); do printf 'paragraph %d foo\n\n' "$i"; done > many-matches.md
  2. Open many-matches.md in MarkText.
  3. Press Ctrl+F and search for foo.
  4. Press Enter repeatedly to step through the matches.

Expected Behavior

Each step only updates the previous and the new active match.

Actual Behavior

Each step re-renders all 2000 matching paragraphs twice.

Screenshots / Logs

On develop (b0079e1f), one find('next') on a document with 2000 paragraphs and one match in each takes about 1.25 s under vitest + happy-dom. Not yet timed in a packaged build.

Operating System

Linux (Other)

MarkText Version

develop @ b0079e1f (0.20.0-dev)

OS Version

Arch Linux, kernel 7.2.7

Reproducibility

  • I can reliably reproduce this issue