Skip to content

Commit

Permalink
feat: auto-search with note title
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangeGirlMurph committed May 21, 2024
1 parent 9af24e2 commit e5b3965
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Binary file modified docs/public/workflow-optimizations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ Whether or not the cursor is placed infront of the insert instead of after it. F

Default: `false`

### Auto-select single response queries
Whether or not to automatically use the active notes title when searching for articles. The current selection will be prioritized.

Default: `false`

### Auto-select single response queries
Whether or not to automatically select the response to a query when there is only one article to choose from. For example when you select someones name and want to hyperlink it to the persons Wikipedia article this feature will automatically select the article when there is only one article related to that name.

Expand Down
18 changes: 16 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface WikipediaSearchSettings {
templates: Template[];
placeCursorInfrontOfInsert: boolean;
autoInsertSingleResponseQueries: boolean;
autoSearchNoteTitle: boolean;
prioritizeArticleTitle: boolean;
cleanupIntros: boolean;
openArticleInFullscreen: boolean;
Expand All @@ -50,6 +51,7 @@ export const DEFAULT_SETTINGS: WikipediaSearchSettings = {
templates: [DEFAULT_TEMPLATE],
placeCursorInfrontOfInsert: false,
autoInsertSingleResponseQueries: false,
autoSearchNoteTitle: false,
prioritizeArticleTitle: false,
cleanupIntros: true,
openArticleInFullscreen: false,
Expand Down Expand Up @@ -102,7 +104,7 @@ export class WikipediaSearchSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName("Search limit")
.setDesc("Maximum number of search results to show. (Between 1 and 500)")
.setDesc("Maximum number of search results to show. (1≤limit≤500)")
.addText((text) =>
text
.setPlaceholder("limit")
Expand Down Expand Up @@ -168,6 +170,18 @@ export class WikipediaSearchSettingTab extends PluginSettingTab {
})
);

new Setting(containerEl)
.setName("Auto-search note title")
.setDesc(
"Whether or not to automatically use the active notes title when searching for articles."
)
.addToggle((toggle) =>
toggle.setValue(this.settings.autoSearchNoteTitle).onChange(async (value) => {
this.settings.autoSearchNoteTitle = value;
await this.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("Auto-select single response queries")
.setDesc(
Expand All @@ -183,7 +197,7 @@ export class WikipediaSearchSettingTab extends PluginSettingTab {
new Setting(containerEl)
.setName("Use article title instead of selection")
.setDesc(
"When hyperlinking: Whether or not to use the articles title instead of the selected text for the '{title}' parameter of your template."
"When hyperlinking: Whether or not to use the articles title instead of the selected text for the '{title}' tag of your template."
)
.addToggle((toggle) =>
toggle.setValue(this.settings.prioritizeArticleTitle).onChange(async (value) => {
Expand Down
12 changes: 11 additions & 1 deletion src/utils/searchModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ export abstract class SearchModal extends SuggestModal<Article> {
}

onOpen(): void {
this.inputEl.value = "";
if (this.editor) {
this.inputEl.value = this.editor.getSelection();
const selection = this.editor?.getSelection();
if (selection != "") {
this.inputEl.value = selection;
}
}
if (this.settings.autoSearchNoteTitle) {
const fileName = this.app.workspace.getActiveFile()?.basename;
if (fileName && fileName != "") {
this.inputEl.value = fileName;
}
}
//@ts-ignore - private method
super.updateSuggestions();
Expand Down

0 comments on commit e5b3965

Please sign in to comment.