You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
|
8 years ago
|
'use babel';
|
||
|
|
|
||
|
|
import { CompositeDisposable } from 'atom';
|
||
|
|
|
||
|
|
export default {
|
||
|
|
|
||
|
|
subscriptions: null,
|
||
|
|
|
||
|
|
activate(state) {
|
||
|
|
|
||
|
|
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
|
||
|
|
this.subscriptions = new CompositeDisposable();
|
||
|
|
|
||
|
|
// Register command that toggles this view
|
||
|
|
this.subscriptions.add(atom.commands.add('atom-workspace', {
|
||
|
|
'latex-helper:convert-to-display-math': () => this.convertToDisplayMath(),
|
||
|
|
'latex-helper:convert-to-abs': () => this.convertToAbs(),
|
||
|
|
'latex-helper:mathify-comma-list': () => this.mathifyList(),
|
||
|
|
'latex-helper:insert-backslash-comma': () => this.insertBackslashComma(),
|
||
|
|
}));
|
||
|
|
},
|
||
|
|
|
||
|
|
deactivate() {
|
||
|
|
this.subscriptions.dispose();
|
||
|
|
},
|
||
|
|
|
||
|
|
|
||
|
|
convertToDisplayMath() {
|
||
|
|
const editor = atom.workspace.getActiveTextEditor()
|
||
|
|
if (editor) {
|
||
|
|
const selection = editor.getSelectedText()
|
||
|
|
const strippedText = selection.replace(/\$/g, '')
|
||
|
|
editor.insertText("\\[\n" + strippedText.trim() + "\n\\]")
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
convertToAbs() {
|
||
|
|
const editor = atom.workspace.getActiveTextEditor()
|
||
|
|
if (editor) {
|
||
|
|
const selection = editor.getSelectedText()
|
||
|
|
const strippedText = selection
|
||
|
|
.replace(/\\mid/g, '')
|
||
|
|
.replace(/\|/g,'')
|
||
|
|
.replace(/\\left/g,'')
|
||
|
|
.replace(/\\right/g,'')
|
||
|
|
editor.insertText("\\abs{" + strippedText.trim() + "}")
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
mathifyList() {
|
||
|
|
const editor = atom.workspace.getActiveTextEditor()
|
||
|
|
if (editor) {
|
||
|
|
const selection = editor.getSelectedText()
|
||
|
|
const items = selection.replace('$','').split(',').map((item) => item.trim())
|
||
|
|
editor.insertText("$" + items.join('$, $') + "$")
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
insertBackslashComma() {
|
||
|
|
const editor = atom.workspace.getActiveTextEditor()
|
||
|
|
if (editor) {
|
||
|
|
editor.insertText('\\,')
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
};
|