fix: 浮动工具栏贴近选中文字 + 构建最新 dist
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:12:47 +08:00
parent 19f9ba91a8
commit 01c9807817
9 changed files with 14324 additions and 3 deletions
+10 -3
View File
@@ -734,11 +734,18 @@ export class MarkdownEditor {
const lines = textBefore.split('\n');
const currentLine = lines.length - 1;
const lineHeight = parseInt(getComputedStyle(ta).lineHeight, 10) || 22;
const paddingTop = parseInt(getComputedStyle(ta).paddingTop, 10) || 16;
const scrollOffset = ta.scrollTop;
let top = rect.top + currentLine * lineHeight - 38;
// Place toolbar just above the selected line (4px gap)
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;
// Center horizontally near the middle of selection
let left = rect.left + (ta.selectionDirection !== 'backward' ? (ta.selectionEnd - ta.selectionStart) / 2 : 0) * 8 + 10;
if (top < rect.top) top = rect.top + currentLine * lineHeight + lineHeight + 4;
if (left < rect.left) left = rect.left + 4;
const maxLeft = rect.right - 200;
if (left > maxLeft) left = maxLeft;