Skip to content

Commit c1f5a77

Browse files
authored
fix(review): hide-whitespace now ignores interior whitespace to match GitHub (#635)
The diff library's ignoreWhitespace only trims leading/trailing whitespace, so interior changes (alignment padding, extra spaces between tokens) still showed as diffs. Normalize all whitespace before diffing to match git diff -w. Also adds a real code change to the settings.ts demo so the file isn't fully collapsed when hide-whitespace is on.
1 parent a11bf80 commit c1f5a77

3 files changed

Lines changed: 5 additions & 7 deletions

File tree

bun.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/review-editor/components/DiffViewer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,10 @@ export const DiffViewer: React.FC<DiffViewerProps> = ({
300300
if (!fileContents || fileContents.forPath !== filePath || (fileContents.old == null && fileContents.new == null)) return fileDiff;
301301
try {
302302
if (hideWhitespace && fileContents.old != null && fileContents.new != null) {
303+
const normalize = (s: string) => s.split('\n').map(l => l.replace(/\s+/g, ' ').trim()).join('\n');
303304
return parseDiffFromFile(
304-
{ name: oldPath || filePath, contents: fileContents.old },
305-
{ name: filePath, contents: fileContents.new },
306-
{ ignoreWhitespace: true },
305+
{ name: oldPath || filePath, contents: normalize(fileContents.old) },
306+
{ name: filePath, contents: normalize(fileContents.new) },
307307
);
308308
}
309309
const result = processFile(patch, {

packages/review-editor/demoData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function getDatabaseConfig() {
7373
connectionString: config.DATABASE_URL,
7474
pool: {
7575
min: 2,
76-
max: config.NODE_ENV === 'production' ? 20 : 5,
76+
max: config.NODE_ENV === 'production' ? 20 : 10,
7777
},
7878
ssl: config.NODE_ENV === 'production',
7979
};
@@ -335,7 +335,7 @@ index 5678901..efghijk 100644
335335
+ connectionString: config.DATABASE_URL,
336336
+ pool: {
337337
+ min: 2,
338-
+ max: config.NODE_ENV === 'production' ? 20 : 5,
338+
+ max: config.NODE_ENV === 'production' ? 20 : 10,
339339
+ },
340340
+ ssl: config.NODE_ENV === 'production',
341341
+ };

0 commit comments

Comments
 (0)