Skip to content

Commit

Permalink
Merge pull request #253 from Lattice-Automation/scroll-to-selection
Browse files Browse the repository at this point in the history
Linear view scrolls to selection when passed by prop
  • Loading branch information
guzmanvig authored Jan 11, 2024
2 parents ea558f2 + 06015f7 commit a806197
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/SeqViewerContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,20 @@ class SeqViewerContainer extends React.Component<SeqViewerContainerProps, SeqVie
this.state = {
centralIndex: {
circular: 0,
linear: 0,
linear: props?.selection?.start || 0,
setCentralIndex: this.setCentralIndex,
},
selection: this.getSelection(defaultSelection, props.selection),
};
}

// If the selection prop updates, also scroll the lineaer view to the new selection
componentDidUpdate = (prevProps: SeqViewerContainerProps) => {
if (this.props.selection?.start !== prevProps.selection?.start) {
this.setCentralIndex("LINEAR", this.props.selection?.start || 0);
}
};

/** this is here because the size listener is returning a new "size" prop every time */
shouldComponentUpdate = (nextProps: SeqViewerContainerProps, nextState: any) =>
!isEqual(nextProps, this.props) || !isEqual(nextState, this.state);
Expand Down

0 comments on commit a806197

Please sign in to comment.