mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-21 16:26:58 +08:00
fix(editor): at menu position in split view (#9500)
This commit is contained in:
@@ -16,6 +16,7 @@ export {
|
||||
export {
|
||||
getBlockSelectionsCommand,
|
||||
getImageSelectionsCommand,
|
||||
getRangeRects,
|
||||
getSelectionRectsCommand,
|
||||
getTextSelectionCommand,
|
||||
type SelectionRect,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user