fix: 删除聊天框图片标签时不再删除画布中的图片
- 修改全局键盘事件处理,增加对 contentEditable 元素的检测 - 在删除图片标签时阻止事件冒泡,防止触发画布的删除操作
This commit is contained in:
parent
8ff91edb11
commit
ba99ad212e
@ -393,8 +393,14 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
// 键盘快捷键
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
// 如果正在输入则不触发快捷键
|
||||
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
|
||||
// 如果正在输入则不触发快捷键(包括 input、textarea 和 contentEditable 元素)
|
||||
const target = e.target as HTMLElement;
|
||||
if (
|
||||
target instanceof HTMLInputElement ||
|
||||
target instanceof HTMLTextAreaElement ||
|
||||
target.isContentEditable ||
|
||||
target.closest('[contenteditable="true"]')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -1012,7 +1012,7 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
||||
e.preventDefault();
|
||||
handleSend();
|
||||
}
|
||||
// 处理 Backspace 删除图片标签
|
||||
// 处理 Backspace 删除图片标签(只删除聊天框中的标签,不影响画布)
|
||||
if (e.key === 'Backspace') {
|
||||
const selection = window.getSelection();
|
||||
if (selection && selection.rangeCount > 0) {
|
||||
@ -1022,6 +1022,7 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
||||
const prevSibling = range.startContainer.previousSibling as HTMLElement;
|
||||
if (prevSibling && prevSibling.getAttribute?.('data-attachment-index')) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation(); // 🆕 阻止事件冒泡,防止触发全局删除
|
||||
const index = parseInt(prevSibling.getAttribute('data-attachment-index') || '0');
|
||||
removeAttachment(index);
|
||||
prevSibling.remove();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user