Keymaps are now updated without restarting (#2455)

* Reload keymaps without restarting

* Reattach key listeners when config have changed
This commit is contained in:
CHaBou 2017-11-15 00:55:21 +01:00 committed by GitHub
parent 319ff3bcd7
commit 81709073cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 25 deletions

View file

@ -8,8 +8,10 @@ export function loadConfig(config) {
}
export function reloadConfig(config) {
const now = Date.now();
return {
type: CONFIG_RELOAD,
config
config,
now
};
}

View file

@ -20,6 +20,9 @@ class Hyper extends PureComponent {
this.handleFocusActive = this.handleFocusActive.bind(this);
this.onTermsRef = this.onTermsRef.bind(this);
this.mousetrap = null;
this.state = {
lastConfigUpdate: 0
};
}
componentWillReceiveProps(next) {
@ -28,6 +31,11 @@ class Hyper extends PureComponent {
// starts working again
document.body.style.backgroundColor = next.backgroundColor;
}
const {lastConfigUpdate} = next;
if (lastConfigUpdate && lastConfigUpdate !== this.state.lastConfigUpdate) {
this.setState({lastConfigUpdate});
this.attachKeyListeners();
}
}
handleFocusActive() {
@ -132,7 +140,8 @@ const HyperContainer = connect(
borderColor: state.ui.borderColor,
activeSession: state.sessions.activeUid,
backgroundColor: state.ui.backgroundColor,
maximized: state.ui.maximized
maximized: state.ui.maximized,
lastConfigUpdate: state.ui._lastUpdate
};
},
dispatch => {

View file

@ -103,7 +103,7 @@ const reducer = (state = initial, action) => {
case CONFIG_LOAD:
// eslint-disable-next-line no-case-declarations, no-fallthrough
case CONFIG_RELOAD:
const {config} = action;
const {config, now} = action;
state_ = state
// unset the user font size override if the
// font size changed from the config
@ -205,6 +205,8 @@ const reducer = (state = initial, action) => {
ret.quickEdit = config.quickEdit;
}
ret._lastUpdate = now;
return ret;
})()
);