Skip to content

Commit 1a05e78

Browse files
committed
0.3.0 Added settings menus and options
1 parent 8ec501f commit 1a05e78

File tree

4 files changed

+113
-15
lines changed

4 files changed

+113
-15
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

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

5+
## [0.3.0] - 2023-10-11
6+
### Added
7+
- Implemented `enableLogging` setting to conditionally log extension activities.
8+
- Introduced a toggle command for the `enableLogging` setting.
9+
- Created a utility function to handle conditional logging based on the `enableLogging` setting.
10+
11+
### Changed
12+
- Refactored the paste command to utilize the `enableAutoSelection` setting.
13+
- Adjusted the type command to handle both auto and manual selection behaviors.
14+
15+
### Fixed
16+
- Addressed inconsistencies in the configuration and command naming.
17+
- Resolved an issue with the logging setting not updating immediately.
18+
519
## [0.2.1] - 2023-10-10
620
- Updated README.md
721

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Boost your VSCode experience with **Auto Select Pasted Text**. This extension is
88

99
- 💼 **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.
1010

11-
- 📖 **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.
11+
- 📖 **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.
12+
13+
- 🎚 **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.
1214

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

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

3436
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.
3537

38+
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.
39+
3640
This auto-selection feature aims to reduce the friction between pasting and editing, ensuring a smooth and efficient coding experience.
3741

3842
## 💻 Development

