From 626db99dc2490bf6a07225994d98ce9779547a45 Mon Sep 17 00:00:00 2001 From: Sergey Hayriyan Date: Sun, 2 Mar 2025 16:27:53 +0400 Subject: [PATCH] Use startKey --- main.ts | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/main.ts b/main.ts index e8ccbb1..ba4a614 100644 --- a/main.ts +++ b/main.ts @@ -12,6 +12,7 @@ import { interface MathTypePrefs { customMappings: { [key: string]: string }; + startKey: string } const DEFUALT_PREFS: MathTypePrefs = { @@ -159,7 +160,8 @@ const DEFUALT_PREFS: MathTypePrefs = { 'proves': '\\vdash', 'contradiction': '\\bot', 'tautology': '\\top' - } + }, + startKey: "^" } export default class MathType extends Plugin { @@ -202,9 +204,14 @@ class MathTypeSuggest extends EditorSuggest { const line = editor.getLine(cursor.line); const word = this.plugin.getWordUnderCursor(line, cursor.ch); + + if (!word.startsWith((this.plugin.settings.startKey))) return null; + + const lookup = word.substring(1) + // Check if the word matches any of our mappings const hasMatch = Object.keys(this.plugin.settings.customMappings) - .some(key => key.includes(word) && word.length >= 2); // Only trigger for 2+ characters + .some(key => key.includes(lookup) && lookup.length >= 2); // Only trigger for 2+ characters if (hasMatch) { return { @@ -213,7 +220,7 @@ class MathTypeSuggest extends EditorSuggest { ch: cursor.ch - word.length }, end: cursor, - query: word + query: lookup }; } return null; @@ -262,18 +269,16 @@ class PrefsTab extends PluginSettingTab { containerEl.empty(); containerEl.createEl('h2', {text: 'MathType Suggester Prefs'}); - containerEl.createEl('p', {text: 'Configure the mappings between words and MathJax syntax.'}); - for (const [key, value] of Object.entries(this.plugin.settings.customMappings)) { - new Setting(containerEl) - .setName(`Mapping for "${key}"`) - .setDesc(`MathJax syntax for ${key}`) - .addText(text => text - .setValue(value) - .onChange(async (newValue) => { - this.plugin.settings.customMappings[key] = newValue; - await this.plugin.saveSettings(); - })); - } + new Setting(containerEl) + .setName('Start Key') + .setDesc('Set the key to trigger MathType suggestions.') + .addText(text => text + .setValue(this.plugin.settings.startKey || '') + .onChange(async (newValue) => { + this.plugin.settings.startKey = newValue; + await this.plugin.saveSettings(); + })); + } }