Skip to content

Commit

Permalink
refactor editor commands
Browse files Browse the repository at this point in the history
  • Loading branch information
artisticat1 committed Apr 8, 2023
1 parent 76ac171 commit a84362e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
49 changes: 44 additions & 5 deletions src/editor_commands.ts → src/features/editor_commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Editor, MarkdownView } from "obsidian";
import { EditorView } from "@codemirror/view";
import { isWithinEquation, getEquationBounds, replaceRange, setCursor, setSelection } from "./editor_helpers";
import { isWithinEquation, getEquationBounds, replaceRange, setCursor, setSelection } from "../editor_helpers";
import LatexSuitePlugin from "../main";


function boxCurrentEquation(view: EditorView) {
Expand Down Expand Up @@ -78,7 +79,45 @@ function getSelectEquationCommand() {
}


export const editorCommands = [
getBoxEquationCommand(),
getSelectEquationCommand()
];
function getEnableAllFeaturesCommand(plugin: LatexSuitePlugin) {
return {
id: "latex-suite-enable-all-features",
name: "Enable all features",
callback: async () => {
plugin.settings.snippetsEnabled = true;
plugin.settings.autofractionEnabled = true;
plugin.settings.matrixShortcutsEnabled = true;
plugin.settings.taboutEnabled = true;
plugin.settings.autoEnlargeBrackets = true;

await plugin.saveSettings();
},
}
}


function getDisableAllFeaturesCommand(plugin: LatexSuitePlugin) {
return {
id: "latex-suite-disable-all-features",
name: "Disable all features",
callback: async () => {
plugin.settings.snippetsEnabled = false;
plugin.settings.autofractionEnabled = false;
plugin.settings.matrixShortcutsEnabled = false;
plugin.settings.taboutEnabled = false;
plugin.settings.autoEnlargeBrackets = false;

await plugin.saveSettings();
},
}
}


export const getEditorCommands = (plugin: LatexSuitePlugin) => {
return [
getBoxEquationCommand(),
getSelectEquationCommand(),
getEnableAllFeaturesCommand(plugin),
getDisableAllFeaturesCommand(plugin)
];
};
33 changes: 2 additions & 31 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Plugin, Notice } from "obsidian";
import { LatexSuiteSettings, LatexSuiteSettingTab, DEFAULT_SETTINGS } from "./settings";
import { editorCommands } from "./editor_commands";

import { EditorView, ViewUpdate, tooltips } from "@codemirror/view";
import { Prec, Extension } from "@codemirror/state";
Expand All @@ -22,6 +21,7 @@ import { runSnippets } from "./features/run_snippets";
import { runAutoFraction } from "./features/autofraction";
import { tabout, shouldTaboutByCloseBracket } from "./features/tabout";
import { runMatrixShortcuts } from "./features/matrix_shortcuts";
import { getEditorCommands } from "./features/editor_commands";


export default class LatexSuitePlugin extends Plugin {
Expand Down Expand Up @@ -179,38 +179,9 @@ export default class LatexSuitePlugin extends Plugin {


private readonly addEditorCommands = () => {
for (const command of editorCommands) {
for (const command of getEditorCommands(this)) {
this.addCommand(command);
}

this.addCommand({
id: "latex-suite-enable-all-features",
name: "Enable all features",
callback: async () => {
this.settings.snippetsEnabled = true;
this.settings.autofractionEnabled = true;
this.settings.matrixShortcutsEnabled = true;
this.settings.taboutEnabled = true;
this.settings.autoEnlargeBrackets = true;

await this.saveSettings();
},
});

this.addCommand({
id: "latex-suite-disable-all-features",
name: "Disable all features",
callback: async () => {
this.settings.snippetsEnabled = false;
this.settings.autofractionEnabled = false;
this.settings.matrixShortcutsEnabled = false;
this.settings.taboutEnabled = false;
this.settings.autoEnlargeBrackets = false;

await this.saveSettings();
},
});

}


Expand Down

0 comments on commit a84362e

Please sign in to comment.