package.json

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "auto-select-pasted-text",
33
"displayName": "Auto Select Pasted Text",
4-
"description": "Automatically selects text after it's pasted",
4+
"description": "Automatically selects text after it's pasted for quick intents and edits.",
55
"icon": "autoselectpastedtextlogo.png",
6-
"version": "0.2.1",
6+
"version": "0.3.0",
77
"publisher": "davidcahill",
88
"license": "MIT",
99
"repository": {
@@ -26,8 +26,49 @@
2626
{
2727
"command": "editor.action.clipboardPasteAction",
2828
"title": "Paste and Select"
29+
},
30+
{
31+
"command": "autoSelectPastedText.toggleAutoSelection",
32+
"title": "AutoSelectPastedText: Toggle Auto Selection of Pasted Text"
33+
},
34+
{
35+
"command": "autoSelectPastedText.toggleLogging",
36+
"title": "AutoSelectPastedText: Toggle Logging for Debugging"
37+
},
38+
{
39+
"command": "autoSelectPastedText.toggleTypeDetection",
40+
"title": "AutoSelectPastedText: Toggle Auto Deselection on Typing"
41+
},
42+
{
43+
"command": "autoSelectPastedText.toggleManualSelection",
44+
"title": "AutoSelectPastedText: Toggle Auto Selection for Manually Selected Text (Not Recommended)"
45+
}
46+
],
47+
"configuration": {
48+
"title": "Auto Select Pasted Text",
49+
"properties": {
50+
"autoSelectPastedText.enableAutoSelection": {
51+
"type": "boolean",
52+
"default": true,
53+
"description": "Enable automatic selection of pasted text."
54+
},
55+
"autoSelectPastedText.enableLogging": {
56+
"type": "boolean",
57+
"default": true,
58+
"description": "Enable logging for debugging purposes."
59+
},
60+
"autoSelectPastedText.enableTypeDetection": {
61+
"type": "boolean",
62+
"default": true,
63+
"description": "Automatically deselect text when you start typing after pasting."
64+
},
65+
"autoSelectPastedText.enableManualSelection": {
66+
"type": "boolean",
67+
"default": false,
68+
"description": "Enable the auto-selection behavior for manually selected text (not recommended)."
69+
}
2970
}
30-
]
71+
}
3172
},
3273
"scripts": {
3374
"vscode:prepublish": "tsc -p ./",

src/extension.ts

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,65 @@ let autoSelected: boolean = false;
88

99
export function activate(context: vscode.ExtensionContext) {
1010
// Create an output channel for logging extension-related activities
11-
const outputChannel = vscode.window.createOutputChannel("AutoSelectPaste");
11+
const outputChannel = vscode.window.createOutputChannel("AutoSelectPastedText");
12+
13+
// Function to handle conditional logging based on the enableLogging setting
14+
const log = (message: string) => {
15+
const enableLogging = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableLogging');
16+
if (enableLogging) {
17+
outputChannel.appendLine(message);
18+
}
19+
};
20+
21+
context.subscriptions.push(vscode.commands.registerCommand('autoSelectPastedText.toggleAutoSelection', () => {
22+
const currentSetting = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableAutoSelection');
23+
vscode.workspace.getConfiguration('autoSelectPastedText').update('enableAutoSelection', !currentSetting, true);
24+
}));
25+
26+
context.subscriptions.push(vscode.commands.registerCommand('autoSelectPastedText.toggleLogging', () => {
27+
const currentSetting = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableLogging');
28+
vscode.workspace.getConfiguration('autoSelectPastedText').update('enableLogging', !currentSetting, true);
29+
}));
30+
31+
context.subscriptions.push(vscode.commands.registerCommand('autoSelectPastedText.toggleTypeDetection', () => {
32+
const currentSetting = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableTypeDetection');
33+
vscode.workspace.getConfiguration('autoSelectPastedText').update('enableTypeDetection', !currentSetting, true);
34+
}));
35+
36+
context.subscriptions.push(vscode.commands.registerCommand('autoSelectPastedText.toggleManualSelection', () => {
37+
const currentSetting = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableManualSelection');
38+
vscode.workspace.getConfiguration('autoSelectPastedText').update('enableManualSelection', !currentSetting, true);
39+
}));
1240

1341
// Indicate activation in the output channel
14-
outputChannel.appendLine('Activating AutoSelectPaste extension...');
42+
log('Activating autoSelectPastedText extension...');
1543

1644
// Register the type command to handle the deselection behavior
1745
vscode.commands.registerCommand('type', (args) => {
1846
const editor = vscode.window.activeTextEditor;
19-
if (editor && autoSelected) { // Check the autoSelected flag
47+
const enableTypeDetection = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableTypeDetection');
48+
const enableManualSelection = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableManualSelection');
49+
50+
if (editor) {
2051
const currentSelection = editor.selection;
21-
if (!currentSelection.isEmpty) {
52+
53+
if (autoSelected && enableTypeDetection && !currentSelection.isEmpty) {
54+
const currentPosition = currentSelection.end;
55+
editor.selection = new vscode.Selection(currentPosition, currentPosition);
56+
autoSelected = false; // Reset the flag
57+
} else if (!autoSelected && enableManualSelection && !currentSelection.isEmpty) {
2258
const currentPosition = currentSelection.end;
2359
editor.selection = new vscode.Selection(currentPosition, currentPosition);
24-
autoSelected = false; // Reset the flag
2560
}
2661
}
2762
vscode.commands.executeCommand('default:type', args);
2863
});
2964

3065
// Register the paste command
3166
let pasteCommandDisposable = vscode.commands.registerCommand('editor.action.clipboardPasteAction', async () => {
32-
outputChannel.appendLine('Paste command executed.');
67+
const enableAutoSelection = vscode.workspace.getConfiguration('autoSelectPastedText').get('enableAutoSelection');
68+
69+
log('Paste command executed.');
3370

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

67-
// Adjust the selection to cover the pasted content
68-
editor.selection = new vscode.Selection(targetSelection.start, endPosition);
69-
// Set the autoSelected flag since we've auto-selected the pasted text
70-
autoSelected = true;
104+
if (enableAutoSelection) {
105+
// Adjust the selection to cover the pasted content
106+
editor.selection = new vscode.Selection(targetSelection.start, endPosition);
107+
// Set the autoSelected flag since we've auto-selected the pasted text
108+
autoSelected = true;
109+
}
71110
// Reveal the pasted content in the editor
72111
editor.revealRange(new vscode.Range(targetSelection.start, endPosition), vscode.TextEditorRevealType.Default);
73112
} else {
@@ -87,7 +126,7 @@ export function activate(context: vscode.ExtensionContext) {
87126
const selections = event.selections;
88127
if (selections && selections.length > 0) {
89128
const selection = selections[0];
90-
outputChannel.appendLine(`Selection changed: Start(${selection.start.line}, ${selection.start.character}), End(${selection.end.line}, ${selection.end.character})`);
129+
log(`Selection changed: Start(${selection.start.line}, ${selection.start.character}), End(${selection.end.line}, ${selection.end.character})`);
91130
}
92131
}
93132
});

0 commit comments

Comments
 (0)