Merge branch 'develop'

This commit is contained in:
Simon Cambier
2023-09-10 09:04:51 +02:00
5 changed files with 98 additions and 29 deletions

29
qodana.yaml Normal file
View File

@@ -0,0 +1,29 @@
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#
version: "1.0"
#Specify inspection profile for code analysis
profile:
name: qodana.starter
#Enable inspections
#include:
# - name: <SomeEnabledInspectionId>
#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
#bootstrap: sh ./prepare-qodana.sh
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
#plugins:
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-js:latest

View File

@@ -35,11 +35,11 @@
onMount(() => { onMount(() => {
eventBus.enable('infile') eventBus.enable('infile')
eventBus.on('infile', 'enter', openSelection) eventBus.on('infile', Action.Enter, openSelection)
eventBus.on('infile', 'open-in-new-pane', openSelectionInNewTab) eventBus.on('infile', Action.OpenInNewPane, openSelectionInNewTab)
eventBus.on('infile', 'arrow-up', () => moveIndex(-1)) eventBus.on('infile', Action.ArrowUp, () => moveIndex(-1))
eventBus.on('infile', 'arrow-down', () => moveIndex(1)) eventBus.on('infile', Action.ArrowDown, () => moveIndex(1))
eventBus.on('infile', 'tab', switchToVaultModal) eventBus.on('infile', Action.Tab, switchToVaultModal)
}) })
onDestroy(() => { onDestroy(() => {

View File

@@ -9,6 +9,7 @@
IndexingStepType, IndexingStepType,
type ResultNote, type ResultNote,
SPACE_OR_PUNCTUATION, SPACE_OR_PUNCTUATION,
Action,
} from 'src/globals' } from 'src/globals'
import { createNote, openNote } from 'src/tools/notes' import { createNote, openNote } from 'src/tools/notes'
import { import {
@@ -90,15 +91,16 @@
onMount(async () => { onMount(async () => {
eventBus.enable('vault') eventBus.enable('vault')
eventBus.on('vault', 'enter', openNoteAndCloseModal) eventBus.on('vault', Action.Enter, openNoteAndCloseModal)
eventBus.on('vault', 'create-note', createNoteAndCloseModal) eventBus.on('vault', Action.OpenInBackground, openNoteInBackground)
eventBus.on('vault', 'open-in-new-pane', openNoteInNewPane) eventBus.on('vault', Action.CreateNote, createNoteAndCloseModal)
eventBus.on('vault', 'insert-link', insertLink) eventBus.on('vault', Action.OpenInNewPane, openNoteInNewPane)
eventBus.on('vault', 'tab', switchToInFileModal) eventBus.on('vault', Action.InsertLink, insertLink)
eventBus.on('vault', 'arrow-up', () => moveIndex(-1)) eventBus.on('vault', Action.Tab, switchToInFileModal)
eventBus.on('vault', 'arrow-down', () => moveIndex(1)) eventBus.on('vault', Action.ArrowUp, () => moveIndex(-1))
eventBus.on('vault', 'prev-search-history', prevSearchHistory) eventBus.on('vault', Action.ArrowDown, () => moveIndex(1))
eventBus.on('vault', 'next-search-history', nextSearchHistory) eventBus.on('vault', Action.PrevSearchHistory, prevSearchHistory)
eventBus.on('vault', Action.NextSearchHistory, nextSearchHistory)
await NotesIndex.refreshIndex() await NotesIndex.refreshIndex()
if (settings.showPreviousQueryResults) { if (settings.showPreviousQueryResults) {
previousQuery = (await cacheManager.getSearchHistory())[0] previousQuery = (await cacheManager.getSearchHistory())[0]
@@ -162,6 +164,11 @@
modal.close() modal.close()
} }
function openNoteInBackground(): void {
if (!selectedNote) return
openSearchResult(selectedNote, true)
}
function openNoteInNewPane(): void { function openNoteInNewPane(): void {
if (!selectedNote) return if (!selectedNote) return
openSearchResult(selectedNote, true) openSearchResult(selectedNote, true)
@@ -324,7 +331,8 @@
<span>to cycle history</span> <span>to cycle history</span>
</div> </div>
<div class="prompt-instruction"> <div class="prompt-instruction">
<span class="prompt-instruction-command">{openInCurrentPaneKey}</span><span>to open</span> <span class="prompt-instruction-command">{openInCurrentPaneKey}</span>
<span>to open</span>
</div> </div>
<div class="prompt-instruction"> <div class="prompt-instruction">
<span class="prompt-instruction-command">tab</span> <span class="prompt-instruction-command">tab</span>
@@ -335,6 +343,12 @@
<span class="prompt-instruction-command">{openInNewPaneKey}</span> <span class="prompt-instruction-command">{openInNewPaneKey}</span>
<span>to open in a new pane</span> <span>to open in a new pane</span>
</div> </div>
<div class="prompt-instruction">
<span class="prompt-instruction-command">alt o</span>
<span>to open in the background</span>
</div>
<div class="prompt-instruction"> <div class="prompt-instruction">
<span class="prompt-instruction-command">{createInCurrentPaneKey}</span> <span class="prompt-instruction-command">{createInCurrentPaneKey}</span>
<span>to create</span> <span>to create</span>
@@ -349,7 +363,7 @@
<span>to insert a link</span> <span>to insert a link</span>
</div> </div>
<div class="prompt-instruction"> <div class="prompt-instruction">
<span class="prompt-instruction-command">ctrl+h</span> <span class="prompt-instruction-command">ctrl h</span>
<span>to toggle excerpts</span> <span>to toggle excerpts</span>
</div> </div>
<div class="prompt-instruction"> <div class="prompt-instruction">

View File

@@ -1,8 +1,8 @@
import { App, Modal, TFile } from 'obsidian' import { App, MarkdownView, Modal, TFile } from 'obsidian'
import type { Modifier } from 'obsidian' import type { Modifier } from 'obsidian'
import ModalVault from './ModalVault.svelte' import ModalVault from './ModalVault.svelte'
import ModalInFile from './ModalInFile.svelte' import ModalInFile from './ModalInFile.svelte'
import { eventBus, EventNames, isInputComposition } from '../globals' import { Action, eventBus, EventNames, isInputComposition } from '../globals'
import { settings } from '../settings' import { settings } from '../settings'
abstract class OmnisearchModal extends Modal { abstract class OmnisearchModal extends Modal {
@@ -24,11 +24,11 @@ abstract class OmnisearchModal extends Modal {
this.scope.register([], 'ArrowDown', e => { this.scope.register([], 'ArrowDown', e => {
e.preventDefault() e.preventDefault()
eventBus.emit('arrow-down') eventBus.emit(Action.ArrowDown)
}) })
this.scope.register([], 'ArrowUp', e => { this.scope.register([], 'ArrowUp', e => {
e.preventDefault() e.preventDefault()
eventBus.emit('arrow-up') eventBus.emit(Action.ArrowUp)
}) })
// Ctrl+j/k // Ctrl+j/k
@@ -82,23 +82,23 @@ abstract class OmnisearchModal extends Modal {
// Open in new pane // Open in new pane
this.scope.register(openInNewPaneKey, 'Enter', e => { this.scope.register(openInNewPaneKey, 'Enter', e => {
e.preventDefault() e.preventDefault()
eventBus.emit('open-in-new-pane') eventBus.emit(Action.OpenInNewPane)
}) })
// Insert link // Insert link
this.scope.register(['Alt'], 'Enter', e => { this.scope.register(['Alt'], 'Enter', e => {
e.preventDefault() e.preventDefault()
eventBus.emit('insert-link') eventBus.emit(Action.InsertLink)
}) })
// Create a new note // Create a new note
this.scope.register(createInCurrentPaneKey, 'Enter', e => { this.scope.register(createInCurrentPaneKey, 'Enter', e => {
e.preventDefault() e.preventDefault()
eventBus.emit('create-note') eventBus.emit(Action.CreateNote)
}) })
this.scope.register(createInNewPaneKey, 'Enter', e => { this.scope.register(createInNewPaneKey, 'Enter', e => {
e.preventDefault() e.preventDefault()
eventBus.emit('create-note', { newLeaf: true }) eventBus.emit(Action.CreateNote, { newLeaf: true })
}) })
// Open in current pane // Open in current pane
@@ -106,23 +106,32 @@ abstract class OmnisearchModal extends Modal {
if (!isInputComposition()) { if (!isInputComposition()) {
// Check if the user is still typing // Check if the user is still typing
e.preventDefault() e.preventDefault()
eventBus.emit('enter') eventBus.emit(Action.Enter)
}
})
// Open in background
this.scope.register(['Alt'], 'O', e => {
if (!isInputComposition()) {
// Check if the user is still typing
e.preventDefault()
eventBus.emit(Action.OpenInBackground)
} }
}) })
this.scope.register([], 'Tab', e => { this.scope.register([], 'Tab', e => {
e.preventDefault() e.preventDefault()
eventBus.emit('tab') // Switch context eventBus.emit(Action.Tab) // Switch context
}) })
// Search history // Search history
this.scope.register(['Alt'], 'ArrowDown', e => { this.scope.register(['Alt'], 'ArrowDown', e => {
e.preventDefault() e.preventDefault()
eventBus.emit('next-search-history') eventBus.emit(Action.NextSearchHistory)
}) })
this.scope.register(['Alt'], 'ArrowUp', e => { this.scope.register(['Alt'], 'ArrowUp', e => {
e.preventDefault() e.preventDefault()
eventBus.emit('prev-search-history') eventBus.emit(Action.PrevSearchHistory)
}) })
// Context // Context
@@ -135,11 +144,15 @@ abstract class OmnisearchModal extends Modal {
export class OmnisearchVaultModal extends OmnisearchModal { export class OmnisearchVaultModal extends OmnisearchModal {
constructor(app: App, query?: string) { constructor(app: App, query?: string) {
super(app) super(app)
// Get selected text
const selection = app.workspace.getActiveViewOfType(MarkdownView)?.editor.getSelection()
const cmp = new ModalVault({ const cmp = new ModalVault({
target: this.modalEl, target: this.modalEl,
props: { props: {
modal: this, modal: this,
previousQuery: query, previousQuery: selection ?? query,
}, },
}) })

View File

@@ -32,6 +32,19 @@ export const enum IndexingStepType {
WritingCache, WritingCache,
} }
export const enum Action {
Enter = 'enter',
OpenInBackground = 'open-in-background',
CreateNote = 'create-note',
OpenInNewPane = 'open-in-new-pane',
InsertLink = 'insert-link',
Tab = 'tab',
ArrowUp = 'arrow-up',
ArrowDown = 'arrow-down',
PrevSearchHistory = 'prev-search-history',
NextSearchHistory = 'next-search-history',
}
export type DocumentRef = { path: string; mtime: number } export type DocumentRef = { path: string; mtime: number }
export type IndexedDocument = { export type IndexedDocument = {