Updates for publishing
This commit is contained in:
Родитель
47b8e07c99
Коммит
669416bd52
20
README.md
20
README.md
|
@ -2,23 +2,6 @@
|
|||
|
||||
This extension does the following:
|
||||
|
||||
## WordCount File Watcher
|
||||
Whenever a `markdown` file is loaded a status bar message is added which includes the current word count - this live updates as you type and move from file to file:
|
||||
|
||||
![Status](images/StatusWordCount.gif)
|
||||
|
||||
### Issues: Word Count
|
||||
the events for opening and closing a file don't seam to fire predictably:
|
||||
|
||||
Repro:
|
||||
|
||||
1. run extension
|
||||
2. open a folder w/ moced filed
|
||||
3. open a `.md` file status bar _may_ activate
|
||||
4. once activzated navigate to another file e.g. `.js`
|
||||
5. status bar stay stay active
|
||||
6. navigate to another `.md` status bar will probably activate but may have a stale count
|
||||
|
||||
## Keybinding 'Alt+T' - Text Tools
|
||||
Also available as `command`.
|
||||
|
||||
|
@ -34,9 +17,6 @@ Hit `Alt+T` to get some text replacement tools e.g.
|
|||
|
||||
Will replace all selections in the current editor.
|
||||
|
||||
### Issues: Ugly Code
|
||||
Lots of copy and paste can abstract [my] common code.
|
||||
|
||||
### Issues: Encode HTML
|
||||
This function will replace the selection(s) with more text than they had orriginally e.g.
|
||||
|
||||
|
|
36
extension.ts
36
extension.ts
|
@ -16,41 +16,10 @@ import us = require('underscore.string');
|
|||
export function activate() {
|
||||
console.log('Congratulations, your extension "TextTools" is now active!');
|
||||
|
||||
let wordCountStatus = new WordCountStatus();
|
||||
|
||||
vscode.commands.registerCommand('extension.textFunctions', textFunctions);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Word Count /////////////////////////////////////
|
||||
class WordCountStatus {
|
||||
constructor() {
|
||||
window.onDidChangeTextEditorSelection((textEditor) => {
|
||||
if (!textEditor) {
|
||||
// No more open editors
|
||||
return;
|
||||
}
|
||||
let doc = textEditor.textEditor.getTextDocument();
|
||||
|
||||
// Only update status if an MD file
|
||||
if (doc.getLanguageId() === "markdown") {
|
||||
window.setStatusBarMessage("Word Count [" + calcWordCount(doc.getText()) + "]");
|
||||
} else {
|
||||
window.setStatusBarMessage("");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function calcWordCount(text): number {
|
||||
text = text.replace(/(< ([^>]+)<)/g, '').replace(/\s+/g, ' ');
|
||||
text = text.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
||||
|
||||
return text.split(" ").length;
|
||||
}
|
||||
|
||||
// Selections test /////////////////////////////////////
|
||||
function workWithSelections() {
|
||||
var e = window.getActiveTextEditor();
|
||||
|
@ -113,6 +82,7 @@ function cleanString(e: vscode.TextEditor, d: vscode.TextDocument, sel: vscode.S
|
|||
}
|
||||
|
||||
|
||||
|
||||
function titleize(e: vscode.TextEditor, d: vscode.TextDocument, sel: vscode.Selection[]) {
|
||||
// itterate through the elections and convert all text to Upper
|
||||
for (var x = 0; x < sel.length; x++) {
|
||||
|
@ -133,8 +103,8 @@ function escapeHTML(e: vscode.TextEditor, d: vscode.TextDocument, sel: vscode.Se
|
|||
edit.replace(sel[x], txt);
|
||||
|
||||
// fix the selection as it could now be longer or shorter
|
||||
let startPos: Position = new Position(sel[x].start.line, sel[x].start.column);
|
||||
let endPos: Position = new Position(sel[x].end.line,sel[x].start.column + txt.length);
|
||||
let startPos: Position = new Position(sel[x].start.line, sel[x].start.character);
|
||||
let endPos: Position = new Position(sel[x].end.line,sel[x].start.character + txt.length);
|
||||
let replaceRange : Range = new Range(startPos, endPos);
|
||||
|
||||
e.setSelection(replaceRange);
|
||||
|
|
16
package.json
16
package.json
|
@ -1,12 +1,13 @@
|
|||
{
|
||||
"name": "30-Command",
|
||||
"version": "0.0.1",
|
||||
"publisher": "Sean",
|
||||
"name": "MDTools",
|
||||
"description": "Text replacement for Markdown",
|
||||
"version": "0.0.2",
|
||||
"publisher": "seanmcbreen",
|
||||
"activationEvents": [
|
||||
"onLanguage:markdown"
|
||||
],
|
||||
"engines": {
|
||||
"vscode": ">=0.9.0-pre.1"
|
||||
"vscode": "*"
|
||||
},
|
||||
"main": "./out/extension",
|
||||
"contributes": {
|
||||
|
@ -14,7 +15,7 @@
|
|||
{
|
||||
"command": "extension.textFunctions",
|
||||
"title": "Text Functions",
|
||||
"description": "Text Functions on selections"
|
||||
"description": "Text functions on selections"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
|
@ -24,6 +25,9 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"keywords": [
|
||||
"Markdown", "Linter", "Spell", "Grammar"
|
||||
],
|
||||
"scripts": {
|
||||
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
|
||||
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./"
|
||||
|
@ -32,6 +36,6 @@
|
|||
"underscore.string": "^3.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vscode": ">=0.9.0-pre.1"
|
||||
"vscode": "*"
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче