Skip to content

Commit

Permalink
0.3.0 Added settings menus and options
Browse files Browse the repository at this point in the history
  • Loading branch information
dcahill committed Oct 10, 2023
1 parent 8ec501f commit 1a05e78
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 15 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

All notable changes to the "Auto Select Pasted Text" extension will be documented in this file.

## [0.3.0] - 2023-10-11
### Added
- Implemented `enableLogging` setting to conditionally log extension activities.
- Introduced a toggle command for the `enableLogging` setting.
- Created a utility function to handle conditional logging based on the `enableLogging` setting.

### Changed
- Refactored the paste command to utilize the `enableAutoSelection` setting.
- Adjusted the type command to handle both auto and manual selection behaviors.

### Fixed
- Addressed inconsistencies in the configuration and command naming.
- Resolved an issue with the logging setting not updating immediately.

## [0.2.1] - 2023-10-10
- Updated README.md

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Boost your VSCode experience with **Auto Select Pasted Text**. This extension is

- 💼 **Smart Pasting & Deselection**: If you paste and then type, the extension smartly deselects the pasted content and positions the cursor at the end. This ensures a seamless transition between pasting and continuing to type. Moreover, the extension recognizes repeated pasting actions and appends content without overwriting the previous pastes.

- 📖 **Logging & Debugging**: Behind the scenes, the extension logs significant events, such as activations, paste commands, and selection changes. This is invaluable for developers seeking insights or debugging the extension's behavior.
- 📖 **Logging & Debugging**: Behind the scenes, the extension logs significant events, such as activations, paste commands, and selection changes. This is invaluable for developers seeking insights or debugging the extension's behavior. Easily toggle logging on or off via the command palette or settings.

- 🎚 **Settings & Command Menu**: Customize your experience by using the settings or command menu to toggle various features, including auto selection of pasted text, logging for debugging, auto deselection on typing, and more.

- 📦 **Seamless Integration**: Experience the magic without any configuration. Just install, and you're good to go!

Expand All @@ -33,6 +35,8 @@ Whenever you paste content, it will be automatically highlighted. This auto-sele

After pasting, if you start typing, the auto-selected content will be deselected, and the cursor will position itself at the end, allowing for a seamless transition between pasting and typing.

For a personalized experience, delve into the extension's settings. Here, you can fine-tune features such as auto-deselection upon typing or enable debugging logs. But that's not all! If you need swift alterations, the command palette is at your service. Simply press `Ctrl+Shift+P` to open the command palette and search for commands starting with `AutoSelectPastedText:`. This will present a list of quick toggles and actions specific to the extension, allowing you to modify its behavior without diving into the settings menu.

This auto-selection feature aims to reduce the friction between pasting and editing, ensuring a smooth and efficient coding experience.

## 💻 Development
Expand Down
47 changes: 44 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "auto-select-pasted-text",
"displayName": "Auto Select Pasted Text",
"description": "Automatically selects text after it's pasted",
"description": "Automatically selects text after it's pasted for quick intents and edits.",
"icon": "autoselectpastedtextlogo.png",
"version": "0.2.1",
"version": "0.3.0",
"publisher": "davidcahill",
"license": "MIT",
"repository": {
Expand All @@ -26,8 +26,49 @@
{
"command": "editor.action.clipboardPasteAction",
"title": "Paste and Select"
},
{
"command": "autoSelectPastedText.toggleAutoSelection",
"title": "AutoSelectPastedText: Toggle Auto Selection of Pasted Text"
},
{
"command": "autoSelectPastedText.toggleLogging",
"title": "AutoSelectPastedText: Toggle Logging for Debugging"
},
{
"command": "autoSelectPastedText.toggleTypeDetection",
"title": "AutoSelectPastedText: Toggle Auto Deselection on Typing"
},
{
"command": "autoSelectPastedText.toggleManualSelection",
"title": "AutoSelectPastedText: Toggle Auto Selection for Manually Selected Text (Not Recommended)"
}
],
"configuration": {
"title": "Auto Select Pasted Text",
"properties": {
"autoSelectPastedText.enableAutoSelection": {
"type": "boolean",
"default": true,
"description": "Enable automatic selection of pasted text."
},
"autoSelectPastedText.enableLogging": {
"type": "boolean",
"default": true,
"description": "Enable logging for debugging purposes."
},
"autoSelectPastedText.enableTypeDetection": {
"type": "boolean",
"default": true,
"description": "Automatically deselect text when you start typing after pasting."
},
"autoSelectPastedText.enableManualSelection": {
"type": "boolean",
"default": false,
"description": "Enable the auto-selection behavior for manually selected text (not recommended)."
}
}
]
}
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
Expand Down
61 changes: 50 additions & 11 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,65 @@ 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");
const outputChannel = vscode.window.createOutputChannel("AutoSelectPastedText");

