From 664d2ef30b9988a35001c5771eca23bf18c515b6 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Tue, 26 Apr 2022 21:51:10 +0200 Subject: [PATCH 1/7] Fixed the InFile's `searchQuery` that was overwritten by an empty `lastSearch` --- src/components/ModalInFile.svelte | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/ModalInFile.svelte b/src/components/ModalInFile.svelte index 309e2a9..cd6e047 100644 --- a/src/components/ModalInFile.svelte +++ b/src/components/ModalInFile.svelte @@ -28,7 +28,9 @@ let selectedIndex = 0 let note: ResultNote | null = null onMount(() => { - searchQuery = lastSearch + if (lastSearch && !searchQuery) { + searchQuery = lastSearch + } eventBus.disable("vault") eventBus.on("infile", "enter", openSelection) @@ -61,7 +63,7 @@ $: { } /** - * Group together close + * Group together close matches to reduce the number of results */ function getGroups(matches: SearchMatch[]): SearchMatch[][] { const groups: SearchMatch[][] = [] From e7b552dc922ca627a5423b41c9f24a06b692fad7 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Tue, 26 Apr 2022 22:10:05 +0200 Subject: [PATCH 2/7] PR fixes for obsidian-releases https://github.com/obsidianmd/obsidian-releases/pull/920#issuecomment-1110183606 --- src/main.ts | 14 +++----------- src/modals.ts | 52 +++++++++++++++++++++------------------------------ 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/src/main.ts b/src/main.ts index 91fbf71..2e97d1d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { MarkdownView, Plugin, TFile } from 'obsidian' +import { Plugin, TFile } from 'obsidian' import { addToIndex, initGlobalSearchIndex, @@ -21,16 +21,8 @@ export default class OmnisearchPlugin extends Plugin { this.addCommand({ id: 'show-modal-infile', name: 'In-file search', - checkCallback: (checking: boolean) => { - // Can only be shown when a note is active - const view = app.workspace.getActiveViewOfType(MarkdownView) - if (view) { - if (!checking) { - new OmnisearchInFileModal(app, view.file).open() - } - return true - } - return false + editorCallback: (_editor, view) => { + new OmnisearchInFileModal(app, view.file).open() }, }) diff --git a/src/modals.ts b/src/modals.ts index 3af48a3..70c50aa 100644 --- a/src/modals.ts +++ b/src/modals.ts @@ -17,37 +17,27 @@ abstract class OmnisearchModal extends Modal { this.modalEl.tabIndex = -1 // Setup events that can be listened through the event bus - this.modalEl.onkeydown = ev => { - switch (ev.key) { - case 'ArrowDown': - ev.preventDefault() - eventBus.emit('arrow-down') - break - case 'ArrowUp': - ev.preventDefault() - eventBus.emit('arrow-up') - break - case 'Enter': - ev.preventDefault() - if (ev.ctrlKey || ev.metaKey) { - // Open in a new pane - eventBus.emit('ctrl-enter') - } - else if (ev.shiftKey) { - // Create a new note - eventBus.emit('shift-enter') - } - else if (ev.altKey) { - // Expand in-note results - eventBus.emit('alt-enter') - } - else { - // Open in current pane - eventBus.emit('enter') - } - break - } - } + this.scope.register([], 'ArrowDown', () => { + eventBus.emit('arrow-down') + }) + this.scope.register([], 'ArrowUp', () => { + eventBus.emit('arrow-up') + }) + this.scope.register(['Ctrl'], 'Enter', () => { + eventBus.emit('ctrl-enter') // Open in new pane + }) + this.scope.register(['Meta'], 'Enter', () => { + eventBus.emit('ctrl-enter') // Open in new pane (but on Mac) + }) + this.scope.register(['Alt'], 'Enter', () => { + eventBus.emit('alt-enter') // Open the InFile modal + }) + this.scope.register(['Shift'], 'Enter', () => { + eventBus.emit('shift-enter') // Create a new note + }) + this.scope.register([], 'Enter', () => { + eventBus.emit('enter') // Open in current pane + }) } } From 627c7f33d62430f653eb4b13d3a51273b68a1ad6 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Tue, 26 Apr 2022 22:15:26 +0200 Subject: [PATCH 3/7] Dropped the namespace prefix. It's cleaner. --- .github/workflows/release.yml | 2 +- README.md | 2 +- manifest.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index abb1296..feae59a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,7 @@ on: - "*" env: - PLUGIN_NAME: scambier.obsidian-omnisearch + PLUGIN_NAME: omnisearch DIST_FOLDER: ./dist jobs: diff --git a/README.md b/README.md index b1dfbbb..2f2dfa0 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Under the hood, it uses the excellent [MiniSearch](https://github.com/lucaong/mi Omnisearch is not yet available on the official community plugins repository. You can either: - Install it through [BRAT](https://github.com/TfTHacker/obsidian42-brat) -- Or download the `scambier.obsidian-omnisearch-x.y.z.zip` file from the [releases page](https://github.com/scambier/obsidian-omnisearch/releases) and unzip it in your `.obsidian/plugins` folder. You'll have to update it manually, though. +- Or download the `omnisearch-x.y.z.zip` file from the [releases page](https://github.com/scambier/obsidian-omnisearch/releases) and unzip it in your `.obsidian/plugins` folder. You'll have to update it manually, though. ## Usage diff --git a/manifest.json b/manifest.json index 0bfe0d2..e6a2658 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "id": "scambier.obsidian-omnisearch", + "id": "omnisearch", "name": "Omnisearch", "version": "0.2.5", "minAppVersion": "0.14.2", From 6912d99d2764039781a812f84efe9ed60585899e Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 27 Apr 2022 07:31:57 +0200 Subject: [PATCH 4/7] 1.0.0 --- manifest.json | 2 +- package.json | 2 +- versions.json | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index e6a2658..9f4b0a0 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "omnisearch", "name": "Omnisearch", - "version": "0.2.5", + "version": "1.0.0", "minAppVersion": "0.14.2", "description": "A search engine that just works", "author": "Simon Cambier", diff --git a/package.json b/package.json index ad14017..e8feafe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scambier.obsidian-search", - "version": "0.2.5", + "version": "1.0.0", "description": "A search engine for Obsidian", "main": "dist/main.js", "scripts": { diff --git a/versions.json b/versions.json index de02512..ac69b47 100644 --- a/versions.json +++ b/versions.json @@ -13,5 +13,6 @@ "0.2.2": "0.14.2", "0.2.3": "0.14.2", "0.2.4": "0.14.2", - "0.2.5": "0.14.2" + "0.2.5": "0.14.2", + "1.0.0": "0.14.2" } \ No newline at end of file From b1db397923058f9fdcbfa0b6ad4e10b12a5ee666 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 27 Apr 2022 17:02:12 +0200 Subject: [PATCH 5/7] 1.0.1 Added a warning if the old version of Omnisearch is installed --- manifest.json | 2 +- package.json | 2 +- src/main.ts | 17 ++++++++++++++++- versions.json | 3 ++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index 9f4b0a0..f7f61bd 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "omnisearch", "name": "Omnisearch", - "version": "1.0.0", + "version": "1.0.1", "minAppVersion": "0.14.2", "description": "A search engine that just works", "author": "Simon Cambier", diff --git a/package.json b/package.json index e8feafe..8702c26 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scambier.obsidian-search", - "version": "1.0.0", + "version": "1.0.1", "description": "A search engine for Obsidian", "main": "dist/main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index 2e97d1d..1738168 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { Plugin, TFile } from 'obsidian' +import { Notice, Plugin, TFile } from 'obsidian' import { addToIndex, initGlobalSearchIndex, @@ -9,6 +9,8 @@ import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals' export default class OmnisearchPlugin extends Plugin { async onload(): Promise { + warningOldVersion() + // Commands to display Omnisearch modals this.addCommand({ id: 'show-modal', @@ -57,3 +59,16 @@ export default class OmnisearchPlugin extends Plugin { }) } } + +function warningOldVersion() { + const installed = (app as any).plugins.enabledPlugins as Set + if (installed.has('scambier.omnisearch')) { + new Notice( + `OMNISEARCH +It looks like you have 2 versions of Omnisearch installed. +Please uninstall the old one (up to 0.2.5) and keep the new one (1.0.0+) +(Click to dismiss)`, + 0, + ) + } +} diff --git a/versions.json b/versions.json index ac69b47..e4ffc29 100644 --- a/versions.json +++ b/versions.json @@ -14,5 +14,6 @@ "0.2.3": "0.14.2", "0.2.4": "0.14.2", "0.2.5": "0.14.2", - "1.0.0": "0.14.2" + "1.0.0": "0.14.2", + "1.0.1": "0.14.2" } \ No newline at end of file From 3417d30508b0cf146f19651a6c9f741826e0e5d4 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 27 Apr 2022 19:19:40 +0200 Subject: [PATCH 6/7] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2f2dfa0..710f528 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,9 @@ Under the hood, it uses the excellent [MiniSearch](https://github.com/lucaong/mi ## Installation -Omnisearch is not yet available on the official community plugins repository. You can either: +[Omnisearch is available on the official Community Plugins repository](https://obsidian.md/plugins?search=omnisearch#). -- Install it through [BRAT](https://github.com/TfTHacker/obsidian42-brat) -- Or download the `omnisearch-x.y.z.zip` file from the [releases page](https://github.com/scambier/obsidian-omnisearch/releases) and unzip it in your `.obsidian/plugins` folder. You'll have to update it manually, though. +You can also install it through [BRAT](https://github.com/TfTHacker/obsidian42-brat) for the future beta releases. ## Usage @@ -64,4 +63,4 @@ For example, if you'd like the usual yellow highlight on search matches, you can ## LICENSE -Omnisearch is licensed under [GPL-3](https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3)). \ No newline at end of file +Omnisearch is licensed under [GPL-3](https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3)). From 004fcd97751f252b9e99ba89ab2f5f9de729b325 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 27 Apr 2022 21:06:50 +0200 Subject: [PATCH 7/7] Different method to check dupe installation app.plugins.enabledPlugins seems buggy when a plugin is not correctly deleted --- src/main.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1738168..65b63b0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -60,9 +60,9 @@ export default class OmnisearchPlugin extends Plugin { } } -function warningOldVersion() { - const installed = (app as any).plugins.enabledPlugins as Set - if (installed.has('scambier.omnisearch')) { +function warningOldVersion(): void { + const plugins = ((app as any).plugins?.plugins ?? {}) as Record + if (plugins['scambier.omnisearch']) { new Notice( `OMNISEARCH It looks like you have 2 versions of Omnisearch installed.