mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-16 16:14:43 -04:00
![renovate[bot]](/assets/img/avatar_default.png)
* Update dependency eslint-plugin-import to v2.25.2 Signed-off-by: Renovate Bot <bot@renovateapp.com> Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de> * Make type imports more explicit Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de> * Enforce use of type imports Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de> Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import type { Editor, Hint, Hints } from 'codemirror'
|
|
import { Pos } from 'codemirror'
|
|
import type { Hinter } from './index'
|
|
import { findWordAtCursor } 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
|
|
}
|