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