🐛 revert changes to fix streaming bug
This commit is contained in:
parent
a0eae24ec1
commit
638e6a79a4
2 changed files with 10 additions and 22 deletions
|
|
@ -17,11 +17,10 @@ export async function* streamDiff(
|
|||
let seenIndentationMistake = false;
|
||||
|
||||
let newLineResult = await newLines.next();
|
||||
const postponedLines: string[] = [];
|
||||
while (oldLines.length > 0 && !newLineResult.done) {
|
||||
const [matchIndex, isPerfectMatch, newLine] = matchLine(
|
||||
newLineResult.value,
|
||||
mutatedOldLines,
|
||||
oldLines,
|
||||
seenIndentationMistake
|
||||
);
|
||||
if (!seenIndentationMistake && newLineResult.value !== newLine) {
|
||||
|
|
@ -30,25 +29,20 @@ export async function* streamDiff(
|
|||
|
||||
if (matchIndex < 0) {
|
||||
// Insert new line
|
||||
postponedLines.push(newLine);
|
||||
yield { type: "new", line: newLine };
|
||||
} else {
|
||||
// Insert all deleted lines before match
|
||||
for (let i = 0; i < matchIndex; i++) {
|
||||
yield { type: "old", line: mutatedOldLines.shift()! };
|
||||
}
|
||||
if (postponedLines.length > 0) {
|
||||
for (let i = 0; i <= postponedLines.length; i++) {
|
||||
yield { type: "new", line: postponedLines.shift()! };
|
||||
}
|
||||
yield { type: "old", line: oldLines.shift()! };
|
||||
}
|
||||
|
||||
if (isPerfectMatch) {
|
||||
// Same
|
||||
yield { type: "same", line: mutatedOldLines.shift()! };
|
||||
yield { type: "same", line: oldLines.shift()! };
|
||||
} else {
|
||||
// Delete old line and insert the new
|
||||
yield { type: "old", line: mutatedOldLines.shift()! };
|
||||
postponedLines.push(newLine);
|
||||
yield { type: "old", line: oldLines.shift()! };
|
||||
yield { type: "new", line: newLine };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,22 +50,16 @@ export async function* streamDiff(
|
|||
}
|
||||
|
||||
// Once at the edge, only one choice
|
||||
if (newLineResult.done === true && mutatedOldLines.length > 0) {
|
||||
if (newLineResult.done === true && oldLines.length > 0) {
|
||||
for (let oldLine of oldLines) {
|
||||
yield { type: "old", line: oldLine };
|
||||
}
|
||||
}
|
||||
|
||||
if (!newLineResult.done && mutatedOldLines.length === 0) {
|
||||
if (!newLineResult.done && oldLines.length === 0) {
|
||||
yield { type: "new", line: newLineResult.value };
|
||||
for await (const newLine of newLines) {
|
||||
yield { type: "new", line: newLine };
|
||||
}
|
||||
}
|
||||
|
||||
if (postponedLines.length > 0) {
|
||||
for await (const newLine of postponedLines) {
|
||||
yield { type: "new", line: newLine };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ export function matchLine(
|
|||
} else if (linesMatch(newLine, oldLines[i])) {
|
||||
// This is a way to fix indentation, but only for sufficiently long lines to avoid matching whitespace or short lines
|
||||
if (
|
||||
newLine.trimStart() === oldLines[i].trimStart() // &&
|
||||
// (permissiveAboutIndentation) || newLine.trim().length > 8)
|
||||
newLine.trimStart() === oldLines[i].trimStart() &&
|
||||
(permissiveAboutIndentation || newLine.trim().length > 8)
|
||||
) {
|
||||
return [i, true, oldLines[i]];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue