@@ -189,6 +189,19 @@ export default function MultiMarkdownInput(props: Props) {
189
189
path,
190
190
} = useFrameContext ( ) ;
191
191
192
+ // We use refs for shiftEnter and onChange to be absolutely
193
+ // 100% certain that if either of these functions is changed,
194
+ // then the new function is used, even if the components
195
+ // implementing our markdown editor mess up somehow and hang on.
196
+ const onShiftEnterRef = useRef < any > ( onShiftEnter ) ;
197
+ useEffect ( ( ) => {
198
+ onShiftEnterRef . current = onShiftEnter ;
199
+ } , [ onShiftEnter ] ) ;
200
+ const onChangeRef = useRef < any > ( onChange ) ;
201
+ useEffect ( ( ) => {
202
+ onChangeRef . current = onChange ;
203
+ } , [ onChange ] ) ;
204
+
192
205
const editBar2 = useRef < JSX . Element | undefined > ( undefined ) ;
193
206
194
207
function getCache ( ) {
@@ -380,7 +393,9 @@ export default function MultiMarkdownInput(props: Props) {
380
393
divRef = { editorDivRef }
381
394
selectionRef = { selectionRef }
382
395
value = { value }
383
- onChange = { onChange }
396
+ onChange = { ( value ) => {
397
+ onChangeRef . current ?.( value ) ;
398
+ } }
384
399
saveDebounceMs = { saveDebounceMs }
385
400
getValueRef = { getValueRef }
386
401
project_id = { project_id }
@@ -389,7 +404,9 @@ export default function MultiMarkdownInput(props: Props) {
389
404
onUploadStart = { onUploadStart }
390
405
onUploadEnd = { onUploadEnd }
391
406
enableMentions = { enableMentions }
392
- onShiftEnter = { onShiftEnter }
407
+ onShiftEnter = { ( value ) => {
408
+ onShiftEnterRef . current ?.( value ) ;
409
+ } }
393
410
placeholder = { placeholder ?? "Type markdown..." }
394
411
fontSize = { fontSize }
395
412
cmOptions = { cmOptions }
@@ -400,7 +417,7 @@ export default function MultiMarkdownInput(props: Props) {
400
417
extraHelp = { extraHelp }
401
418
hideHelp = { hideHelp }
402
419
onBlur = { ( value ) => {
403
- onChange ?.( value ) ;
420
+ onChangeRef . current ?.( value ) ;
404
421
if ( ! ignoreBlur . current ) {
405
422
onBlur ?.( ) ;
406
423
}
@@ -463,14 +480,14 @@ export default function MultiMarkdownInput(props: Props) {
463
480
getValueRef = { getValueRef }
464
481
actions = { {
465
482
set_value : ( value ) => {
466
- onChange ?.( value ) ;
483
+ onChangeRef . current ?.( value ) ;
467
484
} ,
468
485
shiftEnter : ( value ) => {
469
- onChange ?.( value ) ;
470
- onShiftEnter ?.( value ) ;
486
+ onChangeRef . current ?.( value ) ;
487
+ onShiftEnterRef . current ?.( value ) ;
471
488
} ,
472
489
altEnter : ( value ) => {
473
- onChange ?.( value ) ;
490
+ onChangeRef . current ?.( value ) ;
474
491
setMode ( "markdown" ) ;
475
492
} ,
476
493
set_cursor_locs : onCursors ,
0 commit comments