Skip to content

Commit 5c3dbbc

Browse files
committed
fix #8536 -- compositing input support for autoformat
1 parent e4edefd commit 5c3dbbc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/packages/frontend/editors/slate/keyboard/spacebar.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ OS doesn't take. On MacOS that includes option+space for now.
1919
TODO: instead, anytime autoformat happens, there could be an indicator about it in the
2020
toolbar, with a button to undo it (leaving the space). This would be general for
2121
return as well.
22+
23+
IMPORTANT: we also explicitly do this same insertText action in
24+
frontend/editors/slate/slate-react/components/editable.tsx
25+
to handle virtual keyboards. See https://github.com/sagemathinc/cocalc/issues/8536
2226
*/
2327

2428
import { toggleCheckbox } from "../elements/checkbox/editable";

src/packages/frontend/editors/slate/slate-react/components/editable.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ export const Editable: React.FC<EditableProps> = (props: EditableProps) => {
273273
getTargetRanges(): DOMStaticRange[];
274274
inputType: string;
275275
isComposing: boolean;
276+
ctrlKey?: boolean;
277+
altKey?: boolean;
278+
metaKey?: boolean;
276279
},
277280
) => {
278281
if (
@@ -295,6 +298,16 @@ export const Editable: React.FC<EditableProps> = (props: EditableProps) => {
295298

296299
event.preventDefault();
297300

301+
if (
302+
type == "insertText" &&
303+
!event.isComposing &&
304+
event.data == " " &&
305+
!(event.ctrlKey || event.altKey || event.metaKey)
306+
) {
307+
editor.insertText(" ", {});
308+
return;
309+
}
310+
298311
// COMPAT: For the deleting forward/backward input types we don't want
299312
// to change the selection because it is the range that will be deleted,
300313
// and those commands determine that for themselves.
@@ -694,6 +707,7 @@ export const Editable: React.FC<EditableProps> = (props: EditableProps) => {
694707
}
695708
}
696709
}
710+
1;
697711
}
698712
},
699713
[readOnly, attributes.onCut],

0 commit comments

Comments
 (0)