Skip to content

Commit 3e3adba

Browse files
authored
fix(file-manager): allow system paste while renaming (#933)
1 parent 7308de0 commit 3e3adba

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/app/core/main/file/index.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ function useFileManagerShortcuts() {
4646
}
4747
}, [currentPlatform])
4848

49+
const isEditableTarget = useCallback((target: EventTarget | null): boolean => {
50+
if (!(target instanceof HTMLElement)) {
51+
return false
52+
}
53+
54+
if (target.isContentEditable) {
55+
return true
56+
}
57+
58+
if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) {
59+
return true
60+
}
61+
62+
return !!target.closest('input, textarea, select, [contenteditable="true"], [role="textbox"]')
63+
}, [])
64+
4965
// 获取当前激活的 item(文件或文件夹)
5066
const getActiveItem = useCallback((): { path: string; isDirectory: boolean; isLocale: boolean; name: string; sha?: string } | null => {
5167
if (!activeFilePath) return null
@@ -83,6 +99,10 @@ function useFileManagerShortcuts() {
8399
return
84100
}
85101

102+
if (isEditableTarget(e.target)) {
103+
return
104+
}
105+
86106
// 只有文件管理器有焦点时才处理
87107
if (!isFocused) {
88108
return
@@ -158,7 +178,7 @@ function useFileManagerShortcuts() {
158178
window.dispatchEvent(event)
159179
return
160180
}
161-
}, [isFocused, getActiveItem, isModKey, currentPlatform, setClipboardItem])
181+
}, [isFocused, getActiveItem, isModKey, currentPlatform, setClipboardItem, isEditableTarget])
162182

163183
// 注册全局快捷键
164184
useEffect(() => {
@@ -245,4 +265,4 @@ export function FileSidebar() {
245265
<FileFooter />
246266
</div>
247267
)
248-
}
268+
}

0 commit comments

Comments
 (0)