Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
[Breakpoints] Fix timing issue with showing breakpoints (#7365)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonLaster authored and Jason Laster committed Jan 8, 2019
1 parent 49e1161 commit 4c66252
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 35 deletions.
25 changes: 6 additions & 19 deletions src/components/Editor/Breakpoint.js
Expand Up @@ -52,12 +52,9 @@ class Breakpoint extends PureComponent<Props> {

const sourceId = selectedSource.id;
const line = toEditorLine(sourceId, breakpoint.location.line);
const doc = getDocument(sourceId);

editor.codeMirror.setGutterMarker(
line,
"breakpoints",
makeMarker(breakpoint.disabled)
);
doc.setGutterMarker(line, "breakpoints", makeMarker(breakpoint.disabled));

editor.codeMirror.addLineClass(line, "line", "new-breakpoint");
if (breakpoint.condition) {
Expand All @@ -80,31 +77,21 @@ class Breakpoint extends PureComponent<Props> {
}

componentWillUnmount() {
const { editor, breakpoint, selectedSource } = this.props;

if (!selectedSource) {
return;
}

if (breakpoint.loading) {
const { breakpoint, selectedSource } = this.props;
if (!selectedSource || breakpoint.loading) {
return;
}

const sourceId = selectedSource.id;
const doc = getDocument(sourceId);

if (!doc) {
return;
}

const line = toEditorLine(sourceId, breakpoint.location.line);

// NOTE: when we upgrade codemirror we can use `doc.setGutterMarker`
if (doc.setGutterMarker) {
doc.setGutterMarker(line, "breakpoints", null);
} else {
editor.codeMirror.setGutterMarker(line, "breakpoints", null);
}

doc.setGutterMarker(line, "breakpoints", null);
doc.removeLineClass(line, "line", "new-breakpoint");
doc.removeLineClass(line, "line", "has-condition");
}
Expand Down
11 changes: 1 addition & 10 deletions src/components/Editor/Breakpoints.js
Expand Up @@ -8,7 +8,6 @@ import Breakpoint from "./Breakpoint";

import { getSelectedSource, getFirstVisibleBreakpoints } from "../../selectors";
import { makeLocationId } from "../../utils/breakpoint";
import { isLoaded } from "../../utils/source";
import { connect } from "../../utils/connect";

import type { Breakpoint as BreakpointType, Source } from "../../types";
Expand All @@ -20,18 +19,10 @@ type Props = {
};

class Breakpoints extends Component<Props> {
shouldComponentUpdate(nextProps: Props) {
if (nextProps.selectedSource && !isLoaded(nextProps.selectedSource)) {
return false;
}

return true;
}

render() {
const { breakpoints, selectedSource, editor } = this.props;

if (!selectedSource || !breakpoints || selectedSource.isBlackBoxed) {
if (!breakpoints || selectedSource.isBlackBoxed) {
return null;
}

Expand Down
21 changes: 16 additions & 5 deletions src/components/Editor/HighlightLine.js
Expand Up @@ -54,6 +54,14 @@ export class HighlightLine extends Component<Props> {
return this.shouldSetHighlightLine(selectedLocation, selectedSource);
}

componentDidUpdate(prevProps: Props) {
this.completeHighlightLine(prevProps);
}

componentDidMount() {
this.completeHighlightLine(null);
}

shouldSetHighlightLine(
selectedLocation: SourceLocation,
selectedSource: Source
Expand All @@ -72,7 +80,7 @@ export class HighlightLine extends Component<Props> {
return true;
}

componentDidUpdate(prevProps: Props) {
completeHighlightLine(prevProps: Props | null) {
const {
pauseCommand,
selectedLocation,
Expand All @@ -84,10 +92,12 @@ export class HighlightLine extends Component<Props> {
}

startOperation();
this.clearHighlightLine(
prevProps.selectedLocation,
prevProps.selectedSource
);
if (prevProps) {
this.clearHighlightLine(
prevProps.selectedLocation,
prevProps.selectedSource
);
}
this.setHighlightLine(selectedLocation, selectedFrame, selectedSource);
endOperation();
}
Expand All @@ -101,6 +111,7 @@ export class HighlightLine extends Component<Props> {
if (!this.shouldSetHighlightLine(selectedLocation, selectedSource)) {
return;
}

this.isStepping = false;
const editorLine = toEditorLine(sourceId, line);
this.previousEditorLine = editorLine;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/index.js
Expand Up @@ -576,7 +576,7 @@ class Editor extends PureComponent<Props, State> {
const { horizontal, selectedSource, conditionalPanelLocation } = this.props;
const { editor } = this.state;

if (!editor || !selectedSource) {
if (!selectedSource || !editor || !getDocument(selectedSource.id)) {
return null;
}

Expand Down

0 comments on commit 4c66252

Please sign in to comment.