diff --git a/packages/ui/src/components/comments/InlineCommentCard.tsx b/packages/ui/src/components/comments/InlineCommentCard.tsx index 4a892abc..f60c510e 100644 --- a/packages/ui/src/components/comments/InlineCommentCard.tsx +++ b/packages/ui/src/components/comments/InlineCommentCard.tsx @@ -36,7 +36,7 @@ export function InlineCommentCard({ return (
lineCount) return undefined; - - const line = view.state.doc.line(lineNumber); - const coords = view.coordsAtPos(line.from); - if (!coords) return undefined; - - const wrapperRect = wrapper.getBoundingClientRect(); - if (position === 'bottom') { - return coords.bottom - wrapperRect.top; - } - return coords.top - wrapperRect.top; -} - -function shouldFlipUp(view: EditorView, endLine: number, scrollContainer: HTMLElement | null): boolean { - const lineCount = view.state.doc.lines; - if (endLine < 1 || endLine > lineCount) return false; - - const line = view.state.doc.line(endLine); - const coords = view.coordsAtPos(line.from); - if (!coords) return false; - - const viewportBottom = scrollContainer - ? scrollContainer.getBoundingClientRect().bottom - : window.innerHeight; - - return (coords.bottom + COMMENT_POPOVER_HEIGHT + 30) > viewportBottom; -} - -function computePosition( - view: EditorView, - wrapper: HTMLElement, - scrollContainer: HTMLElement | null, - range: { start: number; end: number }, -): CommentPos | undefined { - const flipUp = shouldFlipUp(view, range.end, scrollContainer); - - const top = flipUp - ? getLineTop(view, wrapper, range.start, 'top') - : getLineTop(view, wrapper, range.end, 'bottom'); - - if (top === undefined) return undefined; - return { top, flipUp }; -} - -type FloatingCommentsProps = { - editorView: EditorView | null; - wrapperRef: React.RefObject; - fileDrafts: InlineCommentDraft[]; - editingDraftId: string | null; - commentText: string; - lineSelection: SelectedLineRange | null; - isDragging: boolean; - fileLabel: string; - onSaveComment: (text: string, range?: SelectedLineRange) => void; - onCancelComment: () => void; - onEditDraft: (draft: InlineCommentDraft) => void; - onDeleteDraft: (draft: InlineCommentDraft) => void; -}; - -export function useFloatingComments({ - editorView, - wrapperRef, - fileDrafts, - editingDraftId, - commentText, - lineSelection, - isDragging, - fileLabel, - onSaveComment, - onCancelComment, - onEditDraft, - onDeleteDraft, -}: FloatingCommentsProps): React.ReactNode { - const [positions, setPositions] = React.useState>({}); - - const updatePositions = React.useCallback(() => { - const view = editorView; - const wrapper = wrapperRef.current; - if (!view || !wrapper) return; - - const scrollContainer = wrapper.closest('.overlay-scrollbar-container') as HTMLElement | null; - const next: Record = {}; - - for (const d of fileDrafts) { - next[d.id] = computePosition(view, wrapper, scrollContainer, { - start: d.startLine, - end: d.endLine, - }); - } - - if (lineSelection && !editingDraftId && !isDragging) { - next['__new__'] = computePosition(view, wrapper, scrollContainer, { - start: lineSelection.start, - end: lineSelection.end, - }); - } - - setPositions(next); - }, [editorView, wrapperRef, fileDrafts, editingDraftId, lineSelection, isDragging]); - - React.useEffect(() => { - requestAnimationFrame(updatePositions); - }, [updatePositions]); - - // Also update on scroll - React.useEffect(() => { - const wrapper = wrapperRef.current; - if (!wrapper) return; - - const scrollContainer = wrapper.closest('.overlay-scrollbar-container') as HTMLElement | null; - if (!scrollContainer) return; - - const onScroll = () => requestAnimationFrame(updatePositions); - scrollContainer.addEventListener('scroll', onScroll, { passive: true }); - return () => scrollContainer.removeEventListener('scroll', onScroll); - }, [wrapperRef, updatePositions]); - - const popoverStyle = (flipUp: boolean): React.CSSProperties => flipUp - ? { position: 'absolute', bottom: 'calc(100% + 4px)', right: -8, zIndex: 40, width: 380, maxWidth: 'min(380px, calc(100vw - 48px))', borderRadius: 14 } - : { position: 'absolute', top: 'calc(100% + 4px)', right: -8, zIndex: 40, width: 380, maxWidth: 'min(380px, calc(100vw - 48px))', borderRadius: 14 }; - - return ( - <> - {fileDrafts.map((d) => { - const pos = positions[d.id]; - if (!pos) return null; - - if (d.id === editingDraftId) { - return ( -
-
- -
-
- ); - } - - return ( -
- onEditDraft(d)} - onDelete={() => onDeleteDraft(d)} - /> -
- ); - })} - - {lineSelection && !editingDraftId && !isDragging && positions['__new__'] && ( -
-
- -
-
- )} - - ); -} diff --git a/packages/ui/src/components/layout/ContextPanel.tsx b/packages/ui/src/components/layout/ContextPanel.tsx index 93cbf102..8eb8980f 100644 --- a/packages/ui/src/components/layout/ContextPanel.tsx +++ b/packages/ui/src/components/layout/ContextPanel.tsx @@ -194,6 +194,17 @@ export const ContextPanel: React.FC = () => { return null; } + const panelStyle: React.CSSProperties = isExpanded + ? { + ['--oc-context-panel-width' as string]: '100vw', + } + : { + width: `${width}px`, + minWidth: `${width}px`, + maxWidth: `${width}px`, + ['--oc-context-panel-width' as string]: `${width}px`, + }; + return (