From 4bf55749bbb117ac128181e6722193b0289602c1 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Mon, 17 Nov 2025 00:04:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=81=BF=E5=85=8D=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=9A=84=E6=B6=88=E6=81=AF=E7=B1=BB=E5=9E=8B=E4=B9=8B=E9=97=B4?= =?UTF-8?q?=E7=9A=84=E6=8D=A2=E8=A1=8C=E7=AC=A6=E5=AF=BC=E8=87=B4=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ui/custom-elements/chat-text.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/client/ui/custom-elements/chat-text.ts b/client/ui/custom-elements/chat-text.ts index 7aeda96..37a2446 100644 --- a/client/ui/custom-elements/chat-text.ts +++ b/client/ui/custom-elements/chat-text.ts @@ -10,7 +10,7 @@ customElements.define('chat-text', class extends HTMLElement { } connectedCallback() { const shadow = this.shadowRoot as ShadowRoot - + this.span = document.createElement('span') this.span.style.whiteSpace = 'pre-wrap' this.span.style.fontSynthesis = 'style weight' @@ -23,8 +23,17 @@ customElements.define('chat-text', class extends HTMLElement { } update() { if (this.span == null) return - - this.span.textContent = this.textContent + + const isFirstElementInParent = this.parentElement?.firstElementChild == this + const isLastElementInParent = this.parentElement?.lastElementChild == this + + // 避免不同的消息类型之间的换行符导致显示异常 + if (isFirstElementInParent) + this.span.textContent = this.textContent.trimStart() + else if (isLastElementInParent) + this.span.textContent = this.textContent.trimEnd() + else + this.span.textContent = this.textContent this.span.style.textDecoration = $(this).attr('underline') ? 'underline' : '' this.span.style.fontStyle = $(this).attr('em') ? 'italic' : '' }