fix: Search term highlights missing (#12598)

This commit is contained in:
Tom Moor
2026-06-05 17:57:09 -04:00
committed by GitHub
parent 0c0facc2a1
commit aad2483ff9
+14 -1
View File
@@ -604,13 +604,26 @@ export default class FindAndReplaceExtension extends Extension<FindAndReplaceOpt
return {
update: (view) => {
const generation = pluginKey.getState(view.state) as number;
if (generation !== lastGeneration) {
// Rebuild highlights when the results change (generation bump) or,
// while a search is active, on any view update. The CSS Custom
// Highlight API relies on static DOM ranges that become detached
// when the editor re-renders its DOM — e.g. content settling after
// sync when navigating from search results, collaboration cursors,
// or node views mounting — none of which bump the generation. This
// keeps the highlights tracking the live DOM, as decorations do.
if (generation !== lastGeneration || this.searchTerm) {
lastGeneration = generation;
this.updateHighlights();
}
},
destroy: () => {
// The highlight registry is global and keyed by fixed names, so
// only tear down highlights when this editor actually owns an
// active search — otherwise an unmounting editor could wipe the
// highlights another editor just set during a route transition.
if (this.searchTerm) {
this.clearHighlights();
}
},
};
},