@zjy4fun/json-open 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/json.js +13 -6
- package/package.json +1 -1
package/bin/json.js
CHANGED
|
@@ -385,16 +385,17 @@ function toHtml(jsonObj, deepParsedObj) {
|
|
|
385
385
|
|
|
386
386
|
highlights = Array.from(view.querySelectorAll('mark.highlight'))
|
|
387
387
|
if (highlights.length > 0) {
|
|
388
|
-
//
|
|
388
|
+
// 展开所有包含匹配项的 <details>(从内到外逐层展开)
|
|
389
389
|
highlights.forEach(h => {
|
|
390
|
-
let el = h.
|
|
391
|
-
while (el
|
|
392
|
-
|
|
393
|
-
el = el.parentElement
|
|
390
|
+
let el = h.closest('details')
|
|
391
|
+
while (el) {
|
|
392
|
+
el.open = true
|
|
393
|
+
el = el.parentElement ? el.parentElement.closest('details') : null
|
|
394
394
|
}
|
|
395
395
|
})
|
|
396
396
|
currentIdx = 0
|
|
397
|
-
|
|
397
|
+
// 等 DOM 重新布局后再滚动,确保展开动画完成
|
|
398
|
+
requestAnimationFrame(() => scrollToCurrent())
|
|
398
399
|
}
|
|
399
400
|
updateCount()
|
|
400
401
|
}
|
|
@@ -414,6 +415,12 @@ function toHtml(jsonObj, deepParsedObj) {
|
|
|
414
415
|
h.classList.toggle('current', i === currentIdx)
|
|
415
416
|
})
|
|
416
417
|
if (highlights[currentIdx]) {
|
|
418
|
+
// 确保当前高亮项所在的所有 <details> 都是展开的
|
|
419
|
+
let el = highlights[currentIdx].closest('details')
|
|
420
|
+
while (el) {
|
|
421
|
+
el.open = true
|
|
422
|
+
el = el.parentElement ? el.parentElement.closest('details') : null
|
|
423
|
+
}
|
|
417
424
|
highlights[currentIdx].scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
418
425
|
}
|
|
419
426
|
updateCount()
|