Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions moon/apps/web/components/EditorBubbleMenu/EditorBubbleMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,48 @@ export const EditorBubbleMenu = memo(function EditorBubbleMemo({
}
}, [closeLinkEditor, editor, linkEditorOpen, openLinkEditor, forceUpdate])

// Handle clicking outside to hide menu
useEffect(() => {
if (typeof window === 'undefined' || !editor?.view?.dom) {
return
}

const handleClickOutside = (event: Event) => {

Copilot AI Jul 1, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extract the outside-click logic into a reusable custom hook (e.g., useClickOutside) to reduce boilerplate and improve maintainability across components.

Copilot uses AI. Check for mistakes.
const target = event.target as Node
const editorElement = editor?.view.dom
const menuElement = containerRef.current

// Check if click is outside both editor and menu
if (editorElement && menuElement) {
const isClickInsideEditor = editorElement.contains(target)
const isClickInsideMenu = menuElement.contains(target)

if (!isClickInsideEditor && !isClickInsideMenu) {
// Clear selection to hide the bubble menu
editor?.commands.setTextSelection(editor.state.selection.from)
// Also blur the editor to ensure menu hides
editor?.view.dom.blur()
}
}
}

try {
document.addEventListener('mousedown', handleClickOutside)
} catch (error) {
// eslint-disable-next-line no-console
console.warn('Failed to add click outside listener:', error)
}

return () => {
try {
document.removeEventListener('mousedown', handleClickOutside)
} catch (error) {
// eslint-disable-next-line no-console
console.warn('Failed to remove click outside listener:', error)
}
}
}, [editor])

const containerRef = useRef<HTMLDivElement>(null)

if (!editor) return null
Expand Down
2 changes: 1 addition & 1 deletion moon/apps/web/pages/[org]/mr/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const MRDetailPage:PageWithLayout<any> = () =>{
const id = typeof tempId === 'string' ? tempId : '';
const { data: MrDetailData, isLoading: detailIsLoading } = useGetMrDetail(id)
const mrDetail = MrDetailData?.data as MRDetail | undefined
const UnderlinePanels = require('@primer/react/experimental')
const { UnderlinePanels } = require('@primer/react/experimental')

Copilot AI Jul 1, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this import to a static top-level import { UnderlinePanels } from '@primer/react/experimental' to avoid requiring the module on each render and improve readability.

Suggested change
const { UnderlinePanels } = require('@primer/react/experimental')
// Removed dynamic import of UnderlinePanels

Copilot uses AI. Check for mistakes.

if (mrDetail && typeof mrDetail.status === 'string') {
mrDetail.status = mrDetail.status.toLowerCase();
Expand Down