소스 검색

refac: floating buttons

Timothy J. Baek 7 달 전
부모
커밋
6e8e0454e4
1개의 변경된 파일12개의 추가작업 그리고 7개의 파일을 삭제
  1. 12 7
      src/lib/components/chat/Messages/ContentRenderer.svelte

+ 12 - 7
src/lib/components/chat/Messages/ContentRenderer.svelte

@@ -23,14 +23,18 @@
 	let floatingInputValue = '';
 
 	const updateButtonPosition = (event) => {
+		if (
+			!contentContainerElement?.contains(event.target) &&
+			!buttonsContainerElement?.contains(event.target)
+		) {
+			closeFloatingButtons();
+			return;
+		}
+
 		setTimeout(async () => {
 			await tick();
 
-			// Check if the event target is within the content container
-			if (!contentContainerElement?.contains(event.target)) {
-				closeFloatingButtons();
-				return;
-			}
+			if (!contentContainerElement?.contains(event.target)) return;
 
 			let selection = window.getSelection();
 
@@ -51,8 +55,9 @@
 					// Calculate space available on the right
 					const spaceOnRight = parentRect.width - (left + buttonsContainerElement.offsetWidth);
 
-					if (spaceOnRight < 0) {
-						// Not enough space on the right, position using 'right'
+					let thirdScreenWidth = window.innerWidth / 3;
+
+					if (spaceOnRight < thirdScreenWidth) {
 						const right = parentRect.right - rect.right;
 						buttonsContainerElement.style.right = `${right}px`;
 						buttonsContainerElement.style.left = 'auto'; // Reset left