Skip to content

Commit

Permalink
comparing pasted content ignoring whitespace (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu authored Oct 14, 2024
1 parent e5eb1ed commit 918a749
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>

const clipboardText = await vscode.env.clipboard.readText();

if (contentChange.text !== clipboardText) {
if (!areEqualIgnoringWhitespace(contentChange.text, clipboardText)) {
return;
}

Expand Down Expand Up @@ -150,3 +150,11 @@ function enabled(): boolean {
function isEmptyOrWhitespace(s: string): boolean {
return /^\s*$/.test(s);
}

function areEqualIgnoringWhitespace(a: string, b: string): boolean {
return removeWhitespace(a) === removeWhitespace(b);
}

function removeWhitespace(s: string): string {
return s.replace(/\s*/g, '');
}

0 comments on commit 918a749

Please sign in to comment.