Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking that there is indeed a selection before scrolling #257

Merged
merged 11 commits into from
Feb 20, 2024
Prev Previous commit
Next Next commit
Only scrolling if selection was done programatically
  • Loading branch information
guzmanvig committed Feb 14, 2024
commit b984f49bda390d8bd81c7d6b9f3a0bc26c8b9584
27 changes: 11 additions & 16 deletions src/SeqViewerContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ interface SeqViewerContainerProps {
rotateOnScroll: boolean;
search: NameRange[];
selectAllEvent: (event: React.KeyboardEvent<HTMLElement>) => boolean;
selection?: {
clockwise?: boolean;
end: number;
start: number;
};
selection?: Selection;
seq: string;
seqType: SeqType;
showComplement: boolean;
Expand Down Expand Up @@ -91,13 +87,16 @@ class SeqViewerContainer extends React.Component<SeqViewerContainerProps, SeqVie
};
}

// If the selection prop updates, also scroll the lineaer view to the new selection
// If the selection prop updates, also scroll the linear view to the new selection
componentDidUpdate = (prevProps: SeqViewerContainerProps) => {
if (
this.props.selection?.start !== prevProps.selection?.start &&
this.props.selection?.start !== this.props.selection?.end
) {
this.setCentralIndex("LINEAR", this.props.selection?.start || 0);
// Only scroll if the selection was done programatically, i.e.: has no type.
if (!this.props.selection?.type) {
if (
this.props.selection?.start !== prevProps.selection?.start &&
this.props.selection?.start !== this.props.selection?.end
) {
this.setCentralIndex("LINEAR", this.props.selection?.start || 0);
}
}
};

Expand Down Expand Up @@ -135,11 +134,7 @@ class SeqViewerContainer extends React.Component<SeqViewerContainerProps, SeqVie
*/
getSelection = (
state: Selection,
prop?: {
clockwise?: boolean;
end: number;
start: number;
}
prop?: Selection
): Selection => {
if (prop) {
return { ...prop, clockwise: typeof prop.clockwise === "undefined" || !!prop.clockwise, type: "" };
Expand Down
Loading