Path: blob/master/src/packages/frontend/editors/slate/keyboard/spacebar.ts
1697 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6What happens when you hit the space bar.78We also make shift+space do autoformat for the following reason:9"We also **allow** shift+space for autoformat, since it is easy to accidentally10type! E.g., trying typing "> " quickly a few times on a US keyboard, and you'll11find that > is shift+., and you often don't lift off the shift before hitting space."12and to implement it include { key: " ", shift: true } in the list below.13However, I think overall it's more valuable to allow shift+space to insert a space14without autoformat, since there must be an easy way to do this.1516To insert a space without formatting, use some other modifier that your browser or17OS doesn't take. On MacOS that includes option+space for now.18TODO: instead, anytime autoformat happens, there could be an indicator about it in the19toolbar, with a button to undo it (leaving the space). This would be general for20return as well.2122IMPORTANT: we also explicitly do this same insertText action in23frontend/editors/slate/slate-react/components/editable.tsx24to handle virtual keyboards. See https://github.com/sagemathinc/cocalc/issues/853625*/2627import { toggleCheckbox } from "../elements/checkbox/editable";28import { register } from "./register";2930register([{ key: " " }, { key: " ", shift: true }], ({ editor }) => {31if (toggleCheckbox(editor)) {32return true;33}3435// @ts-ignore - that second argument below is "unsanctioned"; it controls36// whether autoformat should happen.37editor.insertText(" ", true);38return true;39});404142