diff --git a/src/CodeEditor/index.tsx b/src/CodeEditor/index.tsx index 8919d297..4cee7a4c 100644 --- a/src/CodeEditor/index.tsx +++ b/src/CodeEditor/index.tsx @@ -16,6 +16,7 @@ import { import { Flexbox, FlexboxProps } from 'react-layout-kit'; import { useStyles } from '@/CodeEditor/style'; +import { isMacLike } from '@/utils/platform'; import SyntaxHighlighter from '../Highlighter/SyntaxHighlighter'; @@ -78,10 +79,6 @@ const HISTORY_TIME_GAP = 3000; const isWindows = typeof window !== 'undefined' && 'navigator' in window && /win/i.test(navigator.platform); -const isMacLike = - typeof window !== 'undefined' && - 'navigator' in window && - /(mac|iphone|ipod|ipad)/i.test(navigator.platform); const getLines = (text: string, position: number) => text.slice(0, Math.max(0, position)).split('\n'); diff --git a/src/Swatches/index.tsx b/src/Swatches/index.tsx index 17888d1e..7ed6fd8b 100644 --- a/src/Swatches/index.tsx +++ b/src/Swatches/index.tsx @@ -43,13 +43,13 @@ const Swatches = memo(({ colors, activeColor, onSelect, size = 24 background: theme.colorBgContainer, }} /> - {colors.map((c) => { + {colors.map((c, index) => { const isActive = c === activeColor; return ( { onSelect?.(c); }} diff --git a/src/chat/EditableMessage/index.tsx b/src/chat/EditableMessage/index.tsx index 40efd4b0..83322c4b 100644 --- a/src/chat/EditableMessage/index.tsx +++ b/src/chat/EditableMessage/index.tsx @@ -126,6 +126,7 @@ const EditableMessage = memo( setTyping(false); }} placeholder={placeholder} + shortcut style={stylesProps?.input} text={text} textareaClassname={classNames?.input} diff --git a/src/chat/MessageInput/demos/index.tsx b/src/chat/MessageInput/demos/index.tsx index 7aab0aca..e88730bb 100644 --- a/src/chat/MessageInput/demos/index.tsx +++ b/src/chat/MessageInput/demos/index.tsx @@ -3,14 +3,12 @@ import { Divider } from 'antd'; import { useState } from 'react'; import { Flexbox } from 'react-layout-kit'; -import { content } from '../../../Markdown/demos/data'; - export default () => { const [value, setValue] = useState(''); return ( ButtonProps[]; + shortcut?: boolean; text?: { cancel?: string; confirm?: string; @@ -65,6 +69,7 @@ const MessageInput = memo( style, editButtonSize = 'middle', classNames, + shortcut, ...rest }) => { const [temporaryValue, setValue] = useState(defaultValue || ''); @@ -80,6 +85,15 @@ const MessageInput = memo( classNames={classNames} onBlur={(e) => setValue(e.target.value)} onChange={(e) => setValue(e.target.value)} + onPressEnter={ + shortcut + ? (e) => { + if (isMacLike ? e.metaKey : e.ctrlKey) { + onConfirm?.(temporaryValue); + } + } + : undefined + } placeholder={placeholder} resize={false} style={textareaStyle} @@ -101,6 +115,12 @@ const MessageInput = memo( type="primary" > {text?.confirm || 'Confirm'} + {shortcut && ( + + + + + )}