File tree Expand file tree Collapse file tree 9 files changed +100
-12
lines changed Expand file tree Collapse file tree 9 files changed +100
-12
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,25 @@ export function escapeHtmlCharacters (text) {
54
54
: html
55
55
}
56
56
57
+ export function isObjectEqual ( a , b ) {
58
+ const aProps = Object . getOwnPropertyNames ( a )
59
+ const bProps = Object . getOwnPropertyNames ( b )
60
+
61
+ if ( aProps . length !== bProps . length ) {
62
+ return false
63
+ }
64
+
65
+ for ( var i = 0 ; i < aProps . length ; i ++ ) {
66
+ const propName = aProps [ i ]
67
+ if ( a [ propName ] !== b [ propName ] ) {
68
+ return false
69
+ }
70
+ }
71
+ return true
72
+ }
73
+
57
74
export default {
58
75
lastFindInArray,
59
- escapeHtmlCharacters
76
+ escapeHtmlCharacters,
77
+ isObjectEqual
60
78
}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import { hashHistory } from 'react-router'
16
16
import store from 'browser/main/store'
17
17
import i18n from 'browser/lib/i18n'
18
18
import { getLocales } from 'browser/lib/Languages'
19
+ import applyShortcuts from 'browser/main/lib/shortcutManager'
19
20
const path = require ( 'path' )
20
21
const electron = require ( 'electron' )
21
22
const { remote } = electron
@@ -159,7 +160,7 @@ class Main extends React.Component {
159
160
} else {
160
161
i18n . setLocale ( 'en' )
161
162
}
162
-
163
+ applyShortcuts ( )
163
164
// Reload all data
164
165
dataApi . init ( )
165
166
. then ( ( data ) => {
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ import { syncHistoryWithStore } from 'react-router-redux'
9
9
require ( './lib/ipcClient' )
10
10
require ( '../lib/customMeta' )
11
11
import i18n from 'browser/lib/i18n'
12
- import ee from 'browser/main/lib/eventEmitter'
13
12
14
13
const electron = require ( 'electron' )
15
14
@@ -64,12 +63,6 @@ document.addEventListener('keyup', function (e) {
64
63
}
65
64
} )
66
65
67
- document . addEventListener ( 'keydown' , function ( e ) {
68
- if ( e . key === 'm' && e . ctrlKey ) {
69
- ee . emit ( 'topbar:togglemodebutton' )
70
- }
71
- } ) ;
72
-
73
66
document . addEventListener ( 'click' , function ( e ) {
74
67
const className = e . target . className
75
68
if ( ! className && typeof ( className ) !== 'string' ) return
Original file line number Diff line number Diff line change 1
1
import _ from 'lodash'
2
2
import RcParser from 'browser/lib/RcParser'
3
3
import i18n from 'browser/lib/i18n'
4
+ import ee from 'browser/main/lib/eventEmitter'
4
5
5
6
const OSX = global . process . platform === 'darwin'
6
7
const win = global . process . platform === 'win32'
@@ -20,7 +21,8 @@ export const DEFAULT_CONFIG = {
20
21
listStyle : 'DEFAULT' , // 'DEFAULT', 'SMALL'
21
22
amaEnabled : true ,
22
23
hotkey : {
23
- toggleMain : OSX ? 'Cmd + Alt + L' : 'Super + Alt + E'
24
+ toggleMain : OSX ? 'Cmd + Alt + L' : 'Super + Alt + E' ,
25
+ toggleMode : OSX ? 'Cmd + M' : 'Ctrl + M'
24
26
} ,
25
27
ui : {
26
28
language : 'en' ,
@@ -166,6 +168,7 @@ function set (updates) {
166
168
ipcRenderer . send ( 'config-renew' , {
167
169
config : get ( )
168
170
} )
171
+ ee . emit ( 'config-renew' )
169
172
}
170
173
171
174
function assignConfigValues ( originalConfig , rcConfig ) {
Original file line number Diff line number Diff line change
1
+ import ee from 'browser/main/lib/eventEmitter'
2
+
3
+ module . exports = {
4
+ 'toggleMode' : ( ) => {
5
+ ee . emit ( 'topbar:togglemodebutton' )
6
+ }
7
+ }
Original file line number Diff line number Diff line change
1
+ import Mousetrap from 'mousetrap'
2
+ import CM from 'browser/main/lib/ConfigManager'
3
+ import ee from 'browser/main/lib/eventEmitter'
4
+ import { isObjectEqual } from 'browser/lib/utils'
5
+ require ( 'mousetrap-global-bind' )
6
+ const functions = require ( './shortcut' )
7
+
8
+ let shortcuts = CM . get ( ) . hotkey
9
+
10
+ ee . on ( 'config-renew' , function ( ) {
11
+ // only update if hotkey changed !
12
+ const newHotkey = CM . get ( ) . hotkey
13
+ if ( ! isObjectEqual ( newHotkey , shortcuts ) ) {
14
+ updateShortcut ( newHotkey )
15
+ }
16
+ } )
17
+
18
+ function updateShortcut ( newHotkey ) {
19
+ Mousetrap . reset ( )
20
+ shortcuts = newHotkey
21
+ applyShortcuts ( newHotkey )
22
+ }
23
+
24
+ function formatShortcut ( shortcut ) {
25
+ return shortcut . toLowerCase ( ) . replace ( / / g, '' )
26
+ }
27
+
28
+ function applyShortcuts ( shortcuts ) {
29
+ for ( const shortcut in shortcuts ) {
30
+ const toggler = formatShortcut ( shortcuts [ shortcut ] )
31
+ // only bind if the function for that shortcut exists
32
+ if ( functions [ shortcut ] ) {
33
+ Mousetrap . bindGlobal ( toggler , functions [ shortcut ] )
34
+ }
35
+ }
36
+ }
37
+
38
+ applyShortcuts ( CM . get ( ) . hotkey )
39
+
40
+ module . exports = applyShortcuts
Original file line number Diff line number Diff line change @@ -67,7 +67,8 @@ class HotkeyTab extends React.Component {
67
67
handleHotkeyChange ( e ) {
68
68
const { config } = this . state
69
69
config . hotkey = {
70
- toggleMain : this . refs . toggleMain . value
70
+ toggleMain : this . refs . toggleMain . value ,
71
+ toggleMode : this . refs . toggleMode . value
71
72
}
72
73
this . setState ( {
73
74
config
@@ -115,6 +116,17 @@ class HotkeyTab extends React.Component {
115
116
/>
116
117
</ div >
117
118
</ div >
119
+ < div styleName = 'group-section' >
120
+ < div styleName = 'group-section-label' > { i18n . __ ( 'Toggle editor mode' ) } </ div >
121
+ < div styleName = 'group-section-control' >
122
+ < input styleName = 'group-section-control-input'
123
+ onChange = { ( e ) => this . handleHotkeyChange ( e ) }
124
+ ref = 'toggleMode'
125
+ value = { config . hotkey . toggleMode }
126
+ type = 'text'
127
+ />
128
+ </ div >
129
+ </ div >
118
130
< div styleName = 'group-control' >
119
131
< button styleName = 'group-control-leftButton'
120
132
onClick = { ( e ) => this . handleHintToggleButtonClick ( e ) }
Original file line number Diff line number Diff line change 79
79
"md5" : " ^2.0.0" ,
80
80
"mdurl" : " ^1.0.1" ,
81
81
"moment" : " ^2.10.3" ,
82
+ "mousetrap" : " ^1.6.1" ,
83
+ "mousetrap-global-bind" : " ^1.1.0" ,
82
84
"node-ipc" : " ^8.1.0" ,
83
85
"raphael" : " ^2.2.7" ,
84
86
"react" : " ^15.5.4" ,
Original file line number Diff line number Diff line change @@ -1864,14 +1864,18 @@ codemirror-mode-elixir@^1.1.1:
1864
1864
dependencies :
1865
1865
codemirror "^5.20.2"
1866
1866
1867
- codemirror@^5.18.2, codemirror@^5.19.0 :
1867
+ codemirror@^5.18.2 :
1868
1868
version "5.26.0"
1869
1869
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.26.0.tgz#bcbee86816ed123870c260461c2b5c40b68746e5"
1870
1870
1871
1871
codemirror@^5.20.2 :
1872
1872
version "5.33.0"
1873
1873
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.33.0.tgz#462ad9a6fe8d38b541a9536a3997e1ef93b40c6a"
1874
1874
1875
+ codemirror@^5.37.0 :
1876
+ version "5.37.0"
1877
+ resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.37.0.tgz#c349b584e158f590277f26d37c2469a6bc538036"
1878
+
1875
1879
coffee-script@^1.10.0 :
1876
1880
version "1.12.6"
1877
1881
resolved "https://registry.yarnpkg.com/coffee-script/-/coffee-script-1.12.6.tgz#285a3f7115689065064d6bf9ef4572db66695cbf"
@@ -5960,6 +5964,14 @@ moment@^2.10.3:
5960
5964
version "2.18.1"
5961
5965
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"
5962
5966
5967
+ mousetrap-global-bind@^1.1.0 :
5968
+ version "1.1.0"
5969
+ resolved "https://registry.yarnpkg.com/mousetrap-global-bind/-/mousetrap-global-bind-1.1.0.tgz#cd7de9222bd0646fa2e010d54c84a74c26a88edd"
5970
+
5971
+ mousetrap@^1.6.1 :
5972
+ version "1.6.1"
5973
+ resolved "https://registry.yarnpkg.com/mousetrap/-/mousetrap-1.6.1.tgz#2a085f5c751294c75e7e81f6ec2545b29cbf42d9"
5974
+
5963
5975
5964
5976
version "0.7.1"
5965
5977
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"
You can’t perform that action at this time.
0 commit comments