Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/actions/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ export function selectSource(id: string, options: SelectSourceOptions = {}) {
}

let source = getSource(getState(), id);

if (!source) {
// If there is no source we deselect the current selected source
return dispatch({ type: "CLEAR_SELECTED_SOURCE" });
Expand Down Expand Up @@ -229,6 +228,14 @@ export function jumpToMappedLocation(sourceLocation: any) {
};
}

export function moveTab(url: string, tabIndex: number) {
return {
type: "MOVE_TAB",
url,
tabIndex
};
}

/**
* @memberof actions/sources
* @static
Expand Down
3 changes: 2 additions & 1 deletion src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ type SourceAction =
frames: Frame[]
}
}
| { type: "MOVE_TAB", url: string, tabIndex: number }
| { type: "CLOSE_TAB", url: string, tabs: any }
| { type: "CLOSE_TABS", urls: Array<string>, tabs: any };
| { type: "CLOSE_TABS", urls: string[], tabs: any };

export type panelPositionType = "start" | "end";

Expand Down
9 changes: 5 additions & 4 deletions src/components/Editor/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class SourceTabs extends PureComponent {
sourceTabs: SourcesList,
selectedSource: SourceRecord,
selectSource: (string, ?Object) => any,
moveTab: (string, number) => any,
closeTab: string => any,
closeTabs: (List<string>) => any,
toggleProjectSearch: () => any,
Expand Down Expand Up @@ -286,12 +287,12 @@ class SourceTabs extends PureComponent {
if (!this.refs.sourceTabs) {
return;
}
const { selectedSource, sourceTabs, selectSource } = this.props;
const { selectedSource, sourceTabs, moveTab } = this.props;
const sourceTabEls = this.refs.sourceTabs.children;
const hiddenSourceTabs = getHiddenTabs(sourceTabs, sourceTabEls);

if (hiddenSourceTabs.indexOf(selectedSource) !== -1) {
return selectSource(selectedSource.get("id"), { tabIndex: 0 });
return moveTab(selectedSource.get("url"), 0);
}

this.setState({ hiddenSourceTabs });
Expand All @@ -304,7 +305,7 @@ class SourceTabs extends PureComponent {
}

renderDropdownSource(source: SourceRecord) {
const { selectSource } = this.props;
const { moveTab } = this.props;
const filename = getFilename(source.toJS());

return dom.li(
Expand All @@ -313,7 +314,7 @@ class SourceTabs extends PureComponent {
onClick: () => {
// const tabIndex = getLastVisibleTabIndex(sourceTabs, sourceTabEls);
const tabIndex = 0;
selectSource(source.get("id"), { tabIndex });
moveTab(source.get("url"), tabIndex);
}
},
filename
Expand Down
21 changes: 11 additions & 10 deletions src/components/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import {
shouldShowFooter,
clearLineClass,
createEditor,
isTextForSource,
breakpointAtLocation,
getTextForLine,
getCursorLine,
Expand Down Expand Up @@ -134,7 +133,7 @@ class Editor extends PureComponent {
componentWillReceiveProps(nextProps) {
// This lifecycle method is responsible for updating the editor
// text.
const { sourceText, selectedLocation } = nextProps;
const { selectedSource, selectedLocation } = nextProps;
this.clearDebugLine(this.props.selectedFrame);

if (
Expand All @@ -144,14 +143,16 @@ class Editor extends PureComponent {
this.editor.codeMirror.setSize();
}

if (!sourceText) {
if (this.props.sourceText) {
if (!selectedSource) {
if (this.props.selectedSource) {
this.showMessage("");
}
} else if (!isTextForSource(sourceText)) {
this.showMessage(sourceText.get("error") || L10N.getStr("loadingText"));
} else if (this.props.sourceText !== sourceText) {
this.showSourceText(sourceText, selectedLocation);
} else if (selectedSource.get("loading")) {
this.showMessage(L10N.getStr("loadingText"));
} else if (selectedSource.get("error")) {
this.showMessage(selectedSource.get("error"));
} else if (this.props.selectedSource !== selectedSource) {
this.showSourceText(selectedSource, selectedLocation);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided to drop some sourceText refs while i was here

}

if (this.props.outOfScopeLocations !== nextProps.outOfScopeLocations) {
Expand Down Expand Up @@ -258,7 +259,7 @@ class Editor extends PureComponent {
// This is in `componentDidUpdate` so helper functions can expect
// `this.props` to be the current props. This lifecycle method is
// responsible for updating the editor annotations.
const { selectedLocation } = this.props;
const { selectedLocation, selectedSource } = this.props;

// If the location is different and a new line is requested,
// update the pending jump line. Note that if jumping to a line in
Expand All @@ -275,7 +276,7 @@ class Editor extends PureComponent {
// Only update and jump around in real source texts. This will
// keep the jump state around until the real source text is
// loaded.
if (this.props.sourceText && isTextForSource(this.props.sourceText)) {
if (selectedSource && selectedSource.has("text")) {
this.highlightLine();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/components/stories/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function TabsFactory(options, { dir = "ltr", theme = "light" } = {}) {
searchOn: false,
selectedSource: null,
selectSource: action("selectSource"),
moveTab: action("moveTab"),
closeTab: action("closeTab"),
closeTabs: action("closeTabs"),
toggleProjectSearch: action("toggleProjectSearch"),
Expand Down
16 changes: 8 additions & 8 deletions src/reducers/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,14 @@ function update(
};

prefs.pendingSelectedLocation = location;

return state
.set("selectedLocation", {
sourceId: action.source.id,
line: action.line
})
.set("pendingSelectedLocation", location)
.merge({
tabs: updateTabList(
{ sources: state },
action.source.url,
action.tabIndex
)
tabs: updateTabList({ sources: state }, action.source.url)
});

case "CLEAR_SELECTED_SOURCE":
Expand All @@ -116,6 +111,11 @@ function update(
prefs.pendingSelectedLocation = location;
return state.set("pendingSelectedLocation", location);

case "MOVE_TAB":
return state.merge({
tabs: updateTabList({ sources: state }, action.url, action.tabIndex)
});

case "CLOSE_TAB":
prefs.tabs = action.tabs;
return state.merge({ tabs: action.tabs });
Expand Down Expand Up @@ -154,9 +154,9 @@ function getTextPropsFromAction(action: any) {
const sourceText = action.value;

if (action.status === "start") {
return { loading: true };
return { id: source.id, loading: true };
} else if (action.status === "error") {
return { error: action.error, loading: false };
return { id: source.id, error: action.error, loading: false };

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixes a bug where source wasn't getting these field because it couldn't merge w/o an id

}
return {
text: sourceText.text,
Expand Down
5 changes: 0 additions & 5 deletions src/utils/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ function shouldShowFooter(selectedSource, horizontal) {
return shouldShowPrettyPrint(selectedSource);
}

function isTextForSource(sourceText) {
return !sourceText.get("loading") && !sourceText.get("error");
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method was not helpful :)

function breakpointAtLocation(breakpoints, { line, column = undefined }) {
return breakpoints.find(bp => {
const sameLine = bp.location.line === line + 1;
Expand Down Expand Up @@ -118,7 +114,6 @@ module.exports = Object.assign(
createEditor,
shouldShowPrettyPrint,
shouldShowFooter,
isTextForSource,
breakpointAtLocation,
traverseResults,
updateDocument
Expand Down