fix: 浮动工具栏精确定位 — 紧贴选中文字 4px,顶部不足时自动显示在下方
CI / test (18.x) (push) Canceled after 0s
CI / test (20.x) (push) Canceled after 0s
CI / test (22.x) (push) Canceled after 0s
CI / test (24.x) (push) Canceled after 0s

This commit is contained in:
2026-07-25 15:17:24 +08:00
parent 01c9807817
commit d96f124a8f
8 changed files with 41 additions and 30 deletions
+9 -7
View File
@@ -3722,14 +3722,16 @@ dl{margin:.8em 0}dt{font-weight:650;margin:.6em 0 .2em}dd{margin:0 0 .3em 1.6em;
const lineHeight = parseInt(getComputedStyle(ta).lineHeight, 10) || 22;
const paddingTop = parseInt(getComputedStyle(ta).paddingTop, 10) || 16;
const scrollOffset = ta.scrollTop;
// Place toolbar just above the selected line (4px gap)
// Line top relative to textarea content area
const lineTop = rect.top + paddingTop + currentLine * lineHeight - scrollOffset;
const toolbarHeight = 36;
let top = rect.top + paddingTop + currentLine * lineHeight - scrollOffset - toolbarHeight - 4;
// Clamp: don't go above textarea
if (top < rect.top)
top = rect.top + 4;
if (top + toolbarHeight > rect.bottom)
top = rect.bottom - toolbarHeight - 4;
const gap = 4;
// Try above first
let top = lineTop - toolbarHeight - gap;
// If not enough room above, place below the selection
if (top < rect.top + gap) {
top = lineTop + lineHeight + gap;
}
// Center horizontally near the middle of selection
let left = rect.left + (ta.selectionDirection !== 'backward' ? (ta.selectionEnd - ta.selectionStart) / 2 : 0) * 8 + 10;
if (left < rect.left)