From 5bd0a446f15aac8b2b6edfeee015942522baca43 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Jan 2017 21:05:00 +0900 Subject: [PATCH 01/11] refs #226 Adds a shortcut which focuses the note --- lib/main-menu.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/main-menu.js b/lib/main-menu.js index 482c8b07..11f182d7 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: function () { + mainWindow.webContents.send('detail:focus') + } + }, { type: 'separator' }, From e8e05b20cd9cd14c7cf54d2459ea8250fb8bccc2 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 13 Jan 2017 22:23:52 +0900 Subject: [PATCH 02/11] refs #226 Adds blur shortcut on Editor --- browser/components/MarkdownEditor.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index e5041565..d31b30d4 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -142,6 +142,12 @@ class MarkdownEditor extends React.Component { this.renderPreview(this.props.value) } + handleKeyDown(e) { + if (this.state.status === 'CODE' && e.key == 'Escape') { + document.activeElement.blur() + } + } + render () { let { className, value, config } = this.props @@ -160,6 +166,7 @@ class MarkdownEditor extends React.Component { } onContextMenu={(e) => this.handleContextMenu(e)} tabIndex='-1' + onKeyDown={(e) => this.handleKeyDown(e)} > Date: Sat, 14 Jan 2017 00:49:54 +0900 Subject: [PATCH 03/11] refs #226 Adds focus to search shortcut to main-menu --- browser/main/TopBar/index.js | 11 +++++++++++ lib/main-menu.js | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/browser/main/TopBar/index.js b/browser/main/TopBar/index.js index added48f..8be58a63 100644 --- a/browser/main/TopBar/index.js +++ b/browser/main/TopBar/index.js @@ -24,14 +24,20 @@ class TopBar extends React.Component { this.newNoteHandler = () => { this.handleNewPostButtonClick() } + + this.focusSearchHandler = () => { + this.handleFocusSearch() + } } 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,10 @@ class TopBar extends React.Component { }) } + handleFocusSearch () { + this.refs.search.childNodes[0].focus() + } + render () { let { config, style, data } = this.props let searchOptionList = this.getOptions() @@ -287,6 +297,7 @@ class TopBar extends React.Component { onChange={(e) => this.handleSearchChange(e)} placeholder='Search' type='text' + id='Search' /> {this.state.searchPopupOpen &&
diff --git a/lib/main-menu.js b/lib/main-menu.js index 11f182d7..e554e98a 100644 --- a/lib/main-menu.js +++ b/lib/main-menu.js @@ -143,6 +143,16 @@ var view = { click: function () { BrowserWindow.getFocusedWindow().toggleDevTools() } + }, + { + type: 'separator' + }, + { + label: 'Focus Search', + accelerator: 'Control + S', + click: function () { + mainWindow.webContents.send('top:focus-search') + } } ] } From b9e6a56a83d46522b7b0028903369657771ce719 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 14 Jan 2017 01:10:38 +0900 Subject: [PATCH 04/11] refs #226 Changes to toggle by Ctrl + S --- browser/main/TopBar/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser/main/TopBar/index.js b/browser/main/TopBar/index.js index 8be58a63..cc8baf6c 100644 --- a/browser/main/TopBar/index.js +++ b/browser/main/TopBar/index.js @@ -251,7 +251,11 @@ class TopBar extends React.Component { } handleFocusSearch () { - this.refs.search.childNodes[0].focus() + if (this.state.searchPopupOpen) { + this.refs.search.childNodes[0].blur() + } else { + this.refs.search.childNodes[0].focus() + } } render () { From 41977e8726e58c9b40fe9dd01b595b426c7f2d87 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 14 Jan 2017 10:09:39 +0900 Subject: [PATCH 05/11] refs #226 Adds shortcuts which move next note and prior note to main-menu --- lib/main-menu.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/main-menu.js b/lib/main-menu.js index e554e98a..1816bfaf 100644 --- a/lib/main-menu.js +++ b/lib/main-menu.js @@ -147,6 +147,23 @@ var view = { { type: 'separator' }, + { + label: 'Next Note', + accelerator: 'Control + J', + click: function () { + mainWindow.webContents.send('list:next') + } + }, + { + label: 'Prior Note', + accelerator: 'Control + U', + click: function () { + mainWindow.webContents.send('list:prior') + } + }, + { + type: 'separator' + }, { label: 'Focus Search', accelerator: 'Control + S', From 2ac0d93caf4a10caf1f2a0328749eac295f1c460 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 14 Jan 2017 17:38:16 +0900 Subject: [PATCH 06/11] refs #226 Adds Control to Hint of Hotkey --- browser/main/modals/PreferencesModal/HotkeyTab.js | 1 + 1 file changed, 1 insertion(+) 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)
  • } From cdb079dc814e1fa34f0f273b30786405387ac120 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 14 Jan 2017 18:44:53 +0900 Subject: [PATCH 07/11] refs #226 Enables to use multiple key for shortcut --- browser/components/MarkdownEditor.js | 14 +++++++++++++- browser/main/lib/ConfigManager.js | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index d31b30d4..b77c5bda 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -8,6 +8,10 @@ class MarkdownEditor extends React.Component { constructor (props) { super(props) + this.hotkey = props.config.hotkey + + this.keyPressed = [] + this.state = { status: 'PREVIEW', renderValue: props.value @@ -143,11 +147,18 @@ class MarkdownEditor extends React.Component { } handleKeyDown(e) { - if (this.state.status === 'CODE' && e.key == 'Escape') { + this.keyPressed[e.key] = true + let isNoteHandlerKey = (el) => { return this.keyPressed[el] } + if (this.state.status === 'CODE' && this.hotkey.noteHandlerKey.escapeFromEditor.every(isNoteHandlerKey)) { document.activeElement.blur() + this.hotkey.noteHandlerKey.escapeFromEditor.forEach((el) => {this.keyPressed[el] = false}) } } + handleKeyUp (e) { + this.keyPressed[e.key] = false + } + render () { let { className, value, config } = this.props @@ -167,6 +178,7 @@ class MarkdownEditor extends React.Component { onContextMenu={(e) => this.handleContextMenu(e)} tabIndex='-1' onKeyDown={(e) => this.handleKeyDown(e)} + onKeyUp={(e) => this.handleKeyUp(e)} > Date: Wed, 18 Jan 2017 12:01:22 +0900 Subject: [PATCH 08/11] Fix pointed part by review --- browser/components/MarkdownEditor.js | 20 +++++++++++++------- browser/main/TopBar/index.js | 5 ++--- lib/main-menu.js | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index b77c5bda..3ececc2e 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -10,11 +10,10 @@ class MarkdownEditor extends React.Component { this.hotkey = props.config.hotkey - this.keyPressed = [] - this.state = { status: 'PREVIEW', - renderValue: props.value + renderValue: props.value, + keyPressed: {} } } @@ -147,16 +146,23 @@ class MarkdownEditor extends React.Component { } handleKeyDown(e) { - this.keyPressed[e.key] = true - let isNoteHandlerKey = (el) => { return this.keyPressed[el] } + let newKeyPressed = this.state.keyPressed + newKeyPressed[e.key] = true + this.setState({keyPressed: newKeyPressed}) + let isNoteHandlerKey = (el) => { return this.state.keyPressed[el] } if (this.state.status === 'CODE' && this.hotkey.noteHandlerKey.escapeFromEditor.every(isNoteHandlerKey)) { document.activeElement.blur() - this.hotkey.noteHandlerKey.escapeFromEditor.forEach((el) => {this.keyPressed[el] = false}) + this.hotkey.noteHandlerKey.escapeFromEditor.forEach((el) => { + newKeyPressed[e.key] = false + this.setState({keyPressed: newKeyPressed}) + }) } } handleKeyUp (e) { - this.keyPressed[e.key] = false + let newKeyPressed = this.state.keyPressed + newKeyPressed[e.key] = false + this.setState({keyPressed: newKeyPressed}) } render () { diff --git a/browser/main/TopBar/index.js b/browser/main/TopBar/index.js index cc8baf6c..946c7242 100644 --- a/browser/main/TopBar/index.js +++ b/browser/main/TopBar/index.js @@ -26,7 +26,7 @@ class TopBar extends React.Component { } this.focusSearchHandler = () => { - this.handleFocusSearch() + this.handleOnSearchFocus() } } @@ -250,7 +250,7 @@ class TopBar extends React.Component { }) } - handleFocusSearch () { + handleOnSearchFocus () { if (this.state.searchPopupOpen) { this.refs.search.childNodes[0].blur() } else { @@ -301,7 +301,6 @@ class TopBar extends React.Component { onChange={(e) => this.handleSearchChange(e)} placeholder='Search' type='text' - id='Search' /> {this.state.searchPopupOpen &&
    diff --git a/lib/main-menu.js b/lib/main-menu.js index 1816bfaf..81613957 100644 --- a/lib/main-menu.js +++ b/lib/main-menu.js @@ -62,7 +62,7 @@ var file = { { label: 'Focus Note', accelerator: 'Control + E', - click: function () { + click () { mainWindow.webContents.send('detail:focus') } }, @@ -155,7 +155,7 @@ var view = { } }, { - label: 'Prior Note', + label: 'Privious Note', accelerator: 'Control + U', click: function () { mainWindow.webContents.send('list:prior') From ec6de1b91b8cf37d449869b1fbebe2a2d670dc59 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Thu, 19 Jan 2017 00:01:14 +0900 Subject: [PATCH 09/11] Fix typo --- lib/main-menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main-menu.js b/lib/main-menu.js index 81613957..051b6113 100644 --- a/lib/main-menu.js +++ b/lib/main-menu.js @@ -155,7 +155,7 @@ var view = { } }, { - label: 'Privious Note', + label: 'Previous Note', accelerator: 'Control + U', click: function () { mainWindow.webContents.send('list:prior') From de19c51061d5c2cb18b58b529b4c4be33d72397a Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Fri, 20 Jan 2017 19:15:31 +0900 Subject: [PATCH 10/11] Change to use Object.assign by checking keyPressed and remove unnecessary processing --- browser/components/MarkdownEditor.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index 3ececc2e..ad58e00d 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -146,23 +146,21 @@ class MarkdownEditor extends React.Component { } handleKeyDown(e) { - let newKeyPressed = this.state.keyPressed - newKeyPressed[e.key] = true - this.setState({keyPressed: newKeyPressed}) + 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() - this.hotkey.noteHandlerKey.escapeFromEditor.forEach((el) => { - newKeyPressed[e.key] = false - this.setState({keyPressed: newKeyPressed}) - }) } } handleKeyUp (e) { - let newKeyPressed = this.state.keyPressed - newKeyPressed[e.key] = false - this.setState({keyPressed: newKeyPressed}) + const keyPressed = Object.assign(this.state.keyPressed, { + [e.key]: false + }) + this.setState({ keyPressed }) } render () { From 4523743150fcfdc4af8a2eb06afb76a859ec41d5 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 21 Jan 2017 16:06:14 +0900 Subject: [PATCH 11/11] Fix by review refs: https://github.com/BoostIO/Boostnote/pull/235#pullrequestreview-17800321 --- lib/main-menu.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main-menu.js b/lib/main-menu.js index 051b6113..31000948 100644 --- a/lib/main-menu.js +++ b/lib/main-menu.js @@ -150,14 +150,14 @@ var view = { { label: 'Next Note', accelerator: 'Control + J', - click: function () { + click () { mainWindow.webContents.send('list:next') } }, { label: 'Previous Note', accelerator: 'Control + U', - click: function () { + click () { mainWindow.webContents.send('list:prior') } }, @@ -167,7 +167,7 @@ var view = { { label: 'Focus Search', accelerator: 'Control + S', - click: function () { + click () { mainWindow.webContents.send('top:focus-search') } }