Skip to content

Adds shortcuts #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 21, 2017
25 changes: 24 additions & 1 deletion browser/components/MarkdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ class MarkdownEditor extends React.Component {
constructor (props) {
super(props)

this.hotkey = props.config.hotkey

this.state = {
status: 'PREVIEW',
renderValue: props.value
renderValue: props.value,
keyPressed: {}
}
}

Expand Down Expand Up @@ -142,6 +145,24 @@ class MarkdownEditor extends React.Component {
this.renderPreview(this.props.value)
}

handleKeyDown(e) {
const keyPressed = Object.assign(this.state.keyPressed, {
[e.key]: true
})
this.setState({ keyPressed })
let isNoteHandlerKey = (el) => { return this.state.keyPressed[el] }
if (this.state.status === 'CODE' && this.hotkey.noteHandlerKey.escapeFromEditor.every(isNoteHandlerKey)) {
document.activeElement.blur()
}
}

handleKeyUp (e) {
const keyPressed = Object.assign(this.state.keyPressed, {
[e.key]: false
})
this.setState({ keyPressed })
}

render () {
let { className, value, config } = this.props

Expand All @@ -160,6 +181,8 @@ class MarkdownEditor extends React.Component {
}
onContextMenu={(e) => this.handleContextMenu(e)}
tabIndex='-1'
onKeyDown={(e) => this.handleKeyDown(e)}
onKeyUp={(e) => this.handleKeyUp(e)}
>
<CodeEditor styleName='codeEditor'
ref='code'
Expand Down
14 changes: 14 additions & 0 deletions browser/main/TopBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ class TopBar extends React.Component {
this.newNoteHandler = () => {
this.handleNewPostButtonClick()
}

this.focusSearchHandler = () => {
this.handleOnSearchFocus()
}
}

componentDidMount () {
ee.on('top:new-note', this.newNoteHandler)
ee.on('top:focus-search', this.focusSearchHandler)
}

componentWillUnmount () {
ee.off('top:new-note', this.newNoteHandler)
ee.off('top:focus-search', this.focusSearchHandler)
}

handleNewPostButtonClick (e) {
Expand Down Expand Up @@ -244,6 +250,14 @@ class TopBar extends React.Component {
})
}

handleOnSearchFocus () {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

if (this.state.searchPopupOpen) {
this.refs.search.childNodes[0].blur()
} else {
this.refs.search.childNodes[0].focus()
}
}

render () {
let { config, style, data } = this.props
let searchOptionList = this.getOptions()
Expand Down
5 changes: 4 additions & 1 deletion browser/main/lib/ConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export const DEFAULT_CONFIG = {
listStyle: 'DEFAULT', // 'DEFAULT', 'SMALL'
hotkey: {
toggleFinder: OSX ? 'Cmd + Alt + S' : 'Super + Alt + S',
toggleMain: OSX ? 'Cmd + Alt + L' : 'Super + Alt + E'
toggleMain: OSX ? 'Cmd + Alt + L' : 'Super + Alt + E',
noteHandlerKey: {
escapeFromEditor: ['Control', 'e']
}
},
ui: {
theme: 'default',
Expand Down
1 change: 1 addition & 0 deletions browser/main/modals/PreferencesModal/HotkeyTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class HotkeyTab extends React.Component {
<li><code>Escape</code> (or <code>Esc</code> for short)</li>
<li><code>VolumeUp</code>, <code>VolumeDown</code> and <code>VolumeMute</code></li>
<li><code>MediaNextTrack</code>, <code>MediaPreviousTrack</code>, <code>MediaStop</code> and <code>MediaPlayPause</code></li>
<li><code>Control</code> (or <code>Ctrl</code> for short)</li>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In addition, I added this.

</ul>
</div>
}
Expand Down
34 changes: 34 additions & 0 deletions lib/main-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ var file = {
mainWindow.webContents.send('top:new-note')
}
},
{
label: 'Focus Note',
accelerator: 'Control + E',
click () {
mainWindow.webContents.send('detail:focus')
}
},
{
type: 'separator'
},
Expand Down Expand Up @@ -136,6 +143,33 @@ var view = {
click: function () {
BrowserWindow.getFocusedWindow().toggleDevTools()
}
},
{
type: 'separator'
},
{
label: 'Next Note',
accelerator: 'Control + J',
click () {
mainWindow.webContents.send('list:next')
}
},
{
label: 'Previous Note',
accelerator: 'Control + U',
click () {
mainWindow.webContents.send('list:prior')
}
},
{
type: 'separator'
},
{
label: 'Focus Search',
accelerator: 'Control + S',
click () {
mainWindow.webContents.send('top:focus-search')
}
}
]
}
Expand Down