wip suggestions

This commit is contained in:
Simon Cambier
2022-05-06 22:00:07 +02:00
parent 5eb75363bd
commit 9a80e71235
2 changed files with 40 additions and 0 deletions

38
src/suggestions.ts Normal file
View File

@@ -0,0 +1,38 @@
import {
Editor,
EditorSuggest,
TFile,
type EditorPosition,
type EditorSuggestContext,
type EditorSuggestTriggerInfo,
} from 'obsidian'
export class OmnisearchSuggest extends EditorSuggest<string> {
onTrigger(
cursor: EditorPosition,
editor: Editor,
file: TFile,
): EditorSuggestTriggerInfo | null {
const last2Chars = editor.getLine(cursor.line).slice(-2, cursor.ch)
if (last2Chars === '@@') {
return {
start: cursor,
end: cursor,
query: 'foo',
}
}
return null
}
getSuggestions(context: EditorSuggestContext): string[] | Promise<string[]> {
return ['foo', 'bar']
}
renderSuggestion(value: string, el: HTMLElement): void {
el.createSpan({ text: value })
}
selectSuggestion(value: string, evt: MouseEvent | KeyboardEvent): void {
throw new Error('Method not implemented.')
}
}