mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
Merge pull request #235 from asmsuechan/add-focus-shortcut
Adds shortcuts
This commit is contained in:
@@ -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)}
|
||||
>
|
||||
<CodeEditor styleName='codeEditor'
|
||||
ref='code'
|
||||
|
||||
@@ -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) {
|
||||
@@ -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()
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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>
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user