From 41543278e43d34ee0bc7fc3bd6d2452851d023b5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 10 Aug 2025 19:15:31 +0000 Subject: [PATCH 1/3] Initial plan From 6057c32659ec1c8e0696f3989f3a11bddd84b3ce Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 10 Aug 2025 19:20:04 +0000 Subject: [PATCH 2/3] Add compare selection with clipboard functionality Co-authored-by: moshfeu <3723951+moshfeu@users.noreply.github.com> --- package.json | 20 ++++++++++++++++++++ src/commands.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/package.json b/package.json index 4cabb50..815a4aa 100644 --- a/package.json +++ b/package.json @@ -135,6 +135,18 @@ { "command": "diffMerge.compareFileWithClipboard", "group": "z@102" + }, + { + "command": "diffMerge.compareSelectionWithClipboard", + "when": "editorHasSelection", + "group": "z@103" + } + ], + "editor/context": [ + { + "command": "diffMerge.compareSelectionWithClipboard", + "when": "editorHasSelection", + "group": "3_compare@100" } ], "commandPalette": [ @@ -142,6 +154,10 @@ "command": "diffMerge.chooseFile", "when": "editorIsOpen" }, + { + "command": "diffMerge.compareSelectionWithClipboard", + "when": "editorHasSelection" + }, { "command": "diffMerge.scm.file", "when": "false" @@ -217,6 +233,10 @@ "title": "[Diff & Merge] Compare file with Clipboard", "command": "diffMerge.compareFileWithClipboard" }, + { + "title": "[Diff & Merge] Compare selection with Clipboard", + "command": "diffMerge.compareSelectionWithClipboard" + }, { "title": "[Diff & Merge] Select file to compare", "command": "diffMerge.selectToCompare" diff --git a/src/commands.ts b/src/commands.ts index f4dc395..be72503 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -24,6 +24,10 @@ export function init(context: ExtensionContext) { 'diffMerge.compareFileWithClipboard', compareFileWithClipboard ), + commands.registerCommand( + 'diffMerge.compareSelectionWithClipboard', + compareSelectionWithClipboard + ), commands.registerCommand('diffMerge.openWithDiffMerge', reopenCurrentWithDiffMerge), commands.registerCommand('diffMerge.applyAllChanges', applyAllChanges) ); @@ -73,6 +77,37 @@ export function init(context: ExtensionContext) { }); } + async function compareSelectionWithClipboard() { + const editor = window.activeTextEditor; + if (!editor) { + window.showInformationMessage( + 'This command has to be run only when a text based file is open' + ); + log('This command has to be run only when a file is open'); + return; + } + + const selection = editor.selection; + if (selection.isEmpty) { + window.showInformationMessage( + 'Please select some text to compare with clipboard' + ); + log('No text selected for comparison'); + return; + } + + const selectedText = editor.document.getText(selection); + const clipboardText = await env.clipboard.readText(); + + showDiff({ + context, + leftContent: clipboardText, + leftPath: 'Clipboard', + rightPath: `Selection from ${editor.document.uri.fsPath}`, + rightContent: selectedText, + }); + } + function blank() { showDiff({ leftContent: '', rightContent: '', rightPath: '', context }); } From 0c01bf50028161e5c115f4ba09276582cdcb85a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 10 Aug 2025 19:24:20 +0000 Subject: [PATCH 3/3] Add compare clipboard with previous clipboard functionality Co-authored-by: moshfeu <3723951+moshfeu@users.noreply.github.com> --- package.json | 11 +++++++++++ src/commands.ts | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/package.json b/package.json index 815a4aa..c9a2a9a 100644 --- a/package.json +++ b/package.json @@ -140,6 +140,10 @@ "command": "diffMerge.compareSelectionWithClipboard", "when": "editorHasSelection", "group": "z@103" + }, + { + "command": "diffMerge.compareClipboardWithPrevious", + "group": "z@104" } ], "editor/context": [ @@ -158,6 +162,9 @@ "command": "diffMerge.compareSelectionWithClipboard", "when": "editorHasSelection" }, + { + "command": "diffMerge.compareClipboardWithPrevious" + }, { "command": "diffMerge.scm.file", "when": "false" @@ -237,6 +244,10 @@ "title": "[Diff & Merge] Compare selection with Clipboard", "command": "diffMerge.compareSelectionWithClipboard" }, + { + "title": "[Diff & Merge] Compare clipboard with previous clipboard", + "command": "diffMerge.compareClipboardWithPrevious" + }, { "title": "[Diff & Merge] Select file to compare", "command": "diffMerge.selectToCompare" diff --git a/src/commands.ts b/src/commands.ts index be72503..dd6ed8b 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -28,6 +28,10 @@ export function init(context: ExtensionContext) { 'diffMerge.compareSelectionWithClipboard', compareSelectionWithClipboard ), + commands.registerCommand( + 'diffMerge.compareClipboardWithPrevious', + compareClipboardWithPrevious + ), commands.registerCommand('diffMerge.openWithDiffMerge', reopenCurrentWithDiffMerge), commands.registerCommand('diffMerge.applyAllChanges', applyAllChanges) ); @@ -108,6 +112,39 @@ export function init(context: ExtensionContext) { }); } + async function compareClipboardWithPrevious() { + const currentClipboard = await env.clipboard.readText(); + + if (!previousClipboardContent) { + // Store current clipboard as previous for next time + previousClipboardContent = currentClipboard; + window.showInformationMessage( + 'Previous clipboard content saved. Run this command again to compare with current clipboard.' + ); + log('Previous clipboard content saved'); + return; + } + + if (currentClipboard === previousClipboardContent) { + window.showInformationMessage( + 'Current clipboard content is the same as previous clipboard content.' + ); + log('Clipboard content unchanged'); + return; + } + + showDiff({ + context, + leftContent: previousClipboardContent, + leftPath: 'Previous Clipboard', + rightPath: 'Current Clipboard', + rightContent: currentClipboard, + }); + + // Update previous clipboard to current for next comparison + previousClipboardContent = currentClipboard; + } + function blank() { showDiff({ leftContent: '', rightContent: '', rightPath: '', context }); } @@ -165,6 +202,7 @@ export function init(context: ExtensionContext) { } let selectedFilePath: string; + let previousClipboardContent: string | undefined; function selectToCompare(e: Uri) { try { selectedFilePath = tryToGetPath(e);