Skip to content

Commit

Permalink
Remove a useless function call
Browse files Browse the repository at this point in the history
Calling 'reconfigureLatexSuiteConfig' in 'processSettings' is useless.
  • Loading branch information
bdm-k committed Aug 20, 2024
1 parent f73350d commit b0d7172
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
12 changes: 1 addition & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { LatexSuiteSettingTab } from "./settings/settings_tab";
import { ICONS } from "./settings/ui/icons";

import { getEditorCommands } from "./features/editor_commands";
import { iterateCM6 } from "./utils/editor_utils";
import { getLatexSuiteConfigExtension, reconfigureLatexSuiteConfig } from "./snippets/codemirror/config";
import { getLatexSuiteConfigExtension } from "./snippets/codemirror/config";
import { SnippetVariables, parseSnippetVariables, parseSnippets } from "./snippets/parse";
import { handleUpdate, onKeydown } from "./latex_suite";
import { EditorView, tooltips } from "@codemirror/view";
Expand Down Expand Up @@ -148,20 +147,11 @@ export default class LatexSuitePlugin extends Plugin {

async processSettings(becauseFileLocationUpdated = false, becauseFileUpdated = false) {
this.CMSettings = processLatexSuiteSettings(await this.getSnippets(becauseFileLocationUpdated, becauseFileUpdated), this.settings);
this.reconfigureLatexSuiteConfig();
this.setEditorExtensions();
// Request Obsidian to reconfigure CM extensions
this.app.workspace.updateOptions();
}

reconfigureLatexSuiteConfig() {
iterateCM6(this.app.workspace, (view) => {
view.dispatch({
effects: reconfigureLatexSuiteConfig(this.CMSettings)
});
})
}

// Set 'this.editorExtensions' based on the contents of 'this.CMSettings'
setEditorExtensions() {
// Remove all currently loaded CM extensions
Expand Down
10 changes: 2 additions & 8 deletions src/snippets/codemirror/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EditorView } from "@codemirror/view";
import { Facet, Compartment, EditorState } from "@codemirror/state";
import { Facet, EditorState } from "@codemirror/state";
import { LatexSuiteCMSettings, processLatexSuiteSettings, DEFAULT_SETTINGS } from "src/settings/settings";

export const latexSuiteConfig = Facet.define<LatexSuiteCMSettings, LatexSuiteCMSettings>({
Expand All @@ -15,12 +15,6 @@ export function getLatexSuiteConfig(viewOrState: EditorView | EditorState) {
return state.facet(latexSuiteConfig);
}

export const latexSuiteConfigCompartment = new Compartment();

export function getLatexSuiteConfigExtension(pluginSettings: LatexSuiteCMSettings) {
return latexSuiteConfigCompartment.of(latexSuiteConfig.of(pluginSettings));
return latexSuiteConfig.of(pluginSettings);
}

export function reconfigureLatexSuiteConfig(pluginSettings: LatexSuiteCMSettings) {
return latexSuiteConfigCompartment.reconfigure(latexSuiteConfig.of(pluginSettings));
}
10 changes: 1 addition & 9 deletions src/utils/editor_utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Platform, Workspace, MarkdownView } from "obsidian";
import { Platform } from "obsidian";
import { EditorView } from "@codemirror/view";
import { SyntaxNode, TreeCursor } from "@lezer/common";
import { EditorState } from "@codemirror/state";
Expand All @@ -9,14 +9,6 @@ export function replaceRange(view: EditorView, start: number, end: number, repla
});
}

export function iterateCM6(workspace: Workspace, callback: (editor: EditorView) => unknown) {
workspace.iterateAllLeaves(leaf => {
leaf?.view instanceof MarkdownView &&
(leaf.view.editor as any)?.cm instanceof EditorView &&
callback((leaf.view.editor as any).cm);
});
}

export function getCharacterAtPos(viewOrState: EditorView | EditorState, pos: number) {
const state = viewOrState instanceof EditorView ? viewOrState.state : viewOrState;
const doc = state.doc;
Expand Down

0 comments on commit b0d7172

Please sign in to comment.