Skip to content

Commit 6ecfbfc

Browse files
BobDuChanzhaoyu
andauthored
fix: 修复打字机动画 (cherry picked from ChenZhaoYu upstream) (#544)
(cherry picked from commit c226d07) Signed-off-by: Bob Du <i@bobdu.cc> Co-authored-by: ChenZhaoYu <790348264@qq.com>
1 parent c8b71c8 commit 6ecfbfc

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

src/views/chat/components/Message/Text.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,24 @@ function addCopyEvents() {
8181
})
8282
}
8383
}
84+
8485
function removeCopyEvents() {
8586
if (textRef.value) {
8687
const copyBtn = textRef.value.querySelectorAll('.code-block-header__copy')
8788
copyBtn.forEach((btn) => {
88-
btn.removeEventListener('click', () => { })
89+
btn.removeEventListener('click', () => {})
8990
})
9091
}
9192
}
93+
9294
onMounted(() => {
9395
addCopyEvents()
9496
})
97+
9598
onUpdated(() => {
9699
addCopyEvents()
97100
})
101+
98102
onUnmounted(() => {
99103
removeCopyEvents()
100104
})
@@ -104,9 +108,8 @@ onUnmounted(() => {
104108
<div class="text-black" :class="wrapClass">
105109
<div ref="textRef" class="leading-relaxed break-words">
106110
<div v-if="!inversion" class="flex items-end">
107-
<div v-if="!asRawText" class="w-full markdown-body" v-html="text" />
111+
<div v-if="!asRawText" class="w-full markdown-body" :class="{ 'markdown-body-generate': loading }" v-html="text" />
108112
<div v-else class="w-full whitespace-pre-wrap" v-text="text" />
109-
<span v-if="loading" class="dark:text-white w-[4px] h-[20px] block animate-blink" />
110113
</div>
111114
<div v-else class="whitespace-pre-wrap" v-text="text" />
112115
<img v-for="(v, i) of images" :key="i" :src="`/uploads/${v}`" alt="" width="160px">

src/views/chat/components/Message/style.less

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,60 @@
5757
}
5858
}
5959

60+
61+
&.markdown-body-generate>dd:last-child:after,
62+
&.markdown-body-generate>dl:last-child:after,
63+
&.markdown-body-generate>dt:last-child:after,
64+
&.markdown-body-generate>h1:last-child:after,
65+
&.markdown-body-generate>h2:last-child:after,
66+
&.markdown-body-generate>h3:last-child:after,
67+
&.markdown-body-generate>h4:last-child:after,
68+
&.markdown-body-generate>h5:last-child:after,
69+
&.markdown-body-generate>h6:last-child:after,
70+
&.markdown-body-generate>li:last-child:after,
71+
&.markdown-body-generate>ol:last-child li:last-child:after,
72+
&.markdown-body-generate>p:last-child:after,
73+
&.markdown-body-generate>pre:last-child code:after,
74+
&.markdown-body-generate>td:last-child:after,
75+
&.markdown-body-generate>ul:last-child li:last-child:after {
76+
animation: blink 1s steps(5, start) infinite;
77+
color: #000;
78+
content: '_';
79+
font-weight: 700;
80+
margin-left: 3px;
81+
vertical-align: baseline;
82+
}
83+
84+
@keyframes blink {
85+
to {
86+
visibility: hidden;
87+
}
88+
}
6089
}
6190

6291
html.dark {
6392

93+
.markdown-body {
94+
95+
&.markdown-body-generate>dd:last-child:after,
96+
&.markdown-body-generate>dl:last-child:after,
97+
&.markdown-body-generate>dt:last-child:after,
98+
&.markdown-body-generate>h1:last-child:after,
99+
&.markdown-body-generate>h2:last-child:after,
100+
&.markdown-body-generate>h3:last-child:after,
101+
&.markdown-body-generate>h4:last-child:after,
102+
&.markdown-body-generate>h5:last-child:after,
103+
&.markdown-body-generate>h6:last-child:after,
104+
&.markdown-body-generate>li:last-child:after,
105+
&.markdown-body-generate>ol:last-child li:last-child:after,
106+
&.markdown-body-generate>p:last-child:after,
107+
&.markdown-body-generate>pre:last-child code:after,
108+
&.markdown-body-generate>td:last-child:after,
109+
&.markdown-body-generate>ul:last-child li:last-child:after {
110+
color: #65a665;
111+
}
112+
}
113+
64114
.message-reply {
65115
.whitespace-pre-wrap {
66116
white-space: pre-wrap;
@@ -73,3 +123,13 @@ html.dark {
73123
background-color: #282c34;
74124
}
75125
}
126+
127+
@media screen and (max-width: 533px) {
128+
.markdown-body .code-block-wrapper {
129+
padding: unset;
130+
131+
code {
132+
padding: 24px 16px 16px 16px;
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)