I am writing a VSCode Extension that tracks code progress in a .csv file. For now everytime I change from one line to another it gets tracked as a change into the .csv file, even if the content in the line did not change. The .csv file should only track changes and should ignore if a line is still the same.
My current code snippet looks like this:
function trackLineChanges(event: vscode.TextEditorSelectionChangeEvent) {
const line = event.selections[0].active.line;
if (previousLine !== undefined && previousLine !== line) {
const timestamp = Date.now();
const content = editor!.document.lineAt(previousLine).text;
const isEmptyLine = content.trim() === "";
trackedChanges.push({
timestamp,
content,
line: previousLine + 1,
isEmptyLine,
});
console.log(`Line ${previousLine + 1} changed:`, content, timestamp);
saveChangesToCSV();
}
previousLine = line;
}
My idea was to check the content of the line, when the line gets clicked. The content at the click is then saved into a variable. Then there is a second check of the content when the user leaves the line and switches to another line.
I tried to sum my idea up in some general pseudocode:
function trackLineChanges(event: vscode.TextEditorSelectionChangeEvent) {
const line = event.selections[0].active.line;
let contentClicked = "";
let contentLeft = "";
if (cursor focus on line){
contentClicked = text in line when the line got clicked
}
if (cursor focus is not on line anymore){
contentLeft = text in line when the line is not in focus anymore
}
if (contentClicked !== contentLeft){
write to .csv
}