Skip to content

Commit

Permalink
fix(main.ts): refactor openNewBookNote function to improve readabilit…
Browse files Browse the repository at this point in the history
…y 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
  • Loading branch information
anpigon committed Oct 18, 2023
1 parent 520920f commit 854c2d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
28 changes: 11 additions & 17 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Book[]> {
return new Promise((resolve, reject) => {
return new BookSearchModal(this, query, (error, results) => {
Expand Down
17 changes: 7 additions & 10 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const DEFAULT_SETTINGS: BookSearchPluginSettings = {
naverClientId: '',
naverClientSecret: '',
localePreference: 'default',
openPageOnCompletion: true
openPageOnCompletion: true,
};

export class BookSearchSettingTab extends PluginSettingTab {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 854c2d0

Please sign in to comment.