-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved icons and gifs into common folder Restructured code
- Loading branch information
Showing
27 changed files
with
223 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var commands = require('./commands'); | ||
var commands = require('./lib/commands'); | ||
|
||
function activate(context) { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
var vscode = require("vscode"); | ||
|
||
module.exports = { | ||
isAnythingSelected: isAnythingSelected, | ||
replaceSelection: replaceSelection, | ||
surroundSelection: surroundSelection, | ||
isMatch: isMatch | ||
} | ||
|
||
function replaceSelection(replaceFunc) { | ||
var editor = vscode.window.activeTextEditor; | ||
var selection = editor.selection; | ||
|
||
var newText = replaceFunc(editor.document.getText(selection)); | ||
return editor.edit((edit) => { | ||
edit.replace(selection, newText) | ||
}) | ||
} | ||
|
||
function isAnythingSelected() { | ||
return !vscode.window.activeTextEditor.selection.isEmpty; | ||
} | ||
|
||
function surroundSelection(startPattern, endPattern) | ||
{ | ||
if (endPattern == undefined || endPattern == null) endPattern = startPattern; | ||
|
||
var editor = vscode.window.activeTextEditor; | ||
var selection = editor.selection; | ||
|
||
if (!isAnythingSelected()) { | ||
var position = selection.active; | ||
var newPosition = position.with(position.line, position.character + startPattern.length) | ||
editor.edit((edit) => { | ||
edit.insert(selection.start, startPattern + endPattern); | ||
}).then(() => { | ||
editor.selection = new vscode.Selection(newPosition, newPosition) | ||
}) | ||
} | ||
else { | ||
if (isMatch(startPattern, endPattern)) { | ||
replaceSelection((text) => text.substr(startPattern.length, text.length - startPattern.length - endPattern.length)) | ||
} | ||
else { | ||
replaceSelection((text) => startPattern + text + endPattern) | ||
} | ||
} | ||
} | ||
|
||
function isMatch(startPattern, endPattern) { | ||
|
||
var editor = vscode.window.activeTextEditor; | ||
var selection = editor.selection; | ||
|
||
var text = editor.document.getText(selection) | ||
if (startPattern.constructor === RegExp) { | ||
return startPattern.test(text); | ||
} | ||
|
||
return text.startsWith(startPattern) && text.endsWith(endPattern) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
var vscode = require("vscode"); | ||
var editorHelpers = require("./editorHelpers"); | ||
|
||
module.exports = { | ||
addTable: () => addTable(false), | ||
addTableWithHeader: () => addTable(true) | ||
}; | ||
|
||
var sampleTable = [ | ||
"", | ||
"Column A | Column B | Column C", | ||
"---------|----------|---------", | ||
" A1 | B1 | C1", | ||
" A2 | B2 | C2", | ||
" A3 | B3 | C3" | ||
].join("\r\n"); | ||
|
||
function addTable(addHeader) { | ||
//var editor = vscode.window.activeTextEditor; | ||
|
||
var editFunc; | ||
if (!editorHelpers.isAnythingSelected()) { | ||
editFunc = () => sampleTable; | ||
} | ||
else if (addHeader) { | ||
editFunc = convertToTableWithHeader; | ||
} | ||
else { | ||
editFunc = convertToTableWithoutHeader; | ||
} | ||
editorHelpers.replaceSelection(editFunc); | ||
} | ||
|
||
var tableColumnSeparator = /([ ]{2,}|[\t])/gi; | ||
function convertToTableWithoutHeader(text) { | ||
var firstRow = text.match(/.+/); | ||
|
||
var columnSeparators = firstRow == null ? null : firstRow[0].match(tableColumnSeparator); | ||
var columnCount = columnSeparators == null ? 0 : columnSeparators.length; | ||
var line1 = []; | ||
for (var i = 0; i < columnCount + 1; i++) { | ||
line1.push("column" + i); | ||
} | ||
var tableHeader = line1.join(" | ") + "\r\n"; | ||
tableHeader = tableHeader + tableHeader.replace(/[a-z0-9]/gi, "-"); | ||
|
||
return tableHeader + text.replace(tableColumnSeparator, " | "); | ||
} | ||
|
||
function convertToTableWithHeader(text) { | ||
var textAsTable = text.replace(tableColumnSeparator, " | "); | ||
|
||
var firstRow = textAsTable.match(/.+/)[0]; | ||
|
||
var headerLine = firstRow.replace(/[^\|]/gi, "-"); | ||
|
||
return firstRow + "\r\n" + headerLine + textAsTable.substring(firstRow.length); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.