Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
bit-pm
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
燕伟桐
bit-pm
Commits
fa1fb9cc
Unverified
提交
fa1fb9cc
authored
6月 23, 2025
作者:
Will Chen
提交者:
GitHub
6月 23, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow pasting images (#472)
Fixes #283
上级
37fb643f
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
50 行增加
和
1 行删除
+50
-1
ChatInput.tsx
src/components/chat/ChatInput.tsx
+2
-0
HomeChatInput.tsx
src/components/chat/HomeChatInput.tsx
+2
-0
useAttachments.ts
src/hooks/useAttachments.ts
+46
-1
没有找到文件。
src/components/chat/ChatInput.tsx
浏览文件 @
fa1fb9cc
...
...
@@ -97,6 +97,7 @@ export function ChatInput({ chatId }: { chatId?: number }) {
handleDragLeave
,
handleDrop
,
clearAttachments
,
handlePaste
,
}
=
useAttachments
();
// Use the hook to fetch the proposal
...
...
@@ -309,6 +310,7 @@ export function ChatInput({ chatId }: { chatId?: number }) {
value=
{
inputValue
}
onChange=
{
(
e
)
=>
setInputValue
(
e
.
target
.
value
)
}
onKeyPress=
{
handleKeyPress
}
onPaste=
{
handlePaste
}
placeholder=
"Ask Dyad to build..."
className=
"flex-1 p-2 focus:outline-none overflow-y-auto min-h-[40px] max-h-[200px]"
style=
{
{
resize
:
"none"
}
}
...
...
src/components/chat/HomeChatInput.tsx
浏览文件 @
fa1fb9cc
...
...
@@ -37,6 +37,7 @@ export function HomeChatInput({
handleDragLeave
,
handleDrop
,
clearAttachments
,
handlePaste
,
}
=
useAttachments
();
const
adjustHeight
=
()
=>
{
...
...
@@ -103,6 +104,7 @@ export function HomeChatInput({
value=
{
inputValue
}
onChange=
{
(
e
)
=>
setInputValue
(
e
.
target
.
value
)
}
onKeyPress=
{
handleKeyPress
}
onPaste=
{
handlePaste
}
placeholder=
"Ask Dyad to build..."
className=
"flex-1 p-2 focus:outline-none overflow-y-auto min-h-[40px] max-h-[200px]"
style=
{
{
resize
:
"none"
}
}
...
...
src/hooks/useAttachments.ts
浏览文件 @
fa1fb9cc
import
{
useState
,
useRef
}
from
"react"
;
import
React
,
{
useState
,
useRef
}
from
"react"
;
export
function
useAttachments
()
{
const
[
attachments
,
setAttachments
]
=
useState
<
File
[]
>
([]);
...
...
@@ -45,6 +45,50 @@ export function useAttachments() {
setAttachments
([]);
};
const
addAttachments
=
(
files
:
File
[])
=>
{
setAttachments
((
attachments
)
=>
[...
attachments
,
...
files
]);
};
const
handlePaste
=
async
(
e
:
React
.
ClipboardEvent
)
=>
{
const
clipboardData
=
e
.
clipboardData
;
if
(
!
clipboardData
)
return
;
const
items
=
Array
.
from
(
clipboardData
.
items
);
const
imageItems
=
items
.
filter
((
item
)
=>
item
.
type
.
startsWith
(
"image/"
));
if
(
imageItems
.
length
>
0
)
{
e
.
preventDefault
();
// Prevent default paste behavior for images
const
imageFiles
:
File
[]
=
[];
// Generate base timestamp once to avoid collisions
const
baseTimestamp
=
new
Date
().
toISOString
().
replace
(
/
[
:.
]
/g
,
"-"
);
for
(
let
i
=
0
;
i
<
imageItems
.
length
;
i
++
)
{
const
item
=
imageItems
[
i
];
const
file
=
item
.
getAsFile
();
if
(
file
)
{
// Create a more descriptive filename with timestamp and counter
const
extension
=
file
.
type
.
split
(
"/"
)[
1
]
||
"png"
;
const
filename
=
imageItems
.
length
===
1
?
`pasted-image-
${
baseTimestamp
}
.
${
extension
}
`
:
`pasted-image-
${
baseTimestamp
}
-
${
i
+
1
}
.
${
extension
}
`
;
const
newFile
=
new
File
([
file
],
filename
,
{
type
:
file
.
type
,
});
imageFiles
.
push
(
newFile
);
}
}
if
(
imageFiles
.
length
>
0
)
{
addAttachments
(
imageFiles
);
// Show a brief toast or indication that image was pasted
console
.
log
(
`Pasted
${
imageFiles
.
length
}
image(s) from clipboard`
);
}
}
};
return
{
attachments
,
fileInputRef
,
...
...
@@ -56,5 +100,6 @@ export function useAttachments() {
handleDragLeave
,
handleDrop
,
clearAttachments
,
handlePaste
,
};
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论