()
| 504 | } |
| 505 | |
| 506 | const syncParts = () => { |
| 507 | if (!area || area.isDestroyed || type === 0) { |
| 508 | return |
| 509 | } |
| 510 | |
| 511 | const next: Mention[] = [] |
| 512 | const map = new Map<number, number>() |
| 513 | for (const item of area.extmarks.getAllForTypeId(type)) { |
| 514 | const idx = marks.get(item.id) |
| 515 | if (idx === undefined) { |
| 516 | continue |
| 517 | } |
| 518 | |
| 519 | const part = parts[idx] |
| 520 | if (!part) { |
| 521 | continue |
| 522 | } |
| 523 | |
| 524 | const text = area.plainText.slice(item.start, item.end) |
| 525 | const prev = |
| 526 | part.type === "agent" |
| 527 | ? (part.source?.value ?? "@" + part.name) |
| 528 | : (part.source?.text.value ?? "@" + (part.filename ?? "")) |
| 529 | if (text !== prev) { |
| 530 | continue |
| 531 | } |
| 532 | |
| 533 | const copy = structuredClone(part) |
| 534 | if (copy.type === "agent") { |
| 535 | copy.source = { |
| 536 | start: item.start, |
| 537 | end: item.end, |
| 538 | value: text, |
| 539 | } |
| 540 | } |
| 541 | if (copy.type === "file" && copy.source?.text) { |
| 542 | copy.source.text.start = item.start |
| 543 | copy.source.text.end = item.end |
| 544 | copy.source.text.value = text |
| 545 | } |
| 546 | |
| 547 | map.set(item.id, next.length) |
| 548 | next.push(copy) |
| 549 | } |
| 550 | |
| 551 | const stale = map.size !== marks.size |
| 552 | parts = next |
| 553 | marks = map |
| 554 | if (stale) { |
| 555 | restoreParts(next) |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | const clearParts = () => { |
| 560 | if (area && !area.isDestroyed) { |
no test coverage detected