mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
fix findDiffs
This commit is contained in:
parent
c4e29d1c3f
commit
7a33cde334
1 changed files with 6 additions and 1 deletions
|
|
@ -29,6 +29,11 @@ export type SuggestedEdit = {
|
|||
}
|
||||
|
||||
export function findDiffs(oldStr: string, newStr: string) {
|
||||
|
||||
// this makes it so the end of the file always ends with a \n (if you don't have this, then diffing E vs E\n gives an "edit". With it, you end up diffing E\n vs E\n\n which now properly gives an insertion)
|
||||
newStr += '\n';
|
||||
oldStr += '\n';
|
||||
|
||||
// an ordered list of every original line, line added to the new file, and line removed from the old file (order is unambiguous, think about it)
|
||||
const lineByLineChanges = diffLines(oldStr, newStr);
|
||||
lineByLineChanges.push({ value: '', added: false, removed: false }) // add a dummy so we flush any streaks we haven't yet at the very end (!line.added && !line.removed)
|
||||
|
|
@ -172,7 +177,7 @@ export function findDiffs(oldStr: string, newStr: string) {
|
|||
// A
|
||||
// B
|
||||
// C
|
||||
|
||||
// D
|
||||
// E
|
||||
// `
|
||||
// const insertedCode = `\
|
||||
|
|
|
|||
Loading…
Reference in a new issue