fix overflow of conversation name

thanks @sipc
This commit is contained in:
Zhang Minghan 2023-10-01 06:19:58 +08:00
parent cba79caee3
commit 5e5d357456
5 changed files with 17 additions and 2 deletions

View File

@ -11,6 +11,7 @@
.conversation-name {
color: hsl(var(--text));
font-weight: bold !important;
word-wrap: anywhere;
}
.web {

View File

@ -32,6 +32,7 @@ import {
import React, { useEffect, useRef, useState } from "react";
import {
filterMessage,
extractMessage,
formatMessage,
mobile,
useAnimation,
@ -170,7 +171,7 @@ function SideBar() {
<AlertDialogDescription>
{t("conversation.remove-description")}
<strong className={`conversation-name`}>
{filterMessage(removeConversation?.name || "")}
{ extractMessage(filterMessage(removeConversation?.name || "")) }
</strong>
{t("end")}
</AlertDialogDescription>

View File

@ -161,6 +161,10 @@ export function filterMessage(message: string): string {
return message.replace(/```file\n\[\[.*]]\n[\s\S]*?\n```\n\n/g, "");
}
export function extractMessage(message: string, length: number = 50, flow: string = "...") {
return message.length > length ? message.slice(0, length) + flow : message;
}
export function useDraggableInput(
t: any,
toast: any,

View File

@ -196,7 +196,7 @@ func (c *Conversation) HandleMessage(db *sql.DB, form *FormMessage) bool {
return false
}
if head {
c.SetName(db, form.Message)
c.SetName(db, utils.Extract(form.Message, 50, "..."))
}
c.SaveConversation(db)
return true

View File

@ -98,3 +98,12 @@ func SplitItem(data string, sep string) []string {
}
return result
}
func Extract(data string, length int, flow string) string {
value := []rune(data)
if len(value) > length {
return string(value[:length]) + flow
} else {
return data
}
}