Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/slate/format/insert-special-char.ts
1698 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Transforms } from "slate";
7
import {
8
get_insert_special_char_from_user,
9
Options,
10
} from "@cocalc/frontend/codemirror/extensions/insert-special-char";
11
import { alert_message } from "@cocalc/frontend/alerts";
12
import { getFocus } from "./commands";
13
14
export async function insertSpecialChar(editor): Promise<void> {
15
let opts: Options | undefined = undefined;
16
try {
17
opts = await get_insert_special_char_from_user();
18
} catch (err) {
19
alert_message({ type: "error", message: err.errorFields[0]?.errors });
20
return;
21
}
22
if (opts == null) return; // user canceled.
23
// We insert at what is likely the focus, rather than trying to
24
// focus, since focusing is erratic (especially with firefox).
25
Transforms.insertText(editor, opts.char, { at: getFocus(editor) });
26
}
27
28