From 50cd4303dcf893162b865df8bcac8d69824a226b Mon Sep 17 00:00:00 2001 From: Zach Spofford Date: Fri, 28 Jul 2017 18:50:42 -0500 Subject: [PATCH 1/3] added a setting so users can pick the default tag --- README.md | 11 +++++++++++ src/extension.ts | 16 +++++++++++----- test/debug.log | 2 ++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 test/debug.log diff --git a/README.md b/README.md index b8f15cd..c6cae3b 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,17 @@ Select a block of text or a string of text. Press Alt + W 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( File-->Preferences-->Settings ) + +setting.json + ``` + { + "htmltagwrap.tag" = "p" + } + ``` + ## Report Issues I welcome pull requests. Please report an issue on GitHub if you have trouble. diff --git a/src/extension.ts b/src/extension.ts index d9a413c..0c92ddf 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -29,12 +29,18 @@ export function activate() { var editor = vscode.window.activeTextEditor; if (editor != undefined) { + let tag = vscode.workspace.getConfiguration().get("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); console.log('selection.start.character: ' + selection.start.character); @@ -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 + '

'); + editBuilder.insert(new vscode.Position(selectionEnd.line, selectionEnd.character), '\n' + selectionStart_spaces + ''); editBuilder.insert(new vscode.Position(selectionEnd.line, 0), tabSizeSpace); console.log('End line done. Line #: ' + selectionEnd.line); @@ -66,7 +72,7 @@ export function activate() { } // Modify firs line of selection - editBuilder.insert(new vscode.Position(selectionStart.line, selectionStart.character), '

\n' + selectionStart_spaces + tabSizeSpace); + 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!'); @@ -85,8 +91,8 @@ export function activate() { else { //Wrap it inline editor.edit((editBuilder) => { - editBuilder.insert(new vscode.Position(selectionEnd.line, selectionEnd.character), '

'); - editBuilder.insert(new vscode.Position(selectionEnd.line, selectionStart.character), '

'); + editBuilder.insert(new vscode.Position(selectionEnd.line, selectionEnd.character), ''); + editBuilder.insert(new vscode.Position(selectionEnd.line, selectionStart.character), '<' + tag + '>'); }).then(() => { console.log('Edit applied!'); diff --git a/test/debug.log b/test/debug.log new file mode 100644 index 0000000..c70d52e --- /dev/null +++ b/test/debug.log @@ -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 From 793103482e26b663f2a7c256a695c04e9fc392d3 Mon Sep 17 00:00:00 2001 From: Zach Spofford Date: Sat, 29 Jul 2017 17:30:48 -0500 Subject: [PATCH 2/3] changed cursor location to adjust for different length tags --- src/extension.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 0c92ddf..a10c8ec 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -40,7 +40,7 @@ export function activate() { var firstIndex = 1; var lastIndex = selectedText.length; - + console.log('selection is: ' + selectedText); console.log('length is: ' + lastIndex); console.log('selection.start.character: ' + selection.start.character); @@ -71,15 +71,15 @@ export function activate() { editBuilder.insert(new vscode.Position(lineNumber, 0), tabSizeSpace); } - // Modify firs line of selection + // 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; @@ -96,8 +96,8 @@ export function activate() { }).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; From f65454903c289ea492f37a9cfa116c96b4a7a08b Mon Sep 17 00:00:00 2001 From: Zach Spofford Date: Wed, 16 Aug 2017 13:45:46 -0500 Subject: [PATCH 3/3] Update ReadME.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c6cae3b..55449a7 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ add htmltagwrap.tag to your settings.json file( File-->Preferenc setting.json ``` { - "htmltagwrap.tag" = "p" + "htmltagwrap.tag": "p" } ```