This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 758
Fix tabs reselect #2799
Merged
jasonLaster
merged 4 commits into
firefox-devtools:master
from
jasonLaster:fix-tabs-reselect
May 3, 2017
Merged
Fix tabs reselect #2799
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
// @flow | ||
|
||
import { DOM as dom, PropTypes, PureComponent, createFactory } from "react"; | ||
import ImPropTypes from "react-immutable-proptypes"; | ||
import { DOM as dom, PureComponent, createFactory } from "react"; | ||
import { connect } from "react-redux"; | ||
import { bindActionCreators } from "redux"; | ||
import * as I from "immutable"; | ||
|
||
import { | ||
getSelectedSource, | ||
getSourcesForTabs, | ||
|
@@ -25,6 +26,10 @@ const PaneToggleButton = createFactory(_PaneToggleButton); | |
import _Dropdown from "../shared/Dropdown"; | ||
const Dropdown = createFactory(_Dropdown); | ||
|
||
import type { List } from "immutable"; | ||
import type { SourceRecord } from "../../reducers/sources"; | ||
type SourcesList = List<SourceRecord>; | ||
|
||
/* | ||
* Finds the hidden tabs by comparing the tabs' top offset. | ||
* hidden tabs will have a great top offset. | ||
|
@@ -34,7 +39,7 @@ const Dropdown = createFactory(_Dropdown); | |
* | ||
* @returns Immutable.list | ||
*/ | ||
function getHiddenTabs(sourceTabs, sourceTabEls) { | ||
function getHiddenTabs(sourceTabs: SourcesList, sourceTabEls) { | ||
sourceTabEls = [].slice.call(sourceTabEls); | ||
function getTopOffset() { | ||
const topOffsets = sourceTabEls.map(t => t.getBoundingClientRect().top); | ||
|
@@ -66,7 +71,7 @@ function copyToTheClipboard(string) { | |
|
||
type State = { | ||
dropdownShown: boolean, | ||
hiddenSourceTabs: Array<Object> | null | ||
hiddenSourceTabs: SourcesList | ||
}; | ||
|
||
class SourceTabs extends PureComponent { | ||
|
@@ -82,13 +87,29 @@ class SourceTabs extends PureComponent { | |
renderDropDown: Function; | ||
renderStartPanelToggleButton: Function; | ||
renderEndPanelToggleButton: Function; | ||
|
||
props: { | ||
sourceTabs: SourcesList, | ||
selectedSource: SourceRecord, | ||
selectSource: (string, ?Object) => any, | ||
closeTab: string => any, | ||
closeTabs: List<string> => any, | ||
toggleProjectSearch: () => any, | ||
togglePrettyPrint: string => any, | ||
togglePaneCollapse: () => any, | ||
showSource: string => any, | ||
horizontal: boolean, | ||
startPanelCollapsed: boolean, | ||
endPanelCollapsed: boolean | ||
}; | ||
|
||
onResize: Function; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
dropdownShown: false, | ||
hiddenSourceTabs: null | ||
hiddenSourceTabs: I.List() | ||
}; | ||
|
||
this.onTabContextMenu = this.onTabContextMenu.bind(this); | ||
|
@@ -127,7 +148,7 @@ class SourceTabs extends PureComponent { | |
window.removeEventListener("resize", this.onResize); | ||
} | ||
|
||
onTabContextMenu(event, tab) { | ||
onTabContextMenu(event, tab: string) { | ||
event.preventDefault(); | ||
this.showContextMenu(event, tab); | ||
} | ||
|
@@ -166,6 +187,11 @@ class SourceTabs extends PureComponent { | |
const sourceTab = sourceTabs.find(t => t.get("id") == tab); | ||
const tabURLs = sourceTabs.map(thisTab => thisTab.get("url")); | ||
const otherTabURLs = otherTabs.map(thisTab => thisTab.get("url")); | ||
|
||
if (!sourceTab) { | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. flow doesn't know that we'll have a source in the tab list... |
||
|
||
const isPrettySource = isPretty(sourceTab.toJS()); | ||
|
||
const closeTabMenuItem = { | ||
|
@@ -272,7 +298,7 @@ class SourceTabs extends PureComponent { | |
}); | ||
} | ||
|
||
renderDropdownSource(source) { | ||
renderDropdownSource(source: SourceRecord) { | ||
const { selectSource } = this.props; | ||
const filename = getFilename(source.toJS()); | ||
|
||
|
@@ -291,13 +317,17 @@ class SourceTabs extends PureComponent { | |
|
||
renderTabs() { | ||
const sourceTabs = this.props.sourceTabs; | ||
if (!sourceTabs) { | ||
return; | ||
} | ||
|
||
return dom.div( | ||
{ className: "source-tabs", ref: "sourceTabs" }, | ||
sourceTabs.map(this.renderTab) | ||
); | ||
} | ||
|
||
renderTab(source) { | ||
renderTab(source: SourceRecord) { | ||
const { selectedSource, selectSource, closeTab } = this.props; | ||
const filename = getFilename(source.toJS()); | ||
const active = | ||
|
@@ -400,21 +430,6 @@ class SourceTabs extends PureComponent { | |
} | ||
} | ||
|
||
SourceTabs.propTypes = { | ||
sourceTabs: ImPropTypes.list.isRequired, | ||
selectedSource: ImPropTypes.map, | ||
selectSource: PropTypes.func.isRequired, | ||
closeTab: PropTypes.func.isRequired, | ||
closeTabs: PropTypes.func.isRequired, | ||
toggleProjectSearch: PropTypes.func.isRequired, | ||
togglePrettyPrint: PropTypes.func.isRequired, | ||
togglePaneCollapse: PropTypes.func.isRequired, | ||
showSource: PropTypes.func.isRequired, | ||
horizontal: PropTypes.bool.isRequired, | ||
startPanelCollapsed: PropTypes.bool.isRequired, | ||
endPanelCollapsed: PropTypes.bool.isRequired | ||
}; | ||
|
||
SourceTabs.displayName = "SourceTabs"; | ||
|
||
module.exports = connect( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switches from proptypes to props