mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
Keymaps are now updated without restarting (#2455)
* Reload keymaps without restarting * Reattach key listeners when config have changed
This commit is contained in:
parent
319ff3bcd7
commit
81709073cf
6 changed files with 37 additions and 25 deletions
12
app/index.js
12
app/index.js
|
|
@ -200,14 +200,10 @@ app.on('ready', () =>
|
|||
Menu.setApplicationMenu(AppMenu.buildMenu(menu));
|
||||
};
|
||||
|
||||
const load = () => {
|
||||
plugins.onApp(app);
|
||||
plugins.checkDeprecatedExtendKeymaps();
|
||||
makeMenu();
|
||||
};
|
||||
|
||||
load();
|
||||
plugins.subscribe(load);
|
||||
plugins.onApp(app);
|
||||
makeMenu();
|
||||
plugins.subscribe(plugins.onApp.bind(undefined, app));
|
||||
config.subscribe(makeMenu);
|
||||
})
|
||||
.catch(err => {
|
||||
//eslint-disable-next-line no-console
|
||||
|
|
|
|||
|
|
@ -43,6 +43,15 @@ config.subscribe(() => {
|
|||
}
|
||||
});
|
||||
|
||||
function checkDeprecatedExtendKeymaps() {
|
||||
modules.forEach(plugin => {
|
||||
if (plugin.extendKeymaps) {
|
||||
notify('Plugin warning!', `"${plugin._name}" use deprecated "extendKeymaps" handler`);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let updating = false;
|
||||
|
||||
function updatePlugins({force = false} = {}) {
|
||||
|
|
@ -84,6 +93,7 @@ function updatePlugins({force = false} = {}) {
|
|||
} else {
|
||||
notify('Plugins Updated', 'No changes!');
|
||||
}
|
||||
checkDeprecatedExtendKeymaps();
|
||||
watchers.forEach(fn => fn(err, {force}));
|
||||
}
|
||||
}
|
||||
|
|
@ -347,15 +357,6 @@ exports.getDecoratedConfig = () => {
|
|||
return translatedConfig;
|
||||
};
|
||||
|
||||
exports.checkDeprecatedExtendKeymaps = () => {
|
||||
modules.forEach(plugin => {
|
||||
if (plugin.extendKeymaps) {
|
||||
notify('Plugin warning!', `"${plugin._name}" use deprecated "extendKeymaps" handler`);
|
||||
return;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.getDecoratedKeymaps = () => {
|
||||
const baseKeymaps = config.getKeymaps();
|
||||
// Ensure that all keys are in an array and don't use deprecated key combination`
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ const {execCommand} = require('../commands');
|
|||
const {getDecoratedKeymaps} = require('../plugins');
|
||||
const separator = {type: 'separator'};
|
||||
|
||||
const allCommandKeys = getDecoratedKeymaps();
|
||||
const commandKeys = Object.keys(allCommandKeys).reduce((result, command) => {
|
||||
result[command] = allCommandKeys[command][0];
|
||||
return result;
|
||||
}, {});
|
||||
const getCommandKeys = keymaps =>
|
||||
Object.keys(keymaps).reduce((commandKeys, command) => {
|
||||
return Object.assign(commandKeys, {
|
||||
[command]: keymaps[command][0]
|
||||
});
|
||||
}, {});
|
||||
|
||||
// only display cut/copy when there's a cursor selection
|
||||
const filterCutCopy = (selection, menuItem) => {
|
||||
|
|
@ -19,6 +20,7 @@ const filterCutCopy = (selection, menuItem) => {
|
|||
};
|
||||
|
||||
module.exports = (createWindow, selection) => {
|
||||
const commandKeys = getCommandKeys(getDecoratedKeymaps());
|
||||
const _shell = shellMenu(commandKeys, execCommand).submenu;
|
||||
const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection));
|
||||
return _edit.concat(separator, _shell).filter(menuItem => !menuItem.hasOwnProperty('enabled') || menuItem.enabled);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ export function loadConfig(config) {
|
|||
}
|
||||
|
||||
export function reloadConfig(config) {
|
||||
const now = Date.now();
|
||||
return {
|
||||
type: CONFIG_RELOAD,
|
||||
config
|
||||
config,
|
||||
now
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
})()
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue