fix(images): 拖入同图不再被去重拦掉(可重复添加);gcImages 计入画布引用,避免误删在用图片(v3.25.8)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m12s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m12s
This commit is contained in:
1 parent
57fc63dc10
commit
49b419251e
12 files changed
+81
-48
No files matched your search
@@ -1119,22 +1119,10 @@
|
||||
// 而 MIME 没填的 PNG 反倒被静默丢掉(Windows 资源管理器就这行为)。
|
||||
const A = global.IWBImageAdmit
|
||||
const refused = []
|
||||
/* 同图去重(v3.24.75):拖进来的字节与画布上已有图片一致时不再建节点。
|
||||
* 判据见 src/image-dedupe.js —— 只认本地图片字节,URL / 复制节点组都不参与。
|
||||
* 多条命中合并成一条提示(拖 5 张重复图不该刷 5 条),并选中已有节点把位置指出来。 */
|
||||
const D = global.IWBImageDedupe
|
||||
const idx = (D && typeof D.index === 'function') ? D.index(refs.nodes) : null
|
||||
const dupNames = []
|
||||
const dupIds = []
|
||||
const flushDups = () => {
|
||||
if (!dupNames.length) return
|
||||
const ns = dupNames.splice(0, dupNames.length)
|
||||
const ids = dupIds.splice(0, dupIds.length)
|
||||
if (ids.length) setSel(ids)
|
||||
setNotice({ type: 'ok', text: ns.length === 1
|
||||
? ('「' + ns[0] + '」已经在画布上了,没有重复导入' + (ids.length ? '(已选中原来的节点)' : ''))
|
||||
: (ns.length + ' 张图已经在画布上了,没有重复导入' + (ids.length ? '(已选中原来的节点)' : '')) })
|
||||
}
|
||||
/* v3.25.8(用户裁定):拖入同一张图**允许重复添加**,不再走同图去重。
|
||||
* 去重曾经挡住「图片节点数据缺失后重新拖入」这条唯一的自愈路径:命中已有节点 →
|
||||
* 不写 blob → 那个节点依旧是空图。现在每次都正常导入并新建节点,顺带把丢失的
|
||||
* blob 按同一个内容 key 重新写回磁盘(旧节点也就跟着恢复了)。 */
|
||||
for (const f of files) {
|
||||
const verdict = (A && typeof A.of === 'function') ? A.of(f) : ((f.type && f.type.indexOf('image/') === 0) ? 'image' : 'other')
|
||||
if (verdict !== 'image') { refused.push(f); continue }
|
||||
@@ -1143,16 +1131,7 @@
|
||||
// 拖放与粘贴共用导入唯一收口(压缩到 ≤1600 + 立即引用化)
|
||||
rd.onload = () => wImportImage(rd.result, { onError: (msg) => setNotice({ type: 'err', text: msg }) }, (r) => {
|
||||
if (!r || !r.ok || !r.data) return
|
||||
const hitId = idx ? idx.hit(r.data) : ''
|
||||
if (hitId) {
|
||||
dupNames.push(String(f.name || '图片'))
|
||||
if (dupIds.indexOf(hitId) < 0) dupIds.push(hitId)
|
||||
clearTimeout(refs.dupNoticeTimer)
|
||||
refs.dupNoticeTimer = setTimeout(flushDups, 260)
|
||||
return
|
||||
}
|
||||
const nid = mk({ url: '', data: r.data, name: f.name })
|
||||
if (idx) idx.add(r.data, nid)
|
||||
mk({ url: '', data: r.data, name: f.name })
|
||||
})
|
||||
rd.onerror = () => setNotice({ type: 'err', text: '读取拖入的图片失败:' + String(f.name || '') })
|
||||
rd.readAsDataURL(f)
|
||||
|
||||
Reference in new issue
Block a user