Skip to content

Commit 3e36ad0

Browse files
committed
chore: better code
1 parent 083f40f commit 3e36ad0

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/components/editor/components/toolbar/selection-toolbar/actions/MenuButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { ReactNode } from 'react';
2-
import { Button } from '@/components/ui/button';
2+
import { Button, buttonVariants } from '@/components/ui/button';
33
import { ReactComponent as TickIcon } from '@/assets/icons/tick.svg';
4+
import { VariantProps } from 'class-variance-authority';
45

56
interface MenuButtonProps {
67
icon: ReactNode;
78
label: ReactNode;
89
isActive?: boolean;
910
onClick: () => void;
1011
selected?: boolean;
11-
buttonProps?: Record<string, any>;
12+
buttonProps?: React.ComponentProps<'button'> & VariantProps<typeof buttonVariants> & { asChild?: boolean };
1213
}
1314

1415
export function MenuButton({ icon, label, isActive, onClick, selected, buttonProps }: MenuButtonProps) {

src/components/editor/components/toolbar/selection-toolbar/actions/TurnInto.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ function TurnInfo() {
193193
} else {
194194
CustomEditor.turnToBlock(editor, node.blockId as string, option.blockType, option.data || {});
195195
}
196+
196197
setOpen(false);
197198
} catch (e) { setOpen(false); }
198199
};
@@ -225,6 +226,7 @@ function TurnInfo() {
225226
isOpen: open,
226227
onSelect: (index) => {
227228
const options = [...suggestionOptions, ...turnIntoOptions];
229+
228230
handleBlockChange(options[index]);
229231
},
230232
onClose: () => setOpen(false)

src/components/editor/components/toolbar/selection-toolbar/hooks/useKeyboardNavigation.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useEffect, useRef, useState } from 'react';
22

3-
import { createHotkey,HOT_KEY_NAME } from '@/utils/hotkeys';
3+
import { createHotkey, HOT_KEY_NAME } from '@/utils/hotkeys';
44

55
interface UseKeyboardNavigationProps {
66
itemCount: number;
@@ -20,7 +20,6 @@ export function useKeyboardNavigation({ itemCount, onSelect, onClose, isOpen }:
2020
}
2121

2222
const handleKeyDown = (e: KeyboardEvent) => {
23-
// 只在按下上下键时阻止默认行为
2423
if (createHotkey(HOT_KEY_NAME.UP)(e) || createHotkey(HOT_KEY_NAME.DOWN)(e)) {
2524
e.preventDefault();
2625
e.stopPropagation();
@@ -40,7 +39,6 @@ export function useKeyboardNavigation({ itemCount, onSelect, onClose, isOpen }:
4039
}
4140
};
4241

43-
// 使用 capture 阶段来确保在事件到达编辑器之前处理
4442
document.addEventListener('keydown', handleKeyDown, true);
4543
return () => {
4644
document.removeEventListener('keydown', handleKeyDown, true);

0 commit comments

Comments
 (0)