Skip to content

Commit 0c1e2bf

Browse files
authored
fix: side editor styles and interacation (#1710)
1 parent 8b4018b commit 0c1e2bf

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

packages/client/internals/ShikiEditor.vue

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ref, watchEffect } from 'vue'
2+
import { ref, shallowRef } from 'vue'
33
import { getHighlighter } from '#slidev/shiki'
44
55
const props = defineProps<{
@@ -9,30 +9,14 @@ const content = defineModel<string>({ required: true })
99
1010
const textareaEl = ref<HTMLTextAreaElement | null>(null)
1111
12-
const html = ref('')
13-
14-
watchEffect((onCleanup) => {
15-
let canceled = false
16-
onCleanup(() => canceled = true)
17-
18-
const c = content.value
19-
async function updateHtml() {
20-
const highlight = await getHighlighter()
21-
if (canceled)
22-
return
23-
const h = await highlight(c, 'markdown')
24-
if (canceled)
25-
return
26-
html.value = h
27-
}
28-
updateHtml()
29-
})
12+
const highlight = shallowRef<Awaited<ReturnType<typeof getHighlighter>> | null>(null)
13+
getHighlighter().then(h => highlight.value = h)
3014
</script>
3115

3216
<template>
33-
<div class="absolute inset-x-3 inset-y-2 font-mono overflow-x-hidden overflow-y-auto">
34-
<div class="relative w-full h-max">
35-
<div class="relative w-full h-max" v-html="html" />
17+
<div class="absolute left-3 right-0 inset-y-2 font-mono overflow-x-hidden overflow-y-auto cursor-text">
18+
<div v-if="highlight" class="relative w-full h-max min-h-full">
19+
<div class="relative w-full h-max" v-html="`${highlight(content, 'markdown')}&nbsp;`" />
3620
<textarea
3721
ref="textareaEl" v-model="content" :placeholder="props.placeholder"
3822
class="absolute inset-0 resize-none text-transparent bg-transparent focus:outline-none caret-black dark:caret-white overflow-y-hidden"

packages/client/internals/SideEditor.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ useEventListener('keydown', (e) => {
5858
const contentRef = computed({
5959
get() { return content.value },
6060
set(v) {
61-
if (content.value.trim() !== v.trim()) {
62-
content.value = v
61+
if (content.value.trim() !== v.trim())
6362
dirty.value = true
64-
}
63+
content.value = v
6564
},
6665
})
6766
@@ -126,7 +125,7 @@ throttledWatch(
126125
}" @pointerdown="onHandlerDown"
127126
/>
128127
<div
129-
class="shadow bg-main p-4 grid grid-rows-[max-content_1fr] h-full overflow-hidden"
128+
class="shadow bg-main p-2 pt-4 grid grid-rows-[max-content_1fr] h-full overflow-hidden"
130129
:class="resize ? 'border-l border-gray-400 border-opacity-20' : ''"
131130
:style="resize ? {
132131
height: vertical ? `${editorHeight}px` : undefined,

0 commit comments

Comments
 (0)