Skip to content
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"activationEvents": [
"onCommand:unicode-latex.insertMathSymbol",
"onCommand:unicode-latex.replaceLatexNames",
"onCommand:unicode-latex.showLatexCode",
"onLanguage:plaintext"
],
"main": "./out/src/extension",
Expand All @@ -29,6 +30,10 @@
{
"command": "unicode-latex.replaceLatexNames",
"title": "Unicode: Replace LaTeX"
},
{
"command": "unicode-latex.showLatexCode",
"title": "Unicode: Show LaTex Code"
}
]
},
Expand Down
25 changes: 25 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let latexItems: vscode.QuickPickItem[] = [];
let pickOptions: vscode.QuickPickOptions = {
matchOnDescription: true,
};
var latexSymbols2: { [name:string]: string} = {};

export function activate(context: vscode.ExtensionContext) {

Expand All @@ -17,6 +18,7 @@ export function activate(context: vscode.ExtensionContext) {
description: name,
label: latexSymbols[name],
});
latexSymbols2[latexSymbols[name]] = name;
}

let insertion = vscode.commands.registerCommand('unicode-latex.insertMathSymbol', () => {
Expand All @@ -25,13 +27,17 @@ export function activate(context: vscode.ExtensionContext) {
let replacement = vscode.commands.registerCommand('unicode-latex.replaceLatexNames', () => {
replaceWithUnicode(vscode.window.activeTextEditor);
});
let showLatex = vscode.commands.registerCommand('unicode-latex.showLatexCode', () => {
appendLatexOfUnicode(vscode.window.activeTextEditor);
});

const selector: vscode.DocumentSelector = ['plaintext', 'markdown', 'coq'];
const provider = new LatexCompletionItemProvider(latexSymbols);
let completionSub = vscode.languages.registerCompletionItemProvider(selector, provider, '\\');

context.subscriptions.push(insertion);
context.subscriptions.push(replacement);
context.subscriptions.push(showLatex);
context.subscriptions.push(completionSub);
}

Expand Down Expand Up @@ -78,5 +84,24 @@ function replaceWithUnicode(editor: vscode.TextEditor) {
});
}

function appendLatexOfUnicode(editor: vscode.TextEditor) {
if (!editor) { return; }

// If nothing is selected, do nothing
let selection = (() => {
if (editor.selection.start.isBefore(editor.selection.end)) {
return editor.selection;
} else {
return;
}
})();

let text = editor.document.getText(selection);
if (latexSymbols2.hasOwnProperty(text)){
editor.edit((editBuilder) => {
editBuilder.insert(editor.selection.end, latexSymbols2[text]);
});
}
}
// this method is called when your extension is deactivated
export function deactivate() {}