// Function to handle conditional logging based on the enableLogging setting
const log = (message: string) => {
const enableLogging = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableLogging');
if (enableLogging) {
outputChannel.appendLine(message);
}
};

context.subscriptions.push(vscode.commands.registerCommand('autoSelectPastedText.toggleAutoSelection', () => {
const currentSetting = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableAutoSelection');
vscode.workspace.getConfiguration('autoSelectPastedText').update('enableAutoSelection', !currentSetting, true);
}));

context.subscriptions.push(vscode.commands.registerCommand('autoSelectPastedText.toggleLogging', () => {
const currentSetting = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableLogging');
vscode.workspace.getConfiguration('autoSelectPastedText').update('enableLogging', !currentSetting, true);
}));

context.subscriptions.push(vscode.commands.registerCommand('autoSelectPastedText.toggleTypeDetection', () => {
const currentSetting = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableTypeDetection');
vscode.workspace.getConfiguration('autoSelectPastedText').update('enableTypeDetection', !currentSetting, true);
}));

context.subscriptions.push(vscode.commands.registerCommand('autoSelectPastedText.toggleManualSelection', () => {
const currentSetting = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableManualSelection');
vscode.workspace.getConfiguration('autoSelectPastedText').update('enableManualSelection', !currentSetting, true);
}));

// Indicate activation in the output channel
outputChannel.appendLine('Activating AutoSelectPaste extension...');
log('Activating autoSelectPastedText extension...');

// Register the type command to handle the deselection behavior
vscode.commands.registerCommand('type', (args) => {
const editor = vscode.window.activeTextEditor;
if (editor && autoSelected) { // Check the autoSelected flag
const enableTypeDetection = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableTypeDetection');
const enableManualSelection = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableManualSelection');

if (editor) {
const currentSelection = editor.selection;
if (!currentSelection.isEmpty) {

if (autoSelected && enableTypeDetection && !currentSelection.isEmpty) {
const currentPosition = currentSelection.end;
editor.selection = new vscode.Selection(currentPosition, currentPosition);
autoSelected = false; // Reset the flag
} else if (!autoSelected && enableManualSelection && !currentSelection.isEmpty) {
const currentPosition = currentSelection.end;
editor.selection = new vscode.Selection(currentPosition, currentPosition);
autoSelected = false; // Reset the flag
}
}
vscode.commands.executeCommand('default:type', args);
});

// Register the paste command
let pasteCommandDisposable = vscode.commands.registerCommand('editor.action.clipboardPasteAction', async () => {
outputChannel.appendLine('Paste command executed.');
const enableAutoSelection = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableAutoSelection');

log('Paste command executed.');

// Read content from clipboard
const clipboardContent = await vscode.env.clipboard.readText();
Expand Down Expand Up @@ -64,10 +101,12 @@ export function activate(context: vscode.ExtensionContext) {
const endCharacter = (linesPasted.length === 1) ? (targetSelection.start.character + lastLineLength) : lastLineLength;
const endPosition = new vscode.Position(endLine, endCharacter);

// 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;
if (enableAutoSelection) {
// 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 {
Expand All @@ -87,7 +126,7 @@ export function activate(context: vscode.ExtensionContext) {
const selections = event.selections;
if (selections && selections.length > 0) {
const selection = selections[0];
outputChannel.appendLine(`Selection changed: Start(${selection.start.line}, ${selection.start.character}), End(${selection.end.line}, ${selection.end.character})`);
log(`Selection changed: Start(${selection.start.line}, ${selection.start.character}), End(${selection.end.line}, ${selection.end.character})`);
}
}
});
Expand Down

0 comments on commit 1a05e78

Please sign in to comment.