Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(conversation): animate only the last markdown block + drop clearMessages hotkey (#14906)

Arvin Xu469a8e666130
diff --git a/docs/usage/user-interface/shortcuts.mdx b/docs/usage/user-interface/shortcuts.mdx
index 8be5387b930..b355fc93621 100644
--- a/docs/usage/user-interface/shortcuts.mdx
+++ b/docs/usage/user-interface/shortcuts.mdx
@@ -37,16 +37,15 @@ Click your user avatar in the top-right corner → **App Settings** → **Shortc
## Conversation Shortcuts
-| Action | Shortcut |
-| ------------------------------- | ---------------------------------------------------- |
-| **Open conversation settings** | `⌘ + ,` / `Ctrl + ,` |
-| **Regenerate message** | `⌘ + R` / `Ctrl + R` |
-| **Delete last message** | `⌘ + D` / `Ctrl + D` |
-| **Delete and regenerate** | `⌘ + Shift + R` / `Ctrl + Shift + R` |
-| **New Topic** | `⌘ + N` / `Ctrl + N` |
-| **Add message without sending** | `⌘ + Enter` / `Ctrl + Enter` |
-| **Edit message** | `Ctrl + Alt` + double-click message |
-| **Clear all messages** | `⌘ + Shift + Backspace` / `Ctrl + Shift + Backspace` |
+| Action | Shortcut |
+| ------------------------------- | ------------------------------------ |
+| **Open conversation settings** | `⌘ + ,` / `Ctrl + ,` |
+| **Regenerate message** | `⌘ + R` / `Ctrl + R` |
+| **Delete last message** | `⌘ + D` / `Ctrl + D` |
+| **Delete and regenerate** | `⌘ + Shift + R` / `Ctrl + Shift + R` |
+| **New Topic** | `⌘ + N` / `Ctrl + N` |
+| **Add message without sending** | `⌘ + Enter` / `Ctrl + Enter` |
+| **Edit message** | `Ctrl + Alt` + double-click message |
**Add message without sending** — useful when you want to add context to the conversation without triggering an immediate response. The Agent will see the new message when it next replies.
diff --git a/docs/usage/user-interface/shortcuts.zh-CN.mdx b/docs/usage/user-interface/shortcuts.zh-CN.mdx
index 9b00aa2c07d..934c50e921e 100644
--- a/docs/usage/user-interface/shortcuts.zh-CN.mdx
+++ b/docs/usage/user-interface/shortcuts.zh-CN.mdx
@@ -35,16 +35,15 @@ LobeHub 提供丰富的键盘快捷键,让你少用鼠标、多用手感。掌
## 会话快捷键
-| 操作 | 快捷键 |
-| ------------ | ---------------------------------------------------- |
-| **打开会话设置** | `⌘ + ,` / `Ctrl + ,` |
-| **重新生成消息** | `⌘ + R` / `Ctrl + R` |
-| **删除最后一条消息** | `⌘ + D` / `Ctrl + D` |
-| **删除并重新生成** | `⌘ + Shift + R` / `Ctrl + Shift + R` |
-| **新建话题** | `⌘ + N` / `Ctrl + N` |
-| **添加消息但不发送** | `⌘ + Enter` / `Ctrl + Enter` |
-| **编辑消息** | `Ctrl + Alt` + 双击消息 |
-| **清空所有消息** | `⌘ + Shift + Backspace` / `Ctrl + Shift + Backspace` |
+| 操作 | 快捷键 |
+| ------------ | ------------------------------------ |
+| **打开会话设置** | `⌘ + ,` / `Ctrl + ,` |
+| **重新生成消息** | `⌘ + R` / `Ctrl + R` |
+| **删除最后一条消息** | `⌘ + D` / `Ctrl + D` |
+| **删除并重新生成** | `⌘ + Shift + R` / `Ctrl + Shift + R` |
+| **新建话题** | `⌘ + N` / `Ctrl + N` |
+| **添加消息但不发送** | `⌘ + Enter` / `Ctrl + Enter` |
+| **编辑消息** | `Ctrl + Alt` + 双击消息 |
**添加消息但不发送** —— 想在不触发生成的情况下补充上下文时使用。助理会在下次回复时看到这条新消息。
diff --git a/packages/const/src/hotkeys.ts b/packages/const/src/hotkeys.ts
index cf9542331df..bfa8d659ead 100644
--- a/packages/const/src/hotkeys.ts
+++ b/packages/const/src/hotkeys.ts
@@ -41,7 +41,6 @@ export const KeyEnum = {
export const HotkeyEnum = {
AddUserMessage: 'addUserMessage',
- ClearCurrentMessages: 'clearCurrentMessages',
CommandPalette: 'commandPalette',
DeleteAndRegenerateMessage: 'deleteAndRegenerateMessage',
DeleteLastMessage: 'deleteLastMessage',
@@ -168,12 +167,6 @@ export const HOTKEYS_REGISTRATION: HotkeyRegistration = [
nonEditable: true,
scopes: [HotkeyScopeEnum.Chat],
},
- {
- group: HotkeyGroupEnum.Conversation,
- id: HotkeyEnum.ClearCurrentMessages,
- keys: combineKeys([KeyEnum.Alt, KeyEnum.Shift, KeyEnum.Backspace]),
- scopes: [HotkeyScopeEnum.Chat],
- },
{
group: HotkeyGroupEnum.Essential,
id: HotkeyEnum.SaveDocument,
diff --git a/packages/types/src/hotkey.ts b/packages/types/src/hotkey.ts
index 3d312432b0c..7fcbf5fe6f4 100644
--- a/packages/types/src/hotkey.ts
+++ b/packages/types/src/hotkey.ts
@@ -1,6 +1,5 @@
export type HotkeyId =
| 'addUserMessage'
- | 'clearCurrentMessages'
| 'commandPalette'
| 'deleteAndRegenerateMessage'
| 'deleteLastMessage'
diff --git a/src/features/ChatInput/ActionBar/Clear/index.tsx b/src/features/ChatInput/ActionBar/Clear/index.tsx
index 92d66496759..1f120012c09 100644
--- a/src/features/ChatInput/ActionBar/Clear/index.tsx
+++ b/src/features/ChatInput/ActionBar/Clear/index.tsx
@@ -1,4 +1,3 @@
-import { HotkeyEnum } from '@lobechat/const/hotkeys';
import { Popconfirm } from 'antd';
import { Eraser } from 'lucide-react';
import { memo, useCallback, useState } from 'react';
@@ -7,8 +6,6 @@ import { useTranslation } from 'react-i18next';
import { useIsMobile } from '@/hooks/useIsMobile';
import { useChatStore } from '@/store/chat';
import { useFileStore } from '@/store/file';
-import { useUserStore } from '@/store/user';
-import { settingsSelectors } from '@/store/user/selectors';
import Action from '../components/Action';
@@ -24,7 +21,6 @@ export const useClearCurrentMessages = () => {
const Clear = memo(() => {
const { t } = useTranslation('setting');
- const hotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.ClearCurrentMessages));
const clearCurrentMessages = useClearCurrentMessages();
const [confirmOpened, updateConfirmOpened] = useState(false);
@@ -52,7 +48,6 @@ const Clear = memo(() => {
icon={Eraser}
title={actionTitle}
tooltipProps={{
- hotkey,
placement: 'bottom',
styles: {
root: { maxWidth: 'none' },
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/Group.test.tsx b/src/features/Conversation/Messages/AssistantGroup/components/Group.test.tsx
index 1ca2074a8ec..62802216502 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/Group.test.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/components/Group.test.tsx
@@ -163,7 +163,7 @@ describe('Group', () => {
{
content: longContent,
contentOverride: longContent,
- disableMarkdownStreaming: true,
+ disableMarkdownStreaming: false,
domId: 'block-1__answer',
hasError: false,
hasToolsOverride: false,
@@ -174,7 +174,7 @@ describe('Group', () => {
{
content: '',
contentOverride: '',
- disableMarkdownStreaming: true,
+ disableMarkdownStreaming: false,
domId: 'block-1__workflow',
hasError: false,
hasToolsOverride: true,
@@ -204,7 +204,7 @@ describe('Group', () => {
expect(parseAnswerSegments()).toEqual([
{
content: '现在我来搜索资料。',
- disableMarkdownStreaming: true,
+ disableMarkdownStreaming: false,
domId: undefined,
hasError: false,
id: 'block-1',
@@ -302,7 +302,7 @@ describe('Group', () => {
{
content: '',
contentOverride: '',
- disableMarkdownStreaming: true,
+ disableMarkdownStreaming: false,
domId: 'block-1__workflow',
hasError: false,
hasToolsOverride: true,
@@ -312,7 +312,7 @@ describe('Group', () => {
expect(parseAnswerSegment()).toEqual({
content: '',
contentOverride: '',
- disableMarkdownStreaming: true,
+ disableMarkdownStreaming: false,
domId: 'block-1__answer',
hasError: true,
hasToolsOverride: false,
@@ -341,7 +341,7 @@ describe('Group', () => {
expect(parseAnswerSegments()).toEqual([
{
content: '',
- disableMarkdownStreaming: true,
+ disableMarkdownStreaming: false,
domId: undefined,
hasError: false,
id: 'block-1',
@@ -350,4 +350,34 @@ describe('Group', () => {
},
]);
});
+
+ it('only animates the last block in a multi-block group', () => {
+ const { container } = render(
+ <Group
+ id="assistant-1"
+ messageIndex={0}
+ blocks={[
+ blk({ content: 'first paragraph', id: 'block-1' }),
+ blk({ content: 'middle paragraph', id: 'block-2' }),
+ blk({ content: 'last paragraph', id: 'block-3' }),
+ ]}
+ />,
+ );
+
+ const sequence = Array.from(container.querySelectorAll('[data-testid]')).map((node) =>
+ node.getAttribute('data-testid'),
+ );
+
+ expect(sequence).toEqual(['answer-segment', 'answer-segment', 'answer-segment']);
+ expect(
+ parseAnswerSegments().map((seg: { disableMarkdownStreaming: boolean; id: string }) => ({
+ disableMarkdownStreaming: seg.disableMarkdownStreaming,
+ id: seg.id,
+ })),
+ ).toEqual([
+ { disableMarkdownStreaming: true, id: 'block-1' },
+ { disableMarkdownStreaming: true, id: 'block-2' },
+ { disableMarkdownStreaming: false, id: 'block-3' },
+ ]);
+ });
});
diff --git a/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx b/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx
index b81021caf0c..811aeb8b8aa 100644
--- a/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/components/Group.tsx
@@ -395,10 +395,10 @@ const partitionBlocks = (
const withMarkdownStreamingState = (
block: RenderableAssistantContentBlock,
- firstBlockId: string | undefined,
+ lastBlockId: string | undefined,
): RenderableAssistantContentBlock => ({
...block,
- disableMarkdownStreaming: block.disableMarkdownStreaming || block.id === firstBlockId,
+ disableMarkdownStreaming: block.disableMarkdownStreaming || block.id !== lastBlockId,
});
const shouldInlineWorkflowSegment = (blocks: RenderableAssistantContentBlock[]): boolean => {
@@ -427,7 +427,7 @@ const Group = memo<GroupChildrenProps>(
messageStateSelectors.isAssistantGroupItemGenerating(id)(s),
]);
const contextValue = useMemo(() => ({ assistantGroupId: id }), [id]);
- const firstBlockId = blocks[0]?.id;
+ const lastBlockId = blocks.at(-1)?.id;
const { segments, postToolTailPromoted } = useMemo(
() => partitionBlocks(blocks, isGenerating),
@@ -455,7 +455,7 @@ const Group = memo<GroupChildrenProps>(
if (shouldInlineWorkflowSegment(segment.blocks)) {
return segment.blocks.map((block, blockIndex) => {
- const item = withMarkdownStreamingState(block, firstBlockId);
+ const item = withMarkdownStreamingState(block, lastBlockId);
if (!isGenerating && isEmptyBlock(item)) return null;
return (
@@ -479,7 +479,7 @@ const Group = memo<GroupChildrenProps>(
key={segment.blocks[0]?.renderKey ?? `${id}.workflow.${index}`}
workflowChromeComplete={workflowChromeComplete}
blocks={segment.blocks.map((block) =>
- withMarkdownStreamingState(block, firstBlockId),
+ withMarkdownStreamingState(block, lastBlockId),
)}
/>
);
@@ -490,7 +490,7 @@ const Group = memo<GroupChildrenProps>(
return (
<GroupItem
- {...withMarkdownStreamingState(item, firstBlockId)}
+ {...withMarkdownStreamingState(item, lastBlockId)}
assistantId={id}
contentId={contentId}
disableEditing={disableEditing}
diff --git a/src/hooks/useHotkeys/chatScope.ts b/src/hooks/useHotkeys/chatScope.ts
index 0559de9742c..9655574028d 100644
--- a/src/hooks/useHotkeys/chatScope.ts
+++ b/src/hooks/useHotkeys/chatScope.ts
@@ -2,7 +2,6 @@ import { HotkeyEnum, HotkeyScopeEnum } from '@lobechat/const/hotkeys';
import { useEffect } from 'react';
import { useHotkeysContext } from 'react-hotkeys-hook';
-import { useClearCurrentMessages } from '@/features/ChatInput/ActionBar/Clear';
import { useOpenChatSettings } from '@/hooks/useInterceptingRoutes';
import { useActionSWR } from '@/libs/swr';
import { useChatStore } from '@/store/chat';
@@ -42,13 +41,6 @@ export const useAddUserMessageHotkey = (send: () => void) => {
);
};
-export const useClearCurrentMessagesHotkey = () => {
- const clearCurrentMessages = useClearCurrentMessages();
- return useHotkeyById(HotkeyEnum.ClearCurrentMessages, () => clearCurrentMessages(), {
- enableOnContentEditable: true,
- });
-};
-
// Register aggregate
export const useRegisterChatHotkeys = () => {
@@ -63,7 +55,6 @@ export const useRegisterChatHotkeys = () => {
// Conversation
// Note: Regenerate and delete hotkeys have been moved to ConversationStore
useSaveTopicHotkey();
- useClearCurrentMessagesHotkey();
useEffect(() => {
enableScope(HotkeyScopeEnum.Chat);
diff --git a/src/locales/default/hotkey.ts b/src/locales/default/hotkey.ts
index b4f9e955b82..0d68717ab65 100644
--- a/src/locales/default/hotkey.ts
+++ b/src/locales/default/hotkey.ts
@@ -1,9 +1,6 @@
export default {
'addUserMessage.desc': 'Add the current input as a user message without triggering generation',
'addUserMessage.title': 'Add a User Message',
- 'clearCurrentMessages.desc':
- 'Clear the messages and uploaded files from the current conversation',
- 'clearCurrentMessages.title': 'Clear Conversation Messages',
'commandPalette.desc': 'Open the global command palette for quick access to features',
'commandPalette.title': 'Command Palette',
'deleteAndRegenerateMessage.desc': 'Delete the last message and regenerate',