简化合并

This commit is contained in:
satori 2025-01-15 19:26:44 +08:00
parent 9c44a4d425
commit 04c3f57218

View File

@ -111,13 +111,10 @@ element.onclick = (event) => {
return { index: i, rect: range.getBoundingClientRect() }
})
const closest = positions.reduce(
(closest, pos) => {
const dist = Math.abs(x - pos.rect.left)
return dist < closest.distance ? { ...pos, distance: dist } : closest
},
{ index: -1, distance: Infinity }
)
const closest = positions.reduce((closest, pos) => {
const dist = Math.abs(x - pos.rect.left)
return dist < closest.distance ? { ...pos, distance: dist } : closest
}, { index: -1, distance: Infinity })
const rect = closest.rect
const insertBefore = x < rect.left + rect.width / 2