mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
enhancement(autocomplete): add generic code suggestion entry
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
5ccc9059f0
commit
685488c7a2
1 changed files with 12 additions and 4 deletions
|
@ -10,6 +10,7 @@ import { AppExtension } from '../../_base-classes/app-extension'
|
|||
import { HighlightedCodeMarkdownExtension } from './highlighted-code-markdown-extension'
|
||||
import type { CompletionContext, CompletionResult, CompletionSource } from '@codemirror/autocomplete'
|
||||
import { languages } from '@codemirror/language-data'
|
||||
import { t } from 'i18next'
|
||||
|
||||
/**
|
||||
* Adds code highlighting to the markdown rendering.
|
||||
|
@ -29,6 +30,16 @@ export class HighlightedCodeFenceAppExtension extends AppExtension {
|
|||
}
|
||||
|
||||
buildAutocompletion(): CompletionSource[] {
|
||||
const completions = [
|
||||
{
|
||||
detail: t('editor.editorToolbar.code'),
|
||||
label: '```\n\n```'
|
||||
},
|
||||
...languages.map((lang) => ({
|
||||
detail: lang.name,
|
||||
label: '```' + lang.alias[0] + '\n\n```'
|
||||
}))
|
||||
]
|
||||
return [
|
||||
(context: CompletionContext): CompletionResult | null => {
|
||||
const match = context.matchBefore(codeFenceRegex)
|
||||
|
@ -37,10 +48,7 @@ export class HighlightedCodeFenceAppExtension extends AppExtension {
|
|||
}
|
||||
return {
|
||||
from: match.from,
|
||||
options: languages.map((lang) => ({
|
||||
detail: lang.name,
|
||||
label: '```' + lang.alias[0] + '\n\n```'
|
||||
}))
|
||||
options: completions
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue