mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-14 12:58:39 -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));
|
Menu.setApplicationMenu(AppMenu.buildMenu(menu));
|
||||||
};
|
};
|
||||||
|
|
||||||
const load = () => {
|
plugins.onApp(app);
|
||||||
plugins.onApp(app);
|
makeMenu();
|
||||||
plugins.checkDeprecatedExtendKeymaps();
|
plugins.subscribe(plugins.onApp.bind(undefined, app));
|
||||||
makeMenu();
|
config.subscribe(makeMenu);
|
||||||
};
|
|
||||||
|
|
||||||
load();
|
|
||||||
plugins.subscribe(load);
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
//eslint-disable-next-line no-console
|
//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;
|
let updating = false;
|
||||||
|
|
||||||
function updatePlugins({force = false} = {}) {
|
function updatePlugins({force = false} = {}) {
|
||||||
|
|
@ -84,6 +93,7 @@ function updatePlugins({force = false} = {}) {
|
||||||
} else {
|
} else {
|
||||||
notify('Plugins Updated', 'No changes!');
|
notify('Plugins Updated', 'No changes!');
|
||||||
}
|
}
|
||||||
|
checkDeprecatedExtendKeymaps();
|
||||||
watchers.forEach(fn => fn(err, {force}));
|
watchers.forEach(fn => fn(err, {force}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -347,15 +357,6 @@ exports.getDecoratedConfig = () => {
|
||||||
return translatedConfig;
|
return translatedConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.checkDeprecatedExtendKeymaps = () => {
|
|
||||||
modules.forEach(plugin => {
|
|
||||||
if (plugin.extendKeymaps) {
|
|
||||||
notify('Plugin warning!', `"${plugin._name}" use deprecated "extendKeymaps" handler`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.getDecoratedKeymaps = () => {
|
exports.getDecoratedKeymaps = () => {
|
||||||
const baseKeymaps = config.getKeymaps();
|
const baseKeymaps = config.getKeymaps();
|
||||||
// Ensure that all keys are in an array and don't use deprecated key combination`
|
// 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 {getDecoratedKeymaps} = require('../plugins');
|
||||||
const separator = {type: 'separator'};
|
const separator = {type: 'separator'};
|
||||||
|
|
||||||
const allCommandKeys = getDecoratedKeymaps();
|
const getCommandKeys = keymaps =>
|
||||||
const commandKeys = Object.keys(allCommandKeys).reduce((result, command) => {
|
Object.keys(keymaps).reduce((commandKeys, command) => {
|
||||||
result[command] = allCommandKeys[command][0];
|
return Object.assign(commandKeys, {
|
||||||
return result;
|
[command]: keymaps[command][0]
|
||||||
}, {});
|
});
|
||||||
|
}, {});
|
||||||
|
|
||||||
// only display cut/copy when there's a cursor selection
|
// only display cut/copy when there's a cursor selection
|
||||||
const filterCutCopy = (selection, menuItem) => {
|
const filterCutCopy = (selection, menuItem) => {
|
||||||
|
|
@ -19,6 +20,7 @@ const filterCutCopy = (selection, menuItem) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = (createWindow, selection) => {
|
module.exports = (createWindow, selection) => {
|
||||||
|
const commandKeys = getCommandKeys(getDecoratedKeymaps());
|
||||||
const _shell = shellMenu(commandKeys, execCommand).submenu;
|
const _shell = shellMenu(commandKeys, execCommand).submenu;
|
||||||
const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection));
|
const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection));
|
||||||
return _edit.concat(separator, _shell).filter(menuItem => !menuItem.hasOwnProperty('enabled') || menuItem.enabled);
|
return _edit.concat(separator, _shell).filter(menuItem => !menuItem.hasOwnProperty('enabled') || menuItem.enabled);
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,10 @@ export function loadConfig(config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function reloadConfig(config) {
|
export function reloadConfig(config) {
|
||||||
|
const now = Date.now();
|
||||||
return {
|
return {
|
||||||
type: CONFIG_RELOAD,
|
type: CONFIG_RELOAD,
|
||||||
config
|
config,
|
||||||
|
now
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ class Hyper extends PureComponent {
|
||||||
this.handleFocusActive = this.handleFocusActive.bind(this);
|
this.handleFocusActive = this.handleFocusActive.bind(this);
|
||||||
this.onTermsRef = this.onTermsRef.bind(this);
|
this.onTermsRef = this.onTermsRef.bind(this);
|
||||||
this.mousetrap = null;
|
this.mousetrap = null;
|
||||||
|
this.state = {
|
||||||
|
lastConfigUpdate: 0
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(next) {
|
componentWillReceiveProps(next) {
|
||||||
|
|
@ -28,6 +31,11 @@ class Hyper extends PureComponent {
|
||||||
// starts working again
|
// starts working again
|
||||||
document.body.style.backgroundColor = next.backgroundColor;
|
document.body.style.backgroundColor = next.backgroundColor;
|
||||||
}
|
}
|
||||||
|
const {lastConfigUpdate} = next;
|
||||||
|
if (lastConfigUpdate && lastConfigUpdate !== this.state.lastConfigUpdate) {
|
||||||
|
this.setState({lastConfigUpdate});
|
||||||
|
this.attachKeyListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFocusActive() {
|
handleFocusActive() {
|
||||||
|
|
@ -132,7 +140,8 @@ const HyperContainer = connect(
|
||||||
borderColor: state.ui.borderColor,
|
borderColor: state.ui.borderColor,
|
||||||
activeSession: state.sessions.activeUid,
|
activeSession: state.sessions.activeUid,
|
||||||
backgroundColor: state.ui.backgroundColor,
|
backgroundColor: state.ui.backgroundColor,
|
||||||
maximized: state.ui.maximized
|
maximized: state.ui.maximized,
|
||||||
|
lastConfigUpdate: state.ui._lastUpdate
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
dispatch => {
|
dispatch => {
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ const reducer = (state = initial, action) => {
|
||||||
case CONFIG_LOAD:
|
case CONFIG_LOAD:
|
||||||
// eslint-disable-next-line no-case-declarations, no-fallthrough
|
// eslint-disable-next-line no-case-declarations, no-fallthrough
|
||||||
case CONFIG_RELOAD:
|
case CONFIG_RELOAD:
|
||||||
const {config} = action;
|
const {config, now} = action;
|
||||||
state_ = state
|
state_ = state
|
||||||
// unset the user font size override if the
|
// unset the user font size override if the
|
||||||
// font size changed from the config
|
// font size changed from the config
|
||||||
|
|
@ -205,6 +205,8 @@ const reducer = (state = initial, action) => {
|
||||||
ret.quickEdit = config.quickEdit;
|
ret.quickEdit = config.quickEdit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret._lastUpdate = now;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
})()
|
})()
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue