From 854c2d0e201d37a0d4e7a245f0a5aedd34736d17 Mon Sep 17 00:00:00 2001 From: anpigon Date: Wed, 18 Oct 2023 11:18:06 +0900 Subject: [PATCH] fix(main.ts): refactor openNewBookNote function to improve readability and remove unnecessary code feat(main.ts): add support for opening new book note in source mode and setting ephemeral state fix(settings.ts): fix formatting and indentation in DEFAULT_SETTINGS and BookSearchSettingTab --- src/main.ts | 28 +++++++++++----------------- src/settings/settings.ts | 17 +++++++---------- 2 files changed, 18 insertions(+), 27 deletions(-) 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);