@@ -25,11 +25,11 @@ import type {
25
25
DocumentState ,
26
26
InsertType ,
27
27
JSONParser ,
28
+ JSONSelection ,
28
29
OnChange ,
29
30
OnChangeText ,
30
- OnPatch ,
31
31
OnJSONSelect ,
32
- JSONSelection
32
+ OnPatch
33
33
} from '$lib/types'
34
34
import { createDebug } from '$lib/utils/debug.js'
35
35
import {
@@ -562,8 +562,8 @@ export function onInsert({
562
562
563
563
if ( operation ) {
564
564
if ( newValue === '' ) {
565
- // open the newly inserted value in edit mode
566
- tick2 ( ( ) => insertActiveElementContents ( refJsonEditor , '' , true ) )
565
+ // open the newly inserted value in edit mode (can be cancelled via ESC this way)
566
+ tick2 ( ( ) => insertActiveElementContents ( refJsonEditor , '' , true , refreshEditableDiv ) )
567
567
}
568
568
}
569
569
} else {
@@ -620,7 +620,10 @@ export async function onInsertCharacter({
620
620
const replaceContents = ! selection . edit
621
621
622
622
onSelect ( { ...selection , edit : true } )
623
- tick2 ( ( ) => insertActiveElementContents ( refJsonEditor , char , replaceContents ) )
623
+ tick2 ( ( ) =>
624
+ // We use this way via insertActiveElementContents, so we can cancel via ESC
625
+ insertActiveElementContents ( refJsonEditor , char , replaceContents , refreshEditableDiv )
626
+ )
624
627
return
625
628
}
626
629
@@ -656,7 +659,10 @@ export async function onInsertCharacter({
656
659
const replaceContents = ! selection . edit
657
660
658
661
onSelect ( { ...selection , edit : true } )
659
- tick2 ( ( ) => insertActiveElementContents ( refJsonEditor , char , replaceContents ) )
662
+ tick2 ( ( ) =>
663
+ // We use this way via insertActiveElementContents, so we can cancel via ESC
664
+ insertActiveElementContents ( refJsonEditor , char , replaceContents , refreshEditableDiv )
665
+ )
660
666
} else {
661
667
// TODO: replace the object/array with editing a text in edit mode?
662
668
// (Ideally this this should not create an entry in history though,
@@ -721,7 +727,7 @@ async function onInsertValueWithCharacter({
721
727
// multiple characters very quickly after each other due to the async handling)
722
728
const replaceContents = ! isEditingSelection ( selection )
723
729
724
- tick2 ( ( ) => insertActiveElementContents ( refJsonEditor , char , replaceContents ) )
730
+ tick2 ( ( ) => insertActiveElementContents ( refJsonEditor , char , replaceContents , refreshEditableDiv ) )
725
731
}
726
732
727
733
/**
@@ -732,3 +738,13 @@ async function onInsertValueWithCharacter({
732
738
function tick2 ( callback : ( ) => void ) {
733
739
setTimeout ( ( ) => setTimeout ( callback ) )
734
740
}
741
+
742
+ function refreshEditableDiv ( element : HTMLElement ) {
743
+ // We force a refresh because when changing the text of the editable div programmatically,
744
+ // the DIV doesn't get a trigger to update it's class
745
+ // TODO: come up with a better solution
746
+
747
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
748
+ // @ts -ignore
749
+ element ?. refresh ( )
750
+ }
0 commit comments