wip suggestions
This commit is contained in:
38
src/suggestions.ts
Normal file
38
src/suggestions.ts
Normal 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.')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user