Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

570 B
Raw Blame
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) }));
}