Skip to content

Commit 28df48b

Browse files
committed
fix: improve integrated editor
1 parent a3d2df1 commit 28df48b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

packages/client/internals/Editor.vue

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ const dirty = ref(false)
1313
const frontmatter = ref<any>({})
1414
const contentInput = ref<HTMLTextAreaElement>()
1515
const noteInput = ref<HTMLTextAreaElement>()
16+
const focused = ref(false)
1617
1718
const { info, update } = useDynamicSlideInfo(currentSlideId)
1819
1920
watch(
2021
info,
2122
(v) => {
22-
content.value = (v?.content || '').trim()
2323
note.value = (v?.note || '').trim()
2424
frontmatter.value = v?.frontmatter || {}
25-
dirty.value = false
25+
26+
if (!focused.value) {
27+
content.value = (v?.content || '').trim()
28+
dirty.value = false
29+
}
2630
},
2731
{ immediate: true },
2832
)
@@ -54,15 +58,23 @@ onMounted(() => {
5458
computed({
5559
get() { return content.value },
5660
set(v) {
57-
content.value = v
58-
dirty.value = true
61+
if (content.value.trim() !== v.trim()) {
62+
content.value = v
63+
dirty.value = true
64+
}
5965
},
6066
}),
6167
{
6268
mode: 'markdown',
6369
lineWrapping: true,
6470
highlightFormatting: true,
6571
fencedCodeBlockDefaultMode: 'javascript',
72+
onfocus() {
73+
focused.value = true
74+
},
75+
onblur() {
76+
focused.value = false
77+
},
6678
},
6779
)
6880
@@ -80,6 +92,12 @@ onMounted(() => {
8092
lineWrapping: true,
8193
highlightFormatting: true,
8294
fencedCodeBlockDefaultMode: 'javascript',
95+
onfocus() {
96+
focused.value = true
97+
},
98+
onblur() {
99+
focused.value = false
100+
},
83101
},
84102
)
85103
})

packages/client/state/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMagicKeys, useActiveElement, useStorage, useUrlSearchParams, useBreakpoints, breakpointsTailwind, useWindowSize, useFullscreen, useToggle, isClient } from '@vueuse/core'
2-
import { computed, ref } from 'vue'
2+
import { computed, ref, watch } from 'vue'
33

44
export const showOverview = ref(false)
55
export const showRecordingDialog = ref(false)
@@ -15,7 +15,7 @@ export const isScreenVertical = computed(() => windowSize.width.value <= windowS
1515
export const fullscreen = useFullscreen(isClient ? document.body : null)
1616

1717
export const activeElement = useActiveElement()
18-
export const isInputing = computed(() => ['INPUT', 'TEXTAREA'].includes(activeElement.value?.tagName || ''))
18+
export const isInputing = computed(() => ['INPUT', 'TEXTAREA'].includes(activeElement.value?.tagName || '') || activeElement.value?.classList.contains('CodeMirror-code'))
1919

2020
export const currentCamera = useStorage<string>('slidev-camera', 'default')
2121
export const currentMic = useStorage<string>('slidev-mic', 'default')
@@ -27,3 +27,5 @@ export const editorWidth = useStorage('slidev-editor-width', isClient ? window.i
2727
export const isPrintMode = computed(() => query.print != null)
2828

2929
export const toggleOverview = useToggle(showOverview)
30+
31+
watch(activeElement, () => console.log(activeElement.value))

0 commit comments

Comments
 (0)