/
saintbyte
/
obsidian_gigachat_spell_checker
Обзор
Документация
Войти
/
saintbyte
/
obsidian_gigachat_spell_checker
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main.ts
115 строк
3 KB
Yegor Kazantsev
first_commit
27 июн 2026, 14:51
27 июн 2026, 14:51
fd4b88b
Код
Авторство
О чём код?
import { Editor, MarkdownView, MarkdownFileInfo, Menu, Modal, Notice, Plugin, } from 'obsidian'; import { DEFAULT_SETTINGS, GigachatSpellCheckerPluginSettings, SampleSettingTab, } from './settings'; // Remember to rename these classes and interfaces! export default class GigachatSpellCheckerPlugin extends Plugin { settings!: GigachatSpellCheckerPluginSettings; async onload() { await this.loadSettings(); this.addCommand({ id: 'open-modal-simple', name: 'Open modal (simple)', callback: () => { new SampleModal(this.app).open(); }, }); const fixErrors = ( editor: Editor, _ctx: MarkdownView | MarkdownFileInfo, ) => { const selected = editor.getSelection(); if (!selected) { new Notice('Нет выделенного текста'); return; } editor.replaceSelection(selected); new Notice('Проверка орфографии пока не реализована'); }; this.addCommand({ id: 'gigachat-fix-spelling-errors', name: 'Исправить ошибки', editorCallback: fixErrors, }); this.registerEvent( this.app.workspace.on('editor-menu', ( menu: Menu, editor: Editor, ctx: MarkdownView | MarkdownFileInfo, ) => { if (editor.getSelection()) { menu.addItem((item) => item .setTitle('Исправить ошибки') .setIcon('spellcheck') .onClick(() => fixErrors(editor, ctx)), ); } }), ); // This adds a complex command that can check whether the current state of the app allows execution of the command this.addCommand({ id: 'open-modal-complex', name: 'Open modal (complex)', checkCallback: (checking: boolean) => { // Conditions to check const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView); if (markdownView) { // If checking is true, we're simply "checking" if the command can be run. // If checking is false, then we want to actually perform the operation. if (!checking) { new SampleModal(this.app).open(); } // This command will only show up in Command Palette when the check function returns true return true; } return false; }, }); this.addSettingTab(new SampleSettingTab(this.app, this)); } onunload() {} async loadSettings() { this.settings = Object.assign( {}, DEFAULT_SETTINGS, (await this.loadData()) as Partial< GigachatSpellCheckerPluginSettings>, ); } async saveSettings() { await this.saveData(this.settings); } } class SampleModal extends Modal { onOpen() { const { contentEl } = this; contentEl.setText('Woah!'); } onClose() { const { contentEl } = this; contentEl.empty(); } }