Skip to content

Commit 16b60ad

Browse files
committed
add hotkey
1 parent aa71251 commit 16b60ad

5 files changed

Lines changed: 34 additions & 6 deletions

File tree

browser/main/Components/BlueprintForm.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ var BlueprintForm = React.createClass({
9191
PlanetActions.updateBlueprint(blueprintId, blueprint)
9292
}
9393
},
94+
handleKeyDown: function (e) {
95+
if (e.keyCode === 13 && e.metaKey) {
96+
this.submit()
97+
}
98+
},
9499
render: function () {
95100
var content = this.state.mode === BlueprintForm.EDIT_MODE ? (
96101
<div className='form-group'>
@@ -104,7 +109,7 @@ var BlueprintForm = React.createClass({
104109
)
105110

106111
return (
107-
<div className='BlueprintForm'>
112+
<div onKeyDown={this.handleKeyDown} className='BlueprintForm'>
108113
<div className='modal-body'>
109114
<div className='form-group'>
110115
<input ref='title' className='block-input' valueLink={this.linkState('blueprint.title')} placeholder='Title'/>

browser/main/Components/LaunchModal.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,20 @@ var LaunchModal = React.createClass({
4040
this.setState({currentTab: 'blueprint'})
4141
},
4242
submit: function () {
43-
// this.props.submit('yolo')
4443
if (this.state.currentTab === 'snippet') {
4544
console.log(this.state.snippet)
4645
} else {
4746
console.log(this.state.blueprint)
4847
}
4948
},
49+
handleKeyDown: function (e) {
50+
if (e.keyCode === 37 && e.metaKey) {
51+
this.selectSnippetTab()
52+
}
53+
if (e.keyCode === 39 && e.metaKey) {
54+
this.selectBlueprintTab()
55+
}
56+
},
5057
render: function () {
5158
var modalBody
5259
if (this.state.currentTab === 'snippet') {
@@ -60,7 +67,7 @@ var LaunchModal = React.createClass({
6067
}
6168

6269
return (
63-
<div onClick={this.stopPropagation} className='LaunchModal modal'>
70+
<div onKeyDown={this.handleKeyDown} onClick={this.stopPropagation} className='LaunchModal modal'>
6471
<div className='modal-header'>
6572
<div className='modal-tab'>
6673
<button className={this.state.currentTab === 'snippet' ? 'btn-primary active' : 'btn-default'} onClick={this.selectSnippetTab}>Snippet</button><button className={this.state.currentTab === 'blueprint' ? 'btn-primary active' : 'btn-default'} onClick={this.selectBlueprintTab}>Blueprint</button>

browser/main/Components/PlanetNavigator.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,19 @@ var PlanetNavigator = React.createClass({
1717
isLaunchModalOpen: false
1818
}
1919
},
20+
handleKeyDown: function (e) {
21+
if (e.keyCode === 13 && e.metaKey) {
22+
e.preventDefault()
23+
this.openLaunchModal()
24+
}
25+
},
26+
componentDidMount: function () {
27+
document.addEventListener('keydown', this.handleKeyDown, false)
28+
},
29+
componentWillUnmount: function () {
30+
document.removeEventListener('keydown', this.handleKeyDown, false)
31+
},
2032
openLaunchModal: function () {
21-
console.log('and...OPEN!!')
2233
this.setState({isLaunchModalOpen: true})
2334
},
2435
closeLaunchModal: function () {

browser/main/Components/SnippetForm.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,14 @@ var SnippetForm = React.createClass({
8383
PlanetActions.updateSnippet(snippetId, snippet)
8484
}
8585
},
86+
handleKeyDown: function (e) {
87+
if (e.keyCode === 13 && e.metaKey) {
88+
this.submit()
89+
}
90+
},
8691
render: function () {
8792
return (
88-
<div className='SnippetForm'>
93+
<div onKeyDown={this.handleKeyDown} className='SnippetForm'>
8994
<div className='modal-body'>
9095
<div className='form-group'>
9196
<textarea ref='description' className='snippetDescription block-input' valueLink={this.linkState('snippet.description')} placeholder='Description'/>

browser/main/Containers/PlanetContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module.exports = React.createClass({
7878

7979
var index = this.getIndexOfCurrentArticle()
8080

81-
if (index < this.state.filteredArticles.length) {
81+
if (index < this.state.filteredArticles.length - 1) {
8282
this.selectArticleByIndex(index + 1)
8383
}
8484
},

0 commit comments

Comments
 (0)