fix: 浮动工具栏贴近选中文字 + 构建最新 dist
This commit is contained in:
+10
-3
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user