mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-15 17:25:26 -04:00
8746c9c0df
The document editor stores the AI-edit diff state (_diffModeActive, _diffOldContent, _diffNewContent, _diffChunks) as a module-global singleton bound to whatever document was active when the diff opened, and every document shares one #doc-editor-textarea. When the active document is switched while an unapproved diff is open, the stale diff must be discarded first or a later exitDiffMode (tab switch / Accept-Reject-All) flushes the old document's content into the new active document and overwrites it (issue #2467). Guard both paths that switch the active document for an AI update, while activeDocId still points at the previously-active doc: - handleDocUpdate(): a doc_update targeting a different document. - streamDocOpen(): the AI streaming a NEW document — this runs first on that path, so a guard only in handleDocUpdate would fire too late and still overwrite the streamed document. Both reuse the exact `if (_diffModeActive) exitDiffMode(true);` guard switchToDoc() and enterDiffMode() already use. Fixes #2467