1
1
<script setup lang="ts">
2
- import { useEventListener } from ' @vueuse/core'
3
- import { computed , watch , ref , onMounted , onUnmounted } from ' vue'
2
+ import { useEventListener , throttledWatch } from ' @vueuse/core'
3
+ import { computed , watch , ref , onMounted } from ' vue'
4
4
import { activeElement , showEditor , editorWidth } from ' ../state'
5
5
import { useCodeMirror } from ' ../setup/codemirror'
6
6
import { currentRoute , currentSlideId } from ' ../logic/nav'
7
7
import { useDynamicSlideInfo } from ' ../logic/note'
8
8
9
- const clicks = ref <' content' | ' note' >(' content' )
10
- const offsetRight = ref (0 )
9
+ const tab = ref <' content' | ' note' >(' content' )
11
10
const content = ref (' ' )
12
11
const note = ref (' ' )
13
12
const dirty = ref (false )
@@ -85,20 +84,12 @@ onMounted(() => {
85
84
)
86
85
})
87
86
88
- onMounted (() => {
89
- offsetRight .value = editorWidth .value
90
- })
91
- onUnmounted (() => {
92
- offsetRight .value = 0
93
- })
94
-
95
87
const handlerDown = ref (false )
96
88
function onHandlerDown() {
97
89
handlerDown .value = true
98
90
}
99
91
function updateWidth(v : number ) {
100
92
editorWidth .value = Math .min (Math .max (200 , v ), window .innerWidth - 200 )
101
- offsetRight .value = editorWidth .value
102
93
}
103
94
useEventListener (' pointermove' , (e ) => {
104
95
if (handlerDown .value )
@@ -117,6 +108,15 @@ const editorLink = computed(() => {
117
108
? ` vscode://file/${slide .file }:${slide .start } `
118
109
: undefined
119
110
})
111
+
112
+ throttledWatch (
113
+ [content , note ],
114
+ () => {
115
+ if (dirty .value )
116
+ save ()
117
+ },
118
+ { throttle: 500 },
119
+ )
120
120
</script >
121
121
122
122
<template >
@@ -132,20 +132,20 @@ const editorLink = computed(() => {
132
132
>
133
133
<div class =" flex pb-2 text-xl -mt-1" >
134
134
<div class =" mr-4 rounded flex" >
135
- <button class =" icon-btn" :class =" clicks === 'content' ? 'text-primary' : ''" @click =" clicks ='content'" >
135
+ <button class =" icon-btn" :class =" tab === 'content' ? 'text-primary' : ''" @click =" tab ='content'" >
136
136
<carbon:account />
137
137
</button >
138
- <button class =" icon-btn" :class =" clicks === 'note' ? 'text-primary' : ''" @click =" clicks ='note'" >
138
+ <button class =" icon-btn" :class =" tab === 'note' ? 'text-primary' : ''" @click =" tab ='note'" >
139
139
<carbon:align-box-bottom-right />
140
140
</button >
141
141
</div >
142
142
<span class =" text-2xl pt-1" >
143
- {{ clicks === 'content' ? 'Slide' : 'Note' }}
143
+ {{ tab === 'content' ? 'Slide' : 'Note' }}
144
144
</span >
145
145
<div class =" flex-auto" ></div >
146
- <button class =" icon-btn" :class =" { disabled: !dirty }" @click =" save" >
146
+ <!-- < button class="icon-btn" :class="{ disabled: !dirty }" @click="save">
147
147
<carbon:save />
148
- </button >
148
+ </button> -->
149
149
<button class =" icon-btn" >
150
150
<a :href =" editorLink" target =" _blank" >
151
151
<carbon:launch />
@@ -156,10 +156,10 @@ const editorLink = computed(() => {
156
156
</button >
157
157
</div >
158
158
<div class =" h-full overflow-auto" >
159
- <div v-show =" clicks === 'content'" class =" h-full overflow-auto" >
159
+ <div v-show =" tab === 'content'" class =" h-full overflow-auto" >
160
160
<textarea ref =" contentInput" />
161
161
</div >
162
- <div v-show =" clicks === 'note'" class =" h-full overflow-auto" >
162
+ <div v-show =" tab === 'note'" class =" h-full overflow-auto" >
163
163
<textarea ref =" noteInput" />
164
164
</div >
165
165
</div >
0 commit comments