File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ const emit = defineEmits<(e: 'change', value: string) => void>()
2424
2525const el = ref ()
2626const needAutoResize = inject (' autoresize' )
27+ const autoSave = inject (' autosave' )
2728
2829onMounted (() => {
2930 const addonOptions = props .readonly
@@ -46,10 +47,6 @@ onMounted(() => {
4647 ... addonOptions ,
4748 })
4849
49- editor .on (' change' , () => {
50- emit (' change' , editor .getValue ())
51- })
52-
5350 watchEffect (() => {
5451 const cur = editor .getValue ()
5552 if (props .value !== cur ) {
@@ -73,6 +70,19 @@ onMounted(() => {
7370 }),
7471 )
7572 }
73+
74+ if (autoSave ) {
75+ editor .on (' change' , () => {
76+ emit (' change' , editor .getValue ())
77+ })
78+ } else {
79+ el .value ! .addEventListener (' keydown' , (e : KeyboardEvent ) => {
80+ if (e .ctrlKey && e .key === ' s' ) {
81+ e .preventDefault ()
82+ emit (' change' , editor .getValue ())
83+ }
84+ })
85+ }
7686})
7787 </script >
7888
You can’t perform that action at this time.
0 commit comments