Ready for review
This commit is contained in:
Родитель
509594270e
Коммит
b05f94aab3
27
extension.ts
27
extension.ts
|
@ -1,4 +1,3 @@
|
|||
// import {workspace, languages, Diagnostic, DiagnosticSeverity, Location, Range, Disposable, Modes, TextDocument, Position} from 'vscode';
|
||||
import * as vscode from 'vscode';
|
||||
import Window = vscode.window;
|
||||
import QuickPickItem = vscode.QuickPickItem;
|
||||
|
@ -9,7 +8,6 @@ import Range = vscode.Range;
|
|||
import Selection = vscode.Selection;
|
||||
import TextDocument = vscode.TextDocument;
|
||||
import TextEditor = vscode.TextEditor;
|
||||
|
||||
//import InputBoxOptions = InputBoxOptions;
|
||||
|
||||
var figlet = require('figlet');
|
||||
|
@ -21,35 +19,37 @@ export function activate() {
|
|||
}
|
||||
|
||||
// String Functions Helper//////////////////////////////
|
||||
// TODO [P1] - it would be better to use a format like I have for the Underscore calls below - more common code
|
||||
function toUpper(e: TextEditor, d: TextDocument, sel: Selection[]) {
|
||||
// itterate through the elections and convert all text to Upper
|
||||
for (var x = 0; x < sel.length; x++) {
|
||||
e.edit(function(edit) {
|
||||
let txt: string = d.getTextInRange(new Range(sel[x].start, sel[x].end));
|
||||
let txt: string = d.getText(new Range(sel[x].start, sel[x].end));
|
||||
edit.replace(sel[x], txt.toUpperCase());
|
||||
});
|
||||
e.setSelections(sel)
|
||||
e.updateSelection(sel);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO [P1] - it would be better to use a format like I have for the Underscore calls below - more common code
|
||||
function toLower(e: TextEditor, d: TextDocument, sel: Selection[]) {
|
||||
// itterate through the elections and convert all text to Upper
|
||||
for (var x = 0; x < sel.length; x++) {
|
||||
e.edit(function(edit) {
|
||||
let txt: string = d.getTextInRange(new Range(sel[x].start, sel[x].end));
|
||||
let txt: string = d.getText(new Range(sel[x].start, sel[x].end));
|
||||
edit.replace(sel[x], txt.toLowerCase());
|
||||
});
|
||||
e.setSelections(sel)
|
||||
e.updateSelection(sel)
|
||||
}
|
||||
}
|
||||
|
||||
// This function takes a callbac function for the text formatting 'formatCB',
|
||||
// This function takes a callback function for the text formatting 'formatCB',
|
||||
// if there are any args pass an array as 'argsCB'
|
||||
function processSelection(e: TextEditor, d: TextDocument, sel: Selection[], formatCB, argsCB) {
|
||||
// itterate through the selections
|
||||
for (var x = 0; x < sel.length; x++) {
|
||||
e.edit(function(edit) {
|
||||
let txt: string = d.getTextInRange(new Range(sel[x].start, sel[x].end));
|
||||
let txt: string = d.getText(new Range(sel[x].start, sel[x].end));
|
||||
|
||||
if (argsCB.length > 0) {
|
||||
argsCB.splice(0, 0, txt);
|
||||
|
@ -61,10 +61,12 @@ function processSelection(e: TextEditor, d: TextDocument, sel: Selection[], form
|
|||
|
||||
// fix the selection as it could now be longer or shorter
|
||||
let startPos: Position = new Position(sel[x].start.line, sel[x].start.character);
|
||||
// TODO [p1] the end position is not right - do something that increases or decreases the size
|
||||
// of the selection to see issue e.g. ASC II art or HTML encode/decode
|
||||
let endPos: Position = new Position(sel[x].start.line + txt.split(/\r\n|\r|\n/).length, sel[x].start.character + txt.length);
|
||||
let replaceRange: Range = new Range(startPos, endPos);
|
||||
|
||||
e.setSelection(replaceRange);
|
||||
e.updateSelection(replaceRange);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -85,9 +87,9 @@ function textFunctions() {
|
|||
items.push({ label: "ASCII Art", description: "Convert [hello] to ASCII Art" });
|
||||
|
||||
Window.showQuickPick(items).then((selection) => {
|
||||
let e = Window.getActiveTextEditor();
|
||||
let d = e.getTextDocument();
|
||||
let sel = e.getSelections();
|
||||
let e = Window.activeTextEditor;
|
||||
let d = e.document;
|
||||
let sel = e.selections;
|
||||
|
||||
switch (selection.label) {
|
||||
case "toUpper":
|
||||
|
@ -115,6 +117,7 @@ function textFunctions() {
|
|||
processSelection(e, d, sel, us.unescapeHTML, []);
|
||||
break;
|
||||
case "ASCII Art":
|
||||
// build a full list of the fonts for the drop down
|
||||
items = [];
|
||||
figlet.fontsSync().forEach(function (font) {
|
||||
items.push({ label: font, description: "User the "+ font + " font" });
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "MDTools",
|
||||
"description": "Text replacement functions and ASCII Art for Markdown",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"publisher": "seanmcbreen",
|
||||
"categories":[
|
||||
"Test"
|
||||
|
@ -51,6 +51,6 @@
|
|||
"figlet": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vscode": "*"
|
||||
"vscode": "next"
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче