Skip to content

Commit

Permalink
feat: add autocompletionConfig to markupConfig (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
saxumcordis authored Aug 29, 2024
1 parent a50d8a7 commit ad9ce27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/bundle/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export type MarkupConfig = {
* See more https://codemirror.net/docs/ref/#state.EditorState.languageDataAt
*/
languageData?: YfmLangOptions['languageData'];
/** Config for @codemirror/autocomplete https://codemirror.net/docs/ref/#autocomplete.autocompletion%5Econfig */
autocompletion?: CreateCodemirrorParams['autocompletion'];
};

export type EscapeConfig = {
Expand Down Expand Up @@ -310,6 +312,7 @@ export class EditorImpl extends SafeEventEmitter<EventMapInt> implements EditorI
disabledExtensions: this.#markupConfig.disabledExtensions,
keymaps: this.#markupConfig.keymaps,
yfmLangOptions: {languageData: this.#markupConfig.languageData},
autocompletion: this.#markupConfig.autocompletion,
receiver: this,
}),
);
Expand Down
6 changes: 5 additions & 1 deletion src/markup/codemirror/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {type YfmLangOptions, yfmLang} from './yfm';

export type {YfmLangOptions};

type Autocompletion = Parameters<typeof autocompletion>[0];

export type CreateCodemirrorParams = {
doc: EditorViewConfig['doc'];
placeholderText: string;
Expand All @@ -61,6 +63,7 @@ export type CreateCodemirrorParams = {
keymaps?: readonly KeyBinding[];
receiver?: Receiver<EventMap>;
yfmLangOptions?: YfmLangOptions;
autocompletion?: Autocompletion;
};

export function createCodemirror(params: CreateCodemirrorParams) {
Expand All @@ -78,6 +81,7 @@ export function createCodemirror(params: CreateCodemirrorParams) {
keymaps = [],
receiver,
yfmLangOptions,
autocompletion: autocompletionConfig,
} = params;

const extensions: Extension[] = [gravityTheme, placeholder(placeholderText)];
Expand Down Expand Up @@ -126,7 +130,7 @@ export function createCodemirror(params: CreateCodemirrorParams) {
...(disabledExtensions.history ? [] : historyKeymap),
...keymaps,
]),
autocompletion(),
autocompletion(autocompletionConfig),
yfmLang(yfmLangOptions),
ReactRendererFacet.of(reactRenderer),
PairingCharactersExtension,
Expand Down

0 comments on commit ad9ce27

Please sign in to comment.