⚡️ new line matching heuristic
This commit is contained in:
parent
3ac715b759
commit
107e511b82
3 changed files with 9 additions and 10 deletions
|
|
@ -12,10 +12,10 @@ export async function* streamDiff(
|
|||
|
||||
let newLineResult = await newLines.next();
|
||||
while (oldLines.length > 0 && !newLineResult.done) {
|
||||
let newLine = newLineResult.value;
|
||||
const [matchIndex, isPerfectMatch, newLineWithCorrectIndentation] =
|
||||
matchLine(newLine, oldLines);
|
||||
newLine = newLineWithCorrectIndentation;
|
||||
const [matchIndex, isPerfectMatch, newLine] = matchLine(
|
||||
newLineResult.value,
|
||||
oldLines
|
||||
);
|
||||
|
||||
if (matchIndex < 0) {
|
||||
yield { type: "new", line: newLine };
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ export function matchLine(
|
|||
newLine: string,
|
||||
oldLines: string[]
|
||||
): [number, boolean, string] {
|
||||
// Only match empty lines if it's the next one:
|
||||
if (newLine.trim() === "" && oldLines[0]?.trim() === "") {
|
||||
return [0, true, newLine.trim()];
|
||||
}
|
||||
|
||||
for (let i = 0; i < oldLines.length; i++) {
|
||||
if (linesMatchPerfectly(newLine, oldLines[i])) {
|
||||
return [i, true, newLine];
|
||||
|
|
|
|||
|
|
@ -161,12 +161,6 @@ export class VerticalPerLineDiffHandler {
|
|||
private updateIndexLineDecorations() {
|
||||
// Highlight the line at the currentLineIndex
|
||||
// And lightly highlight all lines between that and endLine
|
||||
console.log(
|
||||
this.currentLineIndex,
|
||||
this.newLinesAdded,
|
||||
this.endLine,
|
||||
this.startLine
|
||||
);
|
||||
if (this.currentLineIndex - this.newLinesAdded >= this.endLine) {
|
||||
this.editor.setDecorations(indexDecorationType, []);
|
||||
this.editor.setDecorations(belowIndexDecorationType, []);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue