From 04c3f572182a1b722daba3a4f9d632f7abb15219 Mon Sep 17 00:00:00 2001 From: satori Date: Wed, 15 Jan 2025 19:26:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- markdown.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/markdown.js b/markdown.js index 49bdc0c..f63d31d 100644 --- a/markdown.js +++ b/markdown.js @@ -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