Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ Select a block of text or a string of text. Press <kbd>Alt</kbd> + <kbd>W</kbd>

This extension works best in files that either use tabs or spaces for indentation. It may not work as well with mixed tabs/spaces.

## Settings

add htmltagwrap.tag to your settings.json file( <kbd>File</kbd>--><kbd>Preferences</kbd>--><kbd>Settings</kbd> )

setting.json
```
{
"htmltagwrap.tag": "p"
}
```

## Report Issues
I welcome pull requests. Please report an issue on GitHub if you have trouble.

Expand Down
24 changes: 15 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ export function activate() {
var editor = vscode.window.activeTextEditor;
if (editor != undefined) {

let tag = vscode.workspace.getConfiguration().get<string>("htmltagwrap.tag");
if (!tag) {
tag = 'p';
}

var selection = editor.selection;
var selectedText = editor.document.getText(selection);

var firstIndex = 1;
var lastIndex = selectedText.length;


console.log('selection is: ' + selectedText);
console.log('length is: ' + lastIndex);
Expand All @@ -56,7 +62,7 @@ export function activate() {

editor.edit((editBuilder) => {
// Modify last line of selection
editBuilder.insert(new vscode.Position(selectionEnd.line, selectionEnd.character), '\n' + selectionStart_spaces + '</p>');
editBuilder.insert(new vscode.Position(selectionEnd.line, selectionEnd.character), '\n' + selectionStart_spaces + '</' + tag + '>');
editBuilder.insert(new vscode.Position(selectionEnd.line, 0), tabSizeSpace);
console.log('End line done. Line #: ' + selectionEnd.line);

Expand All @@ -65,15 +71,15 @@ export function activate() {
editBuilder.insert(new vscode.Position(lineNumber, 0), tabSizeSpace);
}

// Modify firs line of selection
editBuilder.insert(new vscode.Position(selectionStart.line, selectionStart.character), '<p>\n' + selectionStart_spaces + tabSizeSpace);
// Modify first line of selection
editBuilder.insert(new vscode.Position(selectionStart.line, selectionStart.character), '<' + tag + '>\n' + selectionStart_spaces + tabSizeSpace);
console.log('Start Line done. Line #: ' + selectionStart.line);
}).then(() => {
console.log('Edit applied!');

var bottomTagLine = lineBelow + 1;
var firstTagSelectionSelection: vscode.Selection = new vscode.Selection(selectionStart.line, selectionStart.character + 1, selectionStart.line, selectionStart.character + 2);
var lastTagSelectionSelection: vscode.Selection = new vscode.Selection(bottomTagLine, selectionStart.character + 2, bottomTagLine, selectionStart.character + 3);
var firstTagSelectionSelection: vscode.Selection = new vscode.Selection(selectionStart.line, selectionStart.character + 1, selectionStart.line, selectionStart.character + 1 + tag.length);
var lastTagSelectionSelection: vscode.Selection = new vscode.Selection(bottomTagLine, selectionStart.character + 2, bottomTagLine, selectionStart.character + 2 + tag.length);
var tagSelections: vscode.Selection[] = [firstTagSelectionSelection, lastTagSelectionSelection];

editor.selections = tagSelections;
Expand All @@ -85,13 +91,13 @@ export function activate() {
else {
//Wrap it inline
editor.edit((editBuilder) => {
editBuilder.insert(new vscode.Position(selectionEnd.line, selectionEnd.character), '</p>');
editBuilder.insert(new vscode.Position(selectionEnd.line, selectionStart.character), '<p>');
editBuilder.insert(new vscode.Position(selectionEnd.line, selectionEnd.character), '</' + tag + '>');
editBuilder.insert(new vscode.Position(selectionEnd.line, selectionStart.character), '<' + tag + '>');
}).then(() => {
console.log('Edit applied!');

var firstTagSelectionSelection: vscode.Selection = new vscode.Selection(selectionStart.line, selectionStart.character + 1, selectionStart.line, selectionStart.character + 2);
var lastTagSelectionSelection: vscode.Selection = new vscode.Selection(selectionEnd.line, selectionEnd.character + 3 + 2, selectionEnd.line, selectionEnd.character + 3 + 3);
var firstTagSelectionSelection: vscode.Selection = new vscode.Selection(selectionStart.line, selectionStart.character + 1, selectionStart.line, selectionStart.character + 1 + tag.length);
var lastTagSelectionSelection: vscode.Selection = new vscode.Selection(selectionEnd.line, selectionEnd.character + 3 + 1 + tag.length, selectionEnd.line, selectionEnd.character + 2 + 2 + 2*tag.length);
var tagSelections: vscode.Selection[] = [firstTagSelectionSelection, lastTagSelectionSelection];

editor.selections = tagSelections;
Expand Down
2 changes: 2 additions & 0 deletions test/debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[0727/213252.494:ERROR:tcp_listen_socket.cc(76)] Could not bind socket to 127.0.0.1:6004
[0727/213252.498:ERROR:node_debugger.cc(87)] Cannot start debugger server