Skip to content

Commit

Permalink
- Added tracking to distinguish between auto-selection vs manual sele…
Browse files Browse the repository at this point in the history
…ction.

- Added logic to not perform auto actions on manually selected text.
  • Loading branch information
dcahill committed Oct 9, 2023
1 parent a1d8014 commit ff21296
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
14 changes: 9 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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.');
}
});

Expand All @@ -87,4 +91,4 @@ export function activate(context: vscode.ExtensionContext) {
}
}
});
}
}

0 comments on commit ff21296

Please sign in to comment.