Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying removal and adding of lines #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DanDaManTran
Copy link
Contributor

Screenshot 2024-06-25 at 1 40 06 PM
Screenshot 2024-06-25 at 2 09 03 PM
Screenshot 2024-06-25 at 3 24 14 PM
Screenshot 2024-06-25 at 3 25 07 PM

Here are the end results of the diff updates. If there is concern about red highlights for removed lines, there is a ticket to handle highlight update.

var validCurData = (curData && curData.length !== 2);
var fileType = convertType(path.extname(files[1]).substring(1));
var useCurData = useCurData ? validCurData && (typeof curData.description === "string") && !curData.body : false;;
var markdown = '\n```' + fileType + '\n' + file2 + '\n```';
var diffLines = diffChecker.diff(file1, file2);
var markdown = '\n```' + fileType + '\n' + diffFile.join('\n') + '\n```';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To display if there removed any lines, we had to create a new "file" to display added and removed lines

const Diff = require('diff');

function normalizeLines(str) {
const strWithNewLine = str.endsWith('\n') ? str : str + '\n';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding lines to the end of a file, the 'diff' package reads it as removing and adding the last line even though there isn't any changes. This line is to ensure a \n at the end so the package can read it as unchanged line.

function normalizeLines(str) {
const strWithNewLine = str.endsWith('\n') ? str : str + '\n';

return strWithNewLine.split('\n').map(line => line.replace(/\s+$/, '')).join('\n');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to clear out trailing white spaces. The package has a property to ignore white spaces, but when trying to rebuild the diff file, it removed all the indentation.

console.log("Hello World");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added white spaces to ensure the diffChecker, ignores white spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant