Skip to content

Commit 2b436bd

Browse files
authored
feat: MiniMap preview use viewport ratio (#482)
1 parent 16e1466 commit 2b436bd

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/components/mini-map/mini-map.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ export const MiniMap: React.FC<MiniMapProps> = ({
5151
const wrapperRef = useRef<HTMLDivElement | null>(null);
5252
const previewRef = useRef<HTMLDivElement | null>(null);
5353

54+
const getViewportSize = useCallback(() => {
55+
if (instance.wrapperComponent) {
56+
const rect = instance.wrapperComponent.getBoundingClientRect();
57+
58+
return {
59+
width: rect.width,
60+
height: rect.height
61+
};
62+
}
63+
return {
64+
width: 0,
65+
height: 0
66+
};
67+
}, [instance.wrapperComponent]);
68+
5469
const getContentSize = useCallback(() => {
5570
if (instance.contentComponent) {
5671
const rect = instance.contentComponent.getBoundingClientRect();
@@ -116,7 +131,7 @@ export const MiniMap: React.FC<MiniMapProps> = ({
116131
mainRef.current.style.height = `${miniSize.height}px`;
117132
}
118133
if (previewRef.current) {
119-
const size = getContentSize();
134+
const size = getViewportSize();
120135
const scale = computeMiniMapScale();
121136
const previewScale = scale * (1 / instance.transformState.scale);
122137
const transform = instance.handleTransformStyles(

0 commit comments

Comments
 (0)