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

Commit 6352752

Browse files
darkwingjasonLaster
authored andcommitted
Add method to select a specific source or location without attempting to detect pretty print (#5767)
1 parent 0308598 commit 6352752

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

src/actions/sources/select.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,60 @@ export function selectLocation(location: Location) {
139139
};
140140
}
141141

142+
/**
143+
* @memberof actions/sources
144+
* @static
145+
*/
146+
export function selectSpecificLocation(location: Location) {
147+
return async ({ dispatch, getState, client }: ThunkArgs) => {
148+
if (!client) {
149+
// No connection, do nothing. This happens when the debugger is
150+
// shut down too fast and it tries to display a default source.
151+
return;
152+
}
153+
154+
const source = getSource(getState(), location.sourceId);
155+
if (!source) {
156+
// If there is no source we deselect the current selected source
157+
return dispatch({ type: "CLEAR_SELECTED_SOURCE" });
158+
}
159+
160+
const activeSearch = getActiveSearch(getState());
161+
if (activeSearch !== "file") {
162+
dispatch(closeActiveSearch());
163+
}
164+
165+
dispatch(addTab(source.toJS(), 0));
166+
167+
dispatch({
168+
type: "SELECT_SOURCE",
169+
source: source.toJS(),
170+
location
171+
});
172+
173+
await dispatch(loadSourceText(source));
174+
const selectedSource = getSelectedSource(getState());
175+
if (!selectedSource) {
176+
return;
177+
}
178+
179+
const sourceId = selectedSource.get("id");
180+
dispatch(setSymbols(sourceId));
181+
dispatch(setOutOfScopeLocations());
182+
};
183+
}
184+
185+
/**
186+
* @memberof actions/sources
187+
* @static
188+
*/
189+
export function selectSpecificSource(sourceId: string) {
190+
return async ({ dispatch }: ThunkArgs) => {
191+
const location = createLocation({ sourceId });
192+
return await dispatch(selectSpecificLocation(location));
193+
};
194+
}
195+
142196
/**
143197
* @memberof actions/sources
144198
* @static

src/components/Editor/Tab.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type SourcesList = List<SourceRecord>;
4040

4141
type Props = {
4242
tabSources: SourcesList,
43-
selectSource: Object => void,
43+
selectSpecificSource: Object => void,
4444
selectedSource: SourceRecord,
4545
closeTab: string => void,
4646
closeTabs: (List<string>) => void,
@@ -150,7 +150,7 @@ class Tab extends PureComponent<Props> {
150150
render() {
151151
const {
152152
selectedSource,
153-
selectSource,
153+
selectSpecificSource,
154154
closeTab,
155155
source,
156156
sourceMetaData
@@ -179,7 +179,7 @@ class Tab extends PureComponent<Props> {
179179
return closeTab(source.url);
180180
}
181181

182-
return selectSource(sourceId);
182+
return selectSpecificSource(sourceId);
183183
}
184184

185185
const className = classnames("source-tab", {

src/components/Editor/Tabs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type SourcesList = List<SourceRecord>;
3131
type Props = {
3232
tabSources: SourcesList,
3333
selectedSource: SourceRecord,
34-
selectSource: Object => void,
34+
selectSpecificSource: Object => void,
3535
moveTab: (string, number) => void,
3636
closeTab: string => void,
3737
togglePaneCollapse: () => void,
@@ -121,7 +121,7 @@ class Tabs extends PureComponent<Props, State> {
121121
}
122122

123123
renderDropdownSource = (source: SourceRecord) => {
124-
const { selectSource } = this.props;
124+
const { selectSpecificSource } = this.props;
125125
const filename = getFilename(source.toJS());
126126

127127
const onClick = () => selectSpecificSource(source.id);

0 commit comments

Comments
 (0)