@@ -63,11 +63,15 @@ export default function Editor({
6363 } ;
6464
6565 const insertText = useCallback ( ( text : string ) => {
66- const selection = window . getSelection ( ) ;
67- if ( ! selection ?. rangeCount ) return ;
68- selection . deleteFromDocument ( ) ; // å é¤éäøēå
容
69- selection . getRangeAt ( 0 ) . insertNode ( document . createTextNode ( text ) ) ;
70- selection . collapseToEnd ( ) ;
66+ if ( text === '\n' ) {
67+ document . execCommand ( 'insertLineBreak' ) ;
68+ } else {
69+ const selection = window . getSelection ( ) ;
70+ if ( ! selection ?. rangeCount ) return ;
71+ selection . deleteFromDocument ( ) ;
72+ selection . getRangeAt ( 0 ) . insertNode ( document . createTextNode ( text ) ) ;
73+ selection . collapseToEnd ( ) ;
74+ }
7175 } , [ ] ) ;
7276
7377 const onKeyDown = useCallback (
@@ -78,7 +82,8 @@ export default function Editor({
7882 // void submit when shiftKey, ctrlKey or metaKey is pressed.
7983 if ( event . shiftKey || event . ctrlKey || event . metaKey ) {
8084 event . preventDefault ( ) ;
81- insertText ( '\n' ) ;
85+ // even execCommand is deprecated, it seems to be the only way to insert a line break in contentEditable.
86+ document . execCommand ( 'insertLineBreak' ) ;
8287 } else {
8388 event . preventDefault ( ) ;
8489 setSubmitted ( true ) ;
@@ -90,7 +95,7 @@ export default function Editor({
9095 }
9196 }
9297 } ,
93- [ insertText , onSubmit , chat . id , editStage ] ,
98+ [ onSubmit , chat . id , editStage ] ,
9499 ) ;
95100
96101 const pasteWithoutStyle = useCallback ( ( e : ClipboardEvent ) => {
0 commit comments