fundon
2025-03-06 07:48:04 +00:00
parent 91adc533a8
commit 8bfaa2502e
2 changed files with 20 additions and 3 deletions

View File

@@ -21,7 +21,9 @@ import {
autoUpdate, autoUpdate,
computePosition, computePosition,
flip, flip,
hide,
inline, inline,
limitShift,
offset, offset,
shift, shift,
} from '@floating-ui/dom'; } from '@floating-ui/dom';
@@ -62,7 +64,22 @@ export function autoUpdatePosition(
const { x, y } = await computePosition(referenceElement, toolbar, { const { x, y } = await computePosition(referenceElement, toolbar, {
placement, placement,
middleware: [offset(10), inline(), shift({ padding: 6 }), flip()], middleware: [
offset(10),
inline(),
shift(state => ({
padding: {
top: 10,
right: 10,
bottom: 150,
left: 10,
},
crossAxis: state.placement.includes('bottom'),
limiter: limitShift(),
})),
flip({ padding: 10 }),
hide(),
],
}); });
toolbar.style.transform = `translate3d(${x}px, ${y}px, 0)`; toolbar.style.transform = `translate3d(${x}px, ${y}px, 0)`;

View File

@@ -123,7 +123,7 @@ test('should format quick bar show when select text by keyboard', async ({
throw new Error("formatBar doesn't exist"); throw new Error("formatBar doesn't exist");
} }
let selectionRect = await getSelectionRect(page); let selectionRect = await getSelectionRect(page);
assertAlmostEqual(formatBarBox.x - selectionRect.x, -107, 3); assertAlmostEqual(formatBarBox.x - selectionRect.x, -103, 3);
assertAlmostEqual( assertAlmostEqual(
formatBarBox.y + formatBarBox.height - selectionRect.top, formatBarBox.y + formatBarBox.height - selectionRect.top,
-10, -10,
@@ -150,7 +150,7 @@ test('should format quick bar show when select text by keyboard', async ({
// The x position of the format quick bar depends on the font size // The x position of the format quick bar depends on the font size
// so there are slight differences in different environments // so there are slight differences in different environments
selectionRect = await getSelectionRect(page); selectionRect = await getSelectionRect(page);
assertAlmostEqual(formatBarBox.x - selectionRect.x, -107, 3); assertAlmostEqual(formatBarBox.x - selectionRect.x, -103, 3);
assertAlmostEqual( assertAlmostEqual(
formatBarBox.y + formatBarBox.height - selectionRect.top, formatBarBox.y + formatBarBox.height - selectionRect.top,
-10, -10,