Skip to content
Closed
Changes from 1 commit
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
36 changes: 35 additions & 1 deletion packages/editor/src/components/collab-sidebar/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ export function Comments( {
reflowComments,
isFloating = false,
commentLastUpdated,
onClearSelection,
} ) {
const [ heights, setHeights ] = useState( {} );
const [ selectedThread, setSelectedThread ] = useState( null );
const [ boardOffsets, setBoardOffsets ] = useState( {} );
const [ blockRefs, setBlockRefs ] = useState( {} );

const { setCanvasMinHeight } = unlock( useDispatch( editorStore ) );
const { toggleBlockSpotlight } = unlock( useDispatch( blockEditorStore ) );
const { blockCommentId, selectedBlockClientId, orderedBlockIds } =
useSelect( ( select ) => {
const {
Expand Down Expand Up @@ -124,6 +126,28 @@ export function Comments( {
orderedBlockIds,
] );

// Clear selection and block spotlights when clicking outside notes.
const clearSelection = useCallback( () => {
if ( selectedThread ) {
// Find the thread that was selected to clear its spotlight.
const selectedThreadData = threads.find(
( t ) => t.id === selectedThread
);
if ( selectedThreadData?.blockClientId ) {
toggleBlockSpotlight( selectedThreadData.blockClientId, false );
}
}
setSelectedThread( null );
setNewNoteFormState( 'closed' );
}, [ selectedThread, threads, toggleBlockSpotlight, setNewNoteFormState ] );

// Expose clearSelection to parent component via callback.
useEffect( () => {
if ( onClearSelection ) {
onClearSelection( clearSelection );
}
}, [ clearSelection, onClearSelection ] );

const handleDelete = async ( comment ) => {
const currentIndex = threads.findIndex( ( t ) => t.id === comment.id );
const nextThread = threads[ currentIndex + 1 ];
Expand Down Expand Up @@ -463,7 +487,17 @@ function Thread( {
onMouseEnter={ onMouseEnter }
onMouseLeave={ onMouseLeave }
onFocus={ onMouseEnter }
onBlur={ onMouseLeave }
onBlur={ ( event ) => {
onMouseLeave();
// Collapse note when focus moves away from the thread.
if (
isSelected &&
event.relatedTarget &&
! event.currentTarget.contains( event.relatedTarget )
) {
unselectThread();
}
} }
onKeyDown={ ( event ) => {
if ( event.defaultPrevented ) {
return;
Expand Down
Loading