简化合并
This commit is contained in:
parent
9c44a4d425
commit
04c3f57218
11
markdown.js
11
markdown.js
@ -111,13 +111,10 @@ element.onclick = (event) => {
|
|||||||
return { index: i, rect: range.getBoundingClientRect() }
|
return { index: i, rect: range.getBoundingClientRect() }
|
||||||
})
|
})
|
||||||
|
|
||||||
const closest = positions.reduce(
|
const closest = positions.reduce((closest, pos) => {
|
||||||
(closest, pos) => {
|
const dist = Math.abs(x - pos.rect.left)
|
||||||
const dist = Math.abs(x - pos.rect.left)
|
return dist < closest.distance ? { ...pos, distance: dist } : closest
|
||||||
return dist < closest.distance ? { ...pos, distance: dist } : closest
|
}, { index: -1, distance: Infinity })
|
||||||
},
|
|
||||||
{ index: -1, distance: Infinity }
|
|
||||||
)
|
|
||||||
|
|
||||||
const rect = closest.rect
|
const rect = closest.rect
|
||||||
const insertBefore = x < rect.left + rect.width / 2
|
const insertBefore = x < rect.left + rect.width / 2
|
||||||
|
Loading…
Reference in New Issue
Block a user