diff --git a/src/main.ts b/src/main.ts index 751a885..f9d3c31 100644 --- a/src/main.ts +++ b/src/main.ts @@ -123,34 +123,28 @@ export default class BookSearchPlugin extends Plugin { // if use Templater plugin await useTemplaterPluginInFile(this.app, targetFile); this.openNewBookNote(targetFile); - } catch (err) { console.warn(err); this.showNotice(err); } } - async openNewBookNote(targetFile: TFile) { - if (!this.settings.openPageOnCompletion) - return; + if (!this.settings.openPageOnCompletion) return; + // open file + const activeLeaf = this.app.workspace.getLeaf(); + if (!activeLeaf) { + console.warn('No active leaf'); + return; + } - // open file - const activeLeaf = this.app.workspace.getLeaf(); - if (!activeLeaf) { - console.warn('No active leaf'); - return; - } - - await activeLeaf.openFile(targetFile, { state: { mode: 'source' } }); - activeLeaf.setEphemeralState({ rename: 'all' }); - // cursor focus - await new CursorJumper(this.app).jumpToNextCursorLocation(); + await activeLeaf.openFile(targetFile, { state: { mode: 'source' } }); + activeLeaf.setEphemeralState({ rename: 'all' }); + // cursor focus + await new CursorJumper(this.app).jumpToNextCursorLocation(); } - - async openBookSearchModal(query = ''): Promise { return new Promise((resolve, reject) => { return new BookSearchModal(this, query, (error, results) => { diff --git a/src/settings/settings.ts b/src/settings/settings.ts index 87f7a3a..67694e7 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -42,7 +42,7 @@ export const DEFAULT_SETTINGS: BookSearchPluginSettings = { naverClientId: '', naverClientSecret: '', localePreference: 'default', - openPageOnCompletion: true + openPageOnCompletion: true, }; export class BookSearchSettingTab extends PluginSettingTab { @@ -209,18 +209,15 @@ export class BookSearchSettingTab extends PluginSettingTab { }); new Setting(containerEl) - .setName("Open New Book Note") - .setDesc("Enable or disable the automatic opening of the note on creation.") + .setName('Open New Book Note') + .setDesc('Enable or disable the automatic opening of the note on creation.') .addToggle(toggle => - toggle - .setValue(this.plugin.settings.openPageOnCompletion) - .onChange(async value => { - this.plugin.settings.openPageOnCompletion = value; - await this.plugin.saveSettings(); - }) + toggle.setValue(this.plugin.settings.openPageOnCompletion).onChange(async value => { + this.plugin.settings.openPageOnCompletion = value; + await this.plugin.saveSettings(); + }), ); - // Frontmatter Settings const formatterSettingsChildren: Setting[] = []; createFoldingHeader(containerEl, 'Frontmatter Settings', formatterSettingsChildren);