fix: 浮动工具栏精确定位 — 紧贴选中文字 4px,顶部不足时自动显示在下方
This commit is contained in:
+10
-5
@@ -737,12 +737,17 @@ export class MarkdownEditor {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user