Skip to content

Commit a4779b6

Browse files
committed
把 event.target 归一化为 Element,再检查 HTMLAnchorElement / HTMLImageElement / closest('a[href], img')
同样先把文本节点提升到 parentElement,再执行 closest(NATIVE_DRAG_SOURCE_SELECTOR)
1 parent 9d8acfc commit a4779b6

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

frontend/plugin-manager/src/main.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,18 @@ function initNativeDragGuard() {
4242
}
4343

4444
const handleDragStart = (event: DragEvent) => {
45-
const target = event.target
45+
const rawTarget = event.target
46+
let target: Element | null = null
47+
if (rawTarget instanceof Element) {
48+
target = rawTarget
49+
} else if (rawTarget instanceof Node) {
50+
target = rawTarget.parentElement
51+
}
52+
4653
if (
4754
target instanceof HTMLAnchorElement
4855
|| target instanceof HTMLImageElement
49-
|| (target instanceof Element && target.closest('a[href], img'))
56+
|| target?.closest('a[href], img')
5057
) {
5158
event.preventDefault()
5259
}

static/js/window_controls.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,16 @@
127127
window.__nekoNativeDragGuardBound = true;
128128

129129
document.addEventListener('dragstart', (event) => {
130-
const target = event.target;
131-
if (!target || typeof target.closest !== 'function') return;
132-
const source = target.closest(NATIVE_DRAG_SOURCE_SELECTOR);
130+
const rawTarget = event.target;
131+
let targetEl = null;
132+
if (rawTarget && rawTarget.nodeType === Node.ELEMENT_NODE) {
133+
targetEl = rawTarget;
134+
} else if (rawTarget && rawTarget.parentElement) {
135+
targetEl = rawTarget.parentElement;
136+
}
137+
138+
if (!targetEl || typeof targetEl.closest !== 'function') return;
139+
const source = targetEl.closest(NATIVE_DRAG_SOURCE_SELECTOR);
133140
if (!source) return;
134141
event.preventDefault();
135142
}, true);

0 commit comments

Comments
 (0)