дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 10:07:11 +02:00
Document::diff only trimmed the common prefix and suffix, so two distant edits on disk became one change spanning everything between them. The caret and scroll position inside that span were mapped to its start, which made the editor jump to the first edit after an agent, formatter or git operation rewrote the file. Diff the changed middle line by line (Myers via similar, 50 ms deadline with a coarser fallback) and emit one change per edited region, trimmed to its differing characters. The frontend DocSync path produces the same per-region changes, so external reloads, local history restores and formatting keep the caret and view in place. Closes #1326 Co-authored-by: ntbang0901 <[email protected]>
12 рядки
570 B
TypeScript
12 рядки
570 B
TypeScript
import { diff } from "@codemirror/merge";
|
|
import type { TextChange } from "@/platform/ipc";
|
|
|
|
/**
|
|
* The changes turning `a` into `b`, one per changed region; empty when equal. Used for resyncs:
|
|
* a single change spanning two distant edits would drag the caret and view to the first one.
|
|
* The timeout keeps a huge file from stalling the UI; past it the regions only get coarser.
|
|
*/
|
|
export function minimalChanges(a: string, b: string): TextChange[] {
|
|
return diff(a, b, { timeout: 50 }).map((c) => ({ from: c.fromA, to: c.toA, insert: b.slice(c.fromB, c.toB) }));
|
|
}
|