forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a GotoLineModal (firefox-devtools#4323)
This commit adds a gotoline modal/functionality triggered with `Cmd+:` (`CtrlOrCmd+Shift+;`) in the main debugger source window. A string that cannot be `parseInt()`'d is a noop. A number higher than the number of lines in the file will go to the end of the file.
- Loading branch information
Showing
4 changed files
with
186 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// @flow | ||
|
||
import React, { Component } from "react"; | ||
import { connect } from "react-redux"; | ||
import { bindActionCreators } from "redux"; | ||
import { getActiveSearch, getSelectedSource } from "../selectors"; | ||
import actions from "../actions"; | ||
|
||
import Modal from "./shared/Modal"; | ||
|
||
import SearchInput from "./shared/SearchInput"; | ||
|
||
import type { SourceRecord } from "../reducers/sources"; | ||
import type { SelectSourceOptions } from "../actions/sources"; | ||
|
||
type GotoLineModalState = { | ||
query: ?string | ||
}; | ||
|
||
import "./SymbolModal.css"; | ||
|
||
class GotoLineModal extends Component { | ||
state: GotoLineModalState; | ||
|
||
props: { | ||
enabled: boolean, | ||
selectSource: (string, ?SelectSourceOptions) => void, | ||
selectedSource?: SourceRecord, | ||
closeActiveSearch: () => void, | ||
highlightLineRange: ({ start: number, end: number }) => void, | ||
clearHighlightLineRange: () => void | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { query: "" }; | ||
} | ||
|
||
onClick = (e: SyntheticEvent) => { | ||
e.stopPropagation(); | ||
}; | ||
|
||
onChange = (e: SyntheticInputEvent) => { | ||
const { selectedSource } = this.props; | ||
if (!selectedSource || !selectedSource.get("text")) { | ||
return; | ||
} | ||
|
||
this.setState({ query: e.target.value }); | ||
}; | ||
|
||
closeModal = () => { | ||
this.props.closeActiveSearch(); | ||
this.props.clearHighlightLineRange(); | ||
}; | ||
|
||
onKeyUp = (e: SyntheticKeyboardEvent) => { | ||
e.preventDefault(); | ||
const { selectSource, selectedSource, enabled } = this.props; | ||
const { query } = this.state; | ||
|
||
if (!enabled || !selectedSource) { | ||
return; | ||
} | ||
|
||
if (e.key === "Enter" && query != null) { | ||
const linenumber = parseInt(query.replace(/[^\d+]/g, ""), 10); | ||
if (!isNaN(linenumber)) { | ||
selectSource(selectedSource.get("id"), { line: linenumber }); | ||
} | ||
this.closeModal(); | ||
return; | ||
} | ||
|
||
if (e.key === "Tab") { | ||
this.closeModal(); | ||
return; | ||
} | ||
return; | ||
}; | ||
|
||
renderInput() { | ||
const { query } = this.state; | ||
|
||
return ( | ||
<div key="input" className="input-wrapper"> | ||
<SearchInput | ||
query={query} | ||
placeholder={this.buildPlaceHolder()} | ||
onChange={this.onChange} | ||
onKeyUp={this.onKeyUp} | ||
handleClose={this.closeModal} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
buildPlaceHolder = () => L10N.getFormatStr("gotoLineModal.placeholder"); | ||
|
||
render() { | ||
const { enabled } = this.props; | ||
|
||
if (!enabled) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Modal in={enabled} handleClose={this.closeModal}> | ||
{this.renderInput()} | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
state => { | ||
const source = getSelectedSource(state); | ||
return { | ||
enabled: Boolean(getActiveSearch(state) === "line" && source) | ||
}; | ||
}, | ||
dispatch => bindActionCreators(actions, dispatch) | ||
)(GotoLineModal); |
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