fix(chat): clear text selection timer (#1154)
Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
28f7a52ec8
commit
98ef2e87a1
@@ -218,6 +218,7 @@ export const TextSelectionMenu: React.FC<TextSelectionMenuProps> = ({ containerR
|
|||||||
const menuWidthRef = React.useRef(DESKTOP_MENU_FALLBACK_WIDTH_PX);
|
const menuWidthRef = React.useRef(DESKTOP_MENU_FALLBACK_WIDTH_PX);
|
||||||
const pendingSelectionRef = React.useRef<SelectionPayload | null>(null);
|
const pendingSelectionRef = React.useRef<SelectionPayload | null>(null);
|
||||||
const openRafRef = React.useRef<number | null>(null);
|
const openRafRef = React.useRef<number | null>(null);
|
||||||
|
const mouseUpTimeoutRef = React.useRef<number | null>(null);
|
||||||
const isMenuVisibleRef = React.useRef(false);
|
const isMenuVisibleRef = React.useRef(false);
|
||||||
const createSession = useSessionUIStore((state) => state.createSession);
|
const createSession = useSessionUIStore((state) => state.createSession);
|
||||||
const currentSessionId = useSessionUIStore((state) => state.currentSessionId);
|
const currentSessionId = useSessionUIStore((state) => state.currentSessionId);
|
||||||
@@ -238,6 +239,10 @@ export const TextSelectionMenu: React.FC<TextSelectionMenuProps> = ({ containerR
|
|||||||
window.cancelAnimationFrame(openRafRef.current);
|
window.cancelAnimationFrame(openRafRef.current);
|
||||||
openRafRef.current = null;
|
openRafRef.current = null;
|
||||||
}
|
}
|
||||||
|
if (mouseUpTimeoutRef.current !== null) {
|
||||||
|
window.clearTimeout(mouseUpTimeoutRef.current);
|
||||||
|
mouseUpTimeoutRef.current = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -408,8 +413,12 @@ export const TextSelectionMenu: React.FC<TextSelectionMenuProps> = ({ containerR
|
|||||||
isDraggingRef.current = false;
|
isDraggingRef.current = false;
|
||||||
// Check if we have a pending selection to show
|
// Check if we have a pending selection to show
|
||||||
if (pendingSelectionRef.current) {
|
if (pendingSelectionRef.current) {
|
||||||
|
if (mouseUpTimeoutRef.current !== null) {
|
||||||
|
window.clearTimeout(mouseUpTimeoutRef.current);
|
||||||
|
}
|
||||||
// Small delay to ensure selection is finalized
|
// Small delay to ensure selection is finalized
|
||||||
setTimeout(() => {
|
mouseUpTimeoutRef.current = window.setTimeout(() => {
|
||||||
|
mouseUpTimeoutRef.current = null;
|
||||||
const selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
if (selection && selection.toString().trim()) {
|
if (selection && selection.toString().trim()) {
|
||||||
showMenu();
|
showMenu();
|
||||||
@@ -440,6 +449,10 @@ export const TextSelectionMenu: React.FC<TextSelectionMenuProps> = ({ containerR
|
|||||||
document.addEventListener('mousedown', handleClickOutside);
|
document.addEventListener('mousedown', handleClickOutside);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
if (mouseUpTimeoutRef.current !== null) {
|
||||||
|
window.clearTimeout(mouseUpTimeoutRef.current);
|
||||||
|
mouseUpTimeoutRef.current = null;
|
||||||
|
}
|
||||||
document.removeEventListener('selectionchange', handleSelectionChange);
|
document.removeEventListener('selectionchange', handleSelectionChange);
|
||||||
container.removeEventListener('mousedown', handleMouseDown);
|
container.removeEventListener('mousedown', handleMouseDown);
|
||||||
document.removeEventListener('mouseup', handleMouseUp);
|
document.removeEventListener('mouseup', handleMouseUp);
|
||||||
|
|||||||
Reference in New Issue
Block a user