From 9c42ff4c3fbb13a31ec55a230bd630d9d38071f6 Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Mon, 14 Oct 2024 14:42:56 +0800 Subject: [PATCH] comparing pasted content ignoring whitespace --- src/extension.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 264b203..36efdec 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -70,7 +70,7 @@ export async function activate(context: vscode.ExtensionContext): Promise const clipboardText = await vscode.env.clipboard.readText(); - if (contentChange.text !== clipboardText) { + if (!areEqualIgnoringWhitespace(contentChange.text, clipboardText)) { return; } @@ -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, ''); +}