From f256936baea59b5bd5656773b066629d038bea66 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Sat, 13 Jul 2024 23:19:39 +0800 Subject: [PATCH] slightly optimize two way merge --- pro/src/conflictLogic.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pro/src/conflictLogic.ts b/pro/src/conflictLogic.ts index fc85ce2..dfff399 100644 --- a/pro/src/conflictLogic.ts +++ b/pro/src/conflictLogic.ts @@ -73,6 +73,18 @@ function getLCSText(a: string, b: string) { * @returns */ function twoWayMerge(a: string, b: string): string { + const aa = a.trim(); + const bb = b.trim(); + if (aa === "" && bb === "") { + return aa.length >= bb.length ? a : b; + } + if (bb === "") { + return a; + } + if (aa === "") { + return b; + } + // const c = getLCSText(a, b); // const patches = makePatches(c, a); // const [d] = applyPatches(patches, b);