Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

perf(editor): discard stale code spans before mapping replacements (#35116)

OrcaWina986c8251e25
diff --git a/src/renderer/src/components/editor/rich-markdown-lowlight.ts b/src/renderer/src/components/editor/rich-markdown-lowlight.ts
index ea4a0888939..02b656d6601 100644
--- a/src/renderer/src/components/editor/rich-markdown-lowlight.ts
+++ b/src/renderer/src/components/editor/rich-markdown-lowlight.ts
@@ -151,8 +151,6 @@ function updateDecorations(
return createDecorations(transaction.doc, name, lowlight, languages, defaultLanguage)
}
- // Why: mapped decorations stay valid outside code blocks touched by the transaction.
- let next = decorationSet.map(transaction.mapping, transaction.doc)
const oldBlocks = findCodeBlocksNearRanges(
transaction.before,
name,
@@ -160,15 +158,14 @@ function updateDecorations(
)
const staleDecorations = new Set<Decoration>()
for (const block of oldBlocks) {
- const from = transaction.mapping.map(block.pos, -1)
- const to = transaction.mapping.map(block.pos + block.node.nodeSize, 1)
- for (const decoration of next.find(Math.min(from, to), Math.max(from, to))) {
+ for (const decoration of decorationSet.find(block.pos, block.pos + block.node.nodeSize)) {
staleDecorations.add(decoration)
}
}
- if (staleDecorations.size > 0) {
- next = next.remove([...staleDecorations])
- }
+ const unchanged =
+ staleDecorations.size > 0 ? decorationSet.remove([...staleDecorations]) : decorationSet
+ // Why: mapped decorations stay valid outside code blocks touched by the transaction.
+ const next = unchanged.map(transaction.mapping, transaction.doc)
const newBlocks = findCodeBlocksNearRanges(
transaction.doc,