From ce02064d8afc8673cef83c92896ee873bd35e7ae Mon Sep 17 00:00:00 2001 From: jaril Date: Thu, 31 Oct 2019 03:22:26 +0000 Subject: [PATCH] Bug 1592775 - Fix jumping behavior in frame timeline Differential Revision: https://phabricator.services.mozilla.com/D51182 --HG-- extra : moz-landing-system : lando --- .../SecondaryPanes/FrameTimeline.js | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.js b/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.js index 9dc31220f48e..0f0c818f7589 100644 --- a/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.js +++ b/devtools/client/debugger/src/components/SecondaryPanes/FrameTimeline.js @@ -4,13 +4,16 @@ // @flow -// import PropTypes from "prop-types"; import React, { Component } from "react"; import { isEqual } from "lodash"; import { connect } from "../../utils/connect"; -import { getFramePositions } from "../../selectors"; -import type { SourceLocation } from "../../types"; +import { + getFramePositions, + getSelectedFrame, + getThreadContext, +} from "../../selectors"; +import type { SourceLocation, Frame } from "../../types"; import { getSelectedLocation } from "../../reducers/sources"; @@ -24,6 +27,7 @@ type Props = { selectedLocation: ?SourceLocation, previewLocation: typeof actions.previewPausedLocation, seekToPosition: typeof actions.seekToPosition, + selectedFrame: Frame, }; type OwnProps = {}; @@ -31,6 +35,7 @@ type State = { scrubbing: boolean, percentage: number, displayedLocation: any, + displayedFrame: Frame, }; function isSameLocation( @@ -68,6 +73,7 @@ class FrameTimeline extends Component { scrubbing: false, percentage: 0, displayedLocation: null, + displayedFrame: {}, }; getProgress(clientX: number) { @@ -158,8 +164,16 @@ class FrameTimeline extends Component { }; getProgressForNewFrame() { - const { framePositions, selectedLocation } = this.props; - this.setState({ displayedLocation: selectedLocation }); + const { framePositions, selectedLocation, selectedFrame } = this.props; + this.setState({ + displayedLocation: selectedLocation, + displayedFrame: selectedFrame, + }); + let progress = 0; + + if (!framePositions) { + return progress; + } const displayedPositions = framePositions.filter( point => point.position.kind === "OnStep" @@ -168,8 +182,6 @@ class FrameTimeline extends Component { isSameLocation(pos.location, selectedLocation) ); - let progress = 0; - if (index != -1) { progress = Math.floor((index / displayedPositions.length) * 100); this.setState({ percentage: progress }); @@ -179,12 +191,21 @@ class FrameTimeline extends Component { } getVisibleProgress() { - const { percentage, displayedLocation, scrubbing } = this.state; - const { selectedLocation } = this.props; + const { + percentage, + displayedLocation, + displayedFrame, + scrubbing, + } = this.state; + const { selectedLocation, selectedFrame } = this.props; let progress = percentage; - if (!isEqual(displayedLocation, selectedLocation) && !scrubbing) { + if ( + !isEqual(displayedLocation, selectedLocation) && + displayedFrame.index !== selectedFrame.index && + !scrubbing + ) { progress = this.getProgressForNewFrame(); } @@ -251,9 +272,15 @@ class FrameTimeline extends Component { } const mapStateToProps = state => { + const selectedFrame: Frame = (getSelectedFrame( + state, + getThreadContext(state).thread + ): any); + return { framePositions: getFramePositions(state), selectedLocation: getSelectedLocation(state), + selectedFrame, }; };