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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue