diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index e5041565..ad58e00d 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -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: {} } } @@ -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 @@ -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)} > { 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) { @@ -244,6 +250,14 @@ class TopBar extends React.Component { }) } + handleOnSearchFocus () { + 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() diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 1f7ab33d..651d7156 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -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', diff --git a/browser/main/modals/PreferencesModal/HotkeyTab.js b/browser/main/modals/PreferencesModal/HotkeyTab.js index b0005bfd..bbce7c62 100644 --- a/browser/main/modals/PreferencesModal/HotkeyTab.js +++ b/browser/main/modals/PreferencesModal/HotkeyTab.js @@ -138,6 +138,7 @@ class HotkeyTab extends React.Component {
  • Escape (or Esc for short)
  • VolumeUp, VolumeDown and VolumeMute
  • MediaNextTrack, MediaPreviousTrack, MediaStop and MediaPlayPause
  • +
  • Control (or Ctrl for short)
  • } diff --git a/lib/main-menu.js b/lib/main-menu.js index 9a95fe1d..b3a7acc7 100644 --- a/lib/main-menu.js +++ b/lib/main-menu.js @@ -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' }, @@ -158,6 +165,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') + } } ] }