File tree 1 file changed +14
-4
lines changed
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>()
24
24
25
25
const el = ref ()
26
26
const needAutoResize = inject (' autoresize' )
27
+ const autoSave = inject (' autosave' )
27
28
28
29
onMounted (() => {
29
30
const addonOptions = props .readonly
@@ -46,10 +47,6 @@ onMounted(() => {
46
47
... addonOptions ,
47
48
})
48
49
49
- editor .on (' change' , () => {
50
- emit (' change' , editor .getValue ())
51
- })
52
-
53
50
watchEffect (() => {
54
51
const cur = editor .getValue ()
55
52
if (props .value !== cur ) {
@@ -73,6 +70,19 @@ onMounted(() => {
73
70
}),
74
71
)
75
72
}
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
+ }
76
86
})
77
87
</script >
78
88
You can’t perform that action at this time.
0 commit comments