Skip to content

Commit 089bd64

Browse files
saxumcordissaxumcordismakhnatkin
authored
feat(markup): support codemirror tooltips config (#923)
Co-authored-by: saxumcordis <saxumcordis@yandex-team.ru> Co-authored-by: Sergey Makhnatkin <makhnatkin@yandex-team.ru>
1 parent fdf0867 commit 089bd64

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/bundle/Editor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ export class EditorImpl extends SafeEventEmitter<EventMapInt> implements EditorI
307307
}).concat(this.#markupConfig?.languageData || []),
308308
},
309309
autocompletion: this.#markupConfig.autocompletion,
310+
tooltips: this.#markupConfig.tooltips,
310311
directiveSyntax: this.directiveSyntax,
311312
receiver: this,
312313
searchPanel: this.#markupConfig.searchPanel,

src/bundle/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ export type MarkdownEditorMarkupConfig = {
157157
languageData?: YfmLangOptions['languageData'];
158158
/** Config for @codemirror/autocomplete https://codemirror.net/docs/ref/#autocomplete.autocompletion%5Econfig */
159159
autocompletion?: CreateCodemirrorParams['autocompletion'];
160+
/** Config for tooltips https://codemirror.net/docs/ref/#view.tooltips */
161+
tooltips?: CreateCodemirrorParams['tooltips'];
160162
/**
161163
* The function, used to determine if the pasted text is the image url and should be inserted as an image
162164
*/

src/markup/codemirror/create.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type KeyBinding,
1616
keymap,
1717
placeholder,
18+
tooltips,
1819
} from '@codemirror/view';
1920

2021
import {InputState} from 'src/utils/input-state';
@@ -62,6 +63,7 @@ import {type YfmLangOptions, yfmLang} from './yfm';
6263
export type {YfmLangOptions};
6364

6465
type Autocompletion = Parameters<typeof autocompletion>[0];
66+
type Tooltips = Parameters<typeof tooltips>[0];
6567

6668
const linkRegex = /\[[\s\S]*?]\([\s\S]*?\)/g;
6769

@@ -88,6 +90,7 @@ export type CreateCodemirrorParams = {
8890
receiver?: Receiver<EventMap>;
8991
yfmLangOptions?: YfmLangOptions;
9092
autocompletion?: Autocompletion;
93+
tooltips?: Tooltips;
9194
directiveSyntax: DirectiveSyntaxContext;
9295
preserveEmptyRows: boolean;
9396
searchPanel?: boolean;
@@ -110,6 +113,7 @@ export function createCodemirror(params: CreateCodemirrorParams) {
110113
extensions: extraExtensions,
111114
placeholder: placeholderContent,
112115
autocompletion: autocompletionConfig,
116+
tooltips: tooltipsConfig,
113117
parseHtmlOnPaste,
114118
parseInsertedUrlAsImage,
115119
directiveSyntax,
@@ -317,6 +321,10 @@ export function createCodemirror(params: CreateCodemirrorParams) {
317321
);
318322
}
319323

324+
if (tooltipsConfig) {
325+
extensions.push(tooltips(tooltipsConfig));
326+
}
327+
320328
if (extraExtensions) {
321329
extensions.push(...extraExtensions);
322330
}

0 commit comments

Comments
 (0)