mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-03 00:19:57 -04:00
38 lines
1,015 B
TypeScript
38 lines
1,015 B
TypeScript
import { Editor, Hint, Hints, Pos } from 'codemirror'
|
|
import { findWordAtCursor, Hinter } from './index'
|
|
|
|
const wordRegExp = /^(!(\[.*])?)$/
|
|
const allSupportedImages = [
|
|
'',
|
|
'',
|
|
'![image alt][reference]'
|
|
]
|
|
|
|
const imageHint = (editor: Editor): Promise< Hints| null > => {
|
|
return new Promise((resolve) => {
|
|
const searchTerm = findWordAtCursor(editor)
|
|
const searchResult = wordRegExp.exec(searchTerm.text)
|
|
if (searchResult === null) {
|
|
resolve(null)
|
|
return
|
|
}
|
|
const suggestions = allSupportedImages
|
|
const cursor = editor.getCursor()
|
|
if (!suggestions) {
|
|
resolve(null)
|
|
} else {
|
|
resolve({
|
|
list: suggestions.map((suggestion: string): Hint => ({
|
|
text: suggestion
|
|
})),
|
|
from: Pos(cursor.line, searchTerm.start),
|
|
to: Pos(cursor.line, searchTerm.end + 1)
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
export const ImageHinter: Hinter = {
|
|
wordRegExp,
|
|
hint: imageHint
|
|
}
|