fix(editor): at menu position in split view (#9500)

This commit is contained in:
Flrande
2025-01-03 12:20:31 +00:00
parent b17dac2201
commit 2074bda8ff
8 changed files with 230 additions and 271 deletions

View File

@@ -16,6 +16,7 @@ export {
export {
getBlockSelectionsCommand,
getImageSelectionsCommand,
getRangeRects,
getSelectionRectsCommand,
getTextSelectionCommand,
type SelectionRect,

View File

@@ -54,22 +54,8 @@ export const getSelectionRectsCommand: Command<
const range = std.range.textSelectionToRange(textSelection);
if (range) {
const nativeRects = Array.from(range.getClientRects());
const rectsWithoutFiltered = nativeRects
.map(rect => ({
width: rect.right - rect.left,
height: rect.bottom - rect.top,
top:
rect.top - (containerRect?.top ?? 0) + (container?.scrollTop ?? 0),
left:
rect.left -
(containerRect?.left ?? 0) +
(container?.scrollLeft ?? 0),
}))
.filter(rect => rect.width > 0 && rect.height > 0);
return next({
selectionRects: filterCoveringRects(rectsWithoutFiltered),
selectionRects: getRangeRects(range, container),
});
}
} else if (blockSelections && blockSelections.length > 0) {
@@ -198,3 +184,22 @@ export function filterCoveringRects(rects: SelectionRect[]): SelectionRect[] {
return mergedRects;
}
export function getRangeRects(
range: Range,
container: HTMLElement | null
): SelectionRect[] {
const nativeRects = Array.from(range.getClientRects());
const containerRect = container?.getBoundingClientRect();
const rectsWithoutFiltered = nativeRects
.map(rect => ({
width: rect.right - rect.left,
height: rect.bottom - rect.top,
top: rect.top - (containerRect?.top ?? 0) + (container?.scrollTop ?? 0),
left:
rect.left - (containerRect?.left ?? 0) + (container?.scrollLeft ?? 0),
}))
.filter(rect => rect.width > 0 && rect.height > 0);
return filterCoveringRects(rectsWithoutFiltered);
}

View File

@@ -1,6 +1,7 @@
export { getBlockSelectionsCommand } from './get-block-selections.js';
export { getImageSelectionsCommand } from './get-image-selections.js';
export {
getRangeRects,
getSelectionRectsCommand,
type SelectionRect,
} from './get-selection-rects.js';