feat: wait 1ms before menu collision detection (#859)
This commit is contained in:
@@ -27,7 +27,7 @@ import {
|
|||||||
TransactionalMutation,
|
TransactionalMutation,
|
||||||
} from '@standardnotes/snjs';
|
} from '@standardnotes/snjs';
|
||||||
import { FunctionComponent } from 'preact';
|
import { FunctionComponent } from 'preact';
|
||||||
import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks';
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||||
import { Icon } from '../Icon';
|
import { Icon } from '../Icon';
|
||||||
import { createEditorMenuGroups } from './changeEditor/createEditorMenuGroups';
|
import { createEditorMenuGroups } from './changeEditor/createEditorMenuGroups';
|
||||||
import { EditorAccordionMenu } from './changeEditor/EditorAccordionMenu';
|
import { EditorAccordionMenu } from './changeEditor/EditorAccordionMenu';
|
||||||
@@ -111,7 +111,7 @@ const calculateMenuPosition = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menuBoundingRect && buttonRect) {
|
if (menuBoundingRect && menuBoundingRect.height && buttonRect) {
|
||||||
if (menuBoundingRect.y < MENU_MARGIN_FROM_APP_BORDER) {
|
if (menuBoundingRect.y < MENU_MARGIN_FROM_APP_BORDER) {
|
||||||
if (
|
if (
|
||||||
buttonRect.right + maxChangeEditorMenuSize >
|
buttonRect.right + maxChangeEditorMenuSize >
|
||||||
@@ -130,11 +130,13 @@ const calculateMenuPosition = (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return position;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return position;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const TIME_IN_MS_TO_WAIT_BEFORE_REPAINT = 1;
|
||||||
|
|
||||||
export const ChangeEditorOption: FunctionComponent<ChangeEditorOptionProps> = ({
|
export const ChangeEditorOption: FunctionComponent<ChangeEditorOptionProps> = ({
|
||||||
application,
|
application,
|
||||||
appState,
|
appState,
|
||||||
@@ -182,16 +184,18 @@ export const ChangeEditorOption: FunctionComponent<ChangeEditorOptionProps> = ({
|
|||||||
setChangeEditorMenuOpen(!changeEditorMenuOpen);
|
setChangeEditorMenuOpen(!changeEditorMenuOpen);
|
||||||
};
|
};
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useEffect(() => {
|
||||||
if (changeEditorMenuOpen) {
|
if (changeEditorMenuOpen) {
|
||||||
const newMenuPosition = calculateMenuPosition(
|
setTimeout(() => {
|
||||||
changeEditorButtonRef.current,
|
const newMenuPosition = calculateMenuPosition(
|
||||||
changeEditorMenuRef.current
|
changeEditorButtonRef.current,
|
||||||
);
|
changeEditorMenuRef.current
|
||||||
|
);
|
||||||
|
|
||||||
if (newMenuPosition) {
|
if (newMenuPosition) {
|
||||||
setChangeEditorMenuPosition(newMenuPosition);
|
setChangeEditorMenuPosition(newMenuPosition);
|
||||||
}
|
}
|
||||||
|
}, TIME_IN_MS_TO_WAIT_BEFORE_REPAINT);
|
||||||
}
|
}
|
||||||
}, [changeEditorMenuOpen]);
|
}, [changeEditorMenuOpen]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user