@@ -18,6 +18,7 @@ class Note extends React.PureComponent {
1818 annotation : PropTypes . object . isRequired ,
1919 isNoteEditing : PropTypes . bool . isRequired ,
2020 isNoteExpanded : PropTypes . bool . isRequired ,
21+ isAnnotationFocused : PropTypes . bool ,
2122 setIsNoteEditing : PropTypes . func . isRequired ,
2223 searchInput : PropTypes . string ,
2324 isReadOnly : PropTypes . bool ,
@@ -35,6 +36,7 @@ class Note extends React.PureComponent {
3536 isRootContentEditing : false ,
3637 isReplyFocused : false
3738 } ;
39+ this . containerRef = React . createRef ( ) ;
3840 }
3941
4042 componentDidMount ( ) {
@@ -47,6 +49,7 @@ class Note extends React.PureComponent {
4749 const commentEditable = core . canModify ( annotation ) && ! annotation . getContents ( ) ;
4850 const noteBeingEdited = ! prevProps . isNoteEditing && this . props . isNoteEditing ;
4951 const noteCollapsed = prevProps . isNoteExpanded && ! this . props . isNoteExpanded ;
52+ const annotationWasFocused = ! prevProps . isAnnotationFocused && this . props . isAnnotationFocused ;
5053
5154 if ( noteBeingEdited ) {
5255 if ( commentEditable ) {
@@ -62,6 +65,10 @@ class Note extends React.PureComponent {
6265 isReplyFocused : false
6366 } ) ;
6467 }
68+
69+ if ( annotationWasFocused ) {
70+ this . scrollIntoView ( ) ;
71+ }
6572 }
6673
6774 componentWillUnmount ( ) {
@@ -99,6 +106,10 @@ class Note extends React.PureComponent {
99106 }
100107 }
101108
109+ scrollIntoView = ( ) => {
110+ this . containerRef . current . scrollIntoView ( ) ;
111+ }
112+
102113 openRootEditing = ( ) => {
103114 this . setState ( { isRootContentEditing : true } ) ;
104115 }
@@ -205,7 +216,7 @@ class Note extends React.PureComponent {
205216 ] . join ( ' ' ) . trim ( ) ;
206217
207218 return (
208- < div className = { className } onClick = { this . onClickNote } >
219+ < div ref = { this . containerRef } className = { className } onClick = { this . onClickNote } >
209220 < NoteRoot
210221 annotation = { annotation }
211222 contents = { rootContents }
@@ -256,6 +267,7 @@ class Note extends React.PureComponent {
256267const mapStateToProps = ( state , ownProps ) => ( {
257268 isNoteExpanded : selectors . isNoteExpanded ( state , ownProps . annotation . Id ) ,
258269 isNoteEditing : selectors . isNoteEditing ( state , ownProps . annotation . Id ) ,
270+ isAnnotationFocused : selectors . isAnnotationFocused ( state , ownProps . annotation . Id ) ,
259271 isReadOnly : selectors . isDocumentReadOnly ( state ) ,
260272 isReplyDisabled : selectors . isElementDisabled ( state , 'noteReply' )
261273} ) ;
0 commit comments