From ff21296913117755bfcabd711ddcb71add6004ec Mon Sep 17 00:00:00 2001 From: TagWolf Date: Sun, 8 Oct 2023 23:25:54 -0700 Subject: [PATCH] - Added tracking to distinguish between auto-selection vs manual selection. - Added logic to not perform auto actions on manually selected text. --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/extension.ts | 14 +++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6756171..1750ea9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the "Auto Select Pasted Text" extension will be documented in this file. +## [0.2.0] - 2023-10-09 +- Added tracking to distinguish between auto-selection vs manual selection. +- Added logic to not perform auto actions on manually selected text. + ## [0.1.9] - 2023-10-08 - Updated changelog. diff --git a/package.json b/package.json index 5147199..dbd1c53 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Auto Select Pasted Text", "description": "Automatically selects text after it's pasted", "icon": "autoselectpastedtextlogo.png", - "version": "0.1.9", + "version": "0.2.0", "publisher": "davidcahill", "license": "MIT", "repository": { diff --git a/src/extension.ts b/src/extension.ts index 4c73059..f9a337c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,6 +3,9 @@ import * as vscode from 'vscode'; // Variable to store the last pasted content let lastPastedContent: string | null = null; +// Flag to track if the selection was auto-selected after pasting +let autoSelected: boolean = false; + export function activate(context: vscode.ExtensionContext) { // Create an output channel for logging extension-related activities const outputChannel = vscode.window.createOutputChannel("AutoSelectPaste"); @@ -13,11 +16,12 @@ export function activate(context: vscode.ExtensionContext) { // Register the type command to handle the deselection behavior vscode.commands.registerCommand('type', (args) => { const editor = vscode.window.activeTextEditor; - if (editor) { + if (editor && autoSelected) { // Check the autoSelected flag const currentSelection = editor.selection; if (!currentSelection.isEmpty) { const currentPosition = currentSelection.end; editor.selection = new vscode.Selection(currentPosition, currentPosition); + autoSelected = false; // Reset the flag } } vscode.commands.executeCommand('default:type', args); @@ -62,15 +66,15 @@ export function activate(context: vscode.ExtensionContext) { // Adjust the selection to cover the pasted content editor.selection = new vscode.Selection(targetSelection.start, endPosition); + // Set the autoSelected flag since we've auto-selected the pasted text + autoSelected = true; // Reveal the pasted content in the editor editor.revealRange(new vscode.Range(targetSelection.start, endPosition), vscode.TextEditorRevealType.Default); } else { - outputChannel.appendLine("Failed to paste content."); + outputChannel.appendLine('Clipboard is empty.'); } }); } - } else { - outputChannel.appendLine('Clipboard is empty.'); } }); @@ -87,4 +91,4 @@ export function activate(context: vscode.ExtensionContext) { } } }); -} +} \ No newline at end of file