Skip to content

Commit

Permalink
test keymaps as commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ppot committed Mar 4, 2017
1 parent 31eb2e1 commit 6de1a85
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 224 deletions.
21 changes: 7 additions & 14 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,32 @@ const _watch = function () {
});
};

const _subscribe = function (fn) {
exports.subscribe = function (fn) {
watchers.push(fn);
return () => {
watchers.splice(watchers.indexOf(fn), 1);
};
};

const _getPlugins = function () {
exports.getPlugins = function () {
return {
plugins: cfg.plugins,
localPlugins: cfg.localPlugins
};
};

const _getConfig = function () {
exports.getConfig = function () {
return cfg.config;
};

const _getKeymaps = function () {
exports.getKeymaps = function () {
return cfg.keymaps;
};

const _setup = function() {
exports.setup = function () {
cfg = _import();
_watch();
};

module.exports = {
setup: _setup,
subscribe: _subscribe,
getPlugins: _getPlugins,
getConfig: _getConfig,
getKeymaps: _getKeymaps,
getWin: win.get,
winRecord: win.recordState
};
exports.getWin = win.get;
exports.winRecord = win.recordState;
5 changes: 4 additions & 1 deletion app/config/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {writeFileSync, readFileSync} = require('fs');
const {sync: mkdirpSync} = require('mkdirp');
const _paths = require('./paths');
const _init = require('./init');
const _keys = require('./keymaps');

const _write = function (path, data) {
// This method will take text formatted as Unix line endings and transform it
Expand Down Expand Up @@ -38,7 +39,9 @@ const _importPlugins = function () {
const _import = function () {
mkdirpSync(_paths.hyperHomeDirPath);
_importPlugins();
return _init(_importConfig());
const cfg = _init(_importConfig());
cfg.keymaps = _keys(cfg.keymaps);
return cfg;
};

module.exports = _import;
39 changes: 39 additions & 0 deletions app/config/keymaps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const {readFileSync} = require('fs');
const {join} = require('path');
const _paths = require('./paths');

const _keys = function (customsKeys) {
const commands = {};
const keys = {};
const path = () => {
switch (process.platform) {
case 'darwin': return join(_paths.keymapPath, 'darwin.json');
case 'win32': return join(_paths.keymapPath, 'win32.json');
case 'linux': return join(_paths.keymapPath, 'linux.json');
default: return join(_paths.keymapPath, 'darwin.json');
}
};
try {
const cmds = JSON.parse(readFileSync(path()));
for (const command in cmds) {
if (command) {
commands[command] = cmds[command];
keys[commands[command]] = command;
}
}

if (customsKeys) {
for (const command in customsKeys) {
if (command) {
commands[command] = customsKeys[command];
keys[customsKeys[command]] = command;
}
}
}

return {commands, keys};
} catch (err) {
}
};

module.exports = _keys;
22 changes: 11 additions & 11 deletions app/config/paths.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// This module exports paths, names, and other metadata that is referenced
const path = require('path');
const {join} = require('path');
const {homedir} = require('os');
const isDev = require('electron-is-dev');

const homeDirPath = homedir();
const repositoryRootPath = path.resolve(__dirname, '..');
const hyperHomeDirPath = path.join(homeDirPath, '.hyper');
const preferencesPath = path.join(hyperHomeDirPath, 'config.js');
const pluginsPath = path.join(hyperHomeDirPath, 'plugins');
const keymapPath = path.join(hyperHomeDirPath, 'keymap.js');
const localPluginsPath = path.join(pluginsPath, 'local');
const previousConfigPath = path.join(homeDirPath, '.hyper.js');
const dotHyperPath = path.join(repositoryRootPath, 'dot-hyper');
const dotConfigPath = path.join(dotHyperPath, 'config-default.js');
const pkgPath = path.join(pluginsPath, 'package.json');
const repositoryRootPath = join(__dirname, '..');
const hyperHomeDirPath = join(homeDirPath, '.hyper');
const preferencesPath = join(hyperHomeDirPath, 'config.js');
const pluginsPath = join(hyperHomeDirPath, 'plugins');
const keymapPath = join(repositoryRootPath, 'keymaps');
const localPluginsPath = join(pluginsPath, 'local');
const previousConfigPath = join(homeDirPath, '.hyper.js');
const dotHyperPath = join(repositoryRootPath, 'dot-hyper');
const dotConfigPath = join(dotHyperPath, 'config-default.js');
const pkgPath = join(pluginsPath, 'package.json');

module.exports = {
isDev, repositoryRootPath, homeDirPath, hyperHomeDirPath, preferencesPath, pluginsPath,
Expand Down
7 changes: 4 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ config.setup();

const plugins = require('./plugins');
const Session = require('./session');
const keymaps = require('./keymaps');

const windowSet = new Set([]);

// expose to plugins
app.config = config;
app.plugins = plugins;

app.getWindows = () => new Set([...windowSet]); // return a clone

// function to retrieve the last focused window in windowSet;
Expand Down Expand Up @@ -118,6 +118,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
// previous window. This also ensures in multi monitor setups that the
// new terminal is on the correct screen.
const focusedWindow = BrowserWindow.getFocusedWindow() || app.getLastFocusedWindow();

// In case of options defaults position and size, we should ignore the focusedWindow.
if (winPos !== undefined) {
[startX, startY] = winPos;
Expand Down Expand Up @@ -354,6 +355,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
// the window can be closed by the browser process itself
win.on('close', () => {
config.winRecord(win);
windowSet.delete(win);
rpc.destroy();
deleteSessions();
cfgUnsubscribe();
Expand Down Expand Up @@ -390,8 +392,7 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
});

const makeMenu = () => {
const menu = new AppMenu(keymaps.commands, createWindow, () => {
// plugins.update({force: true});
const menu = new AppMenu(config.getKeymaps().commands, createWindow, () => {
plugins.updatePlugins({force: true});
});

Expand Down
4 changes: 0 additions & 4 deletions app/keymaps.js

This file was deleted.

56 changes: 28 additions & 28 deletions app/keymaps/darwin.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
{
"window:devtools":"Cmd+Alt+I",
"window:reload":"Cmd+R",
"window:reloadFull":"Cmd+Shift+R",
"window:preferences":"Cmd+,",
"zoom:reset":"Cmd+0",
"zoom:in":"Cmd+plus",
"zoom:out":"Cmd+-",
"window:new":"Cmd+N",
"window:minimize": "Cmd+M",
"window:full": "Cmd+Ctrl+F",
"window:close":"Cmd+Shift+W",
"window:devtools":"cmd+alt+i",
"window:reload":"cmd+r",
"window:reloadFull":"cmd+shift+r",
"window:preferences":"cmd+,",
"zoom:reset":"cmd+0",
"zoom:in":"cmd+plus",
"zoom:out":"cmd+-",
"window:new":"cmd+n",
"window:minimize": "cmd+m",
"window:full": "cmd+ctrl+f",
"window:close":"cmd+shift+w",

"tab:new":"Cmd+T",
"tab:next":"Cmd+shift+]",
"tab:prev":"Cmd+shift+[",
"pane:next":"Cmd+]",
"pane:prev":"Cmd+[",
"pane:vertical":"Cmd+D",
"pane:horizontal":"Cmd+Shift+D",
"pane:close":"Cmd+W",
"tab:new":"cmd+t",
"tab:next":"cmd+shift+]",
"tab:prev":"cmd+shift+[",
"pane:next":"cmd+]",
"pane:prev":"cmd+[",
"pane:vertical":"cmd+d",
"pane:horizontal":"cmd+shift+d",
"pane:close":"cmd+w",

"editor:undo":"Cmd+Z",
"editor:redo":"Cmd+Y",
"editor:cut":"Cmd+X",
"editor:copy":"Cmd+C",
"editor:paste":"Cmd+V",
"editor:selectAll":"Cmd+A",
"editor:clearBuffer":"Cmd+K",
"editor:emojis": "Cmd+Ctrl+Space",
"editor:undo":"cmd+z",
"editor:redo":"cmd+y",
"editor:cut":"cmd+x",
"editor:copy":"cmd+c",
"editor:paste":"cmd+v",
"editor:selectAll":"cmd+a",
"editor:clearBuffer":"cmd+k",
"editor:emojis": "cmd+ctrl+space",

"plugins:update": "Cmd+Shift+U"
"plugins:update": "cmd+shift+u"
}
72 changes: 0 additions & 72 deletions app/keymaps/keymap-manager.js

This file was deleted.

54 changes: 27 additions & 27 deletions app/keymaps/linux.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{
"window:devtools":"Ctrl+Shift+I",
"window:reload":"Ctrl+Shift+R",
"window:reloadFull":"Ctrl+Shift+F5",
"window:preferences":"Ctrl+,",
"zoom:reset":"Ctrl+0",
"zoom:in":"Ctrl+plus",
"zoom:out":"Ctrl+-",
"window:new":"Ctrl+Shift+N",
"window:minimize": "Ctrl+M",
"window:full": "F11",
"window:close":"Ctrl+Shift+W",
"window:devtools":"ctrl+shift+i",
"window:reload":"ctrl+shift+r",
"window:reloadFull":"ctrl+shift+f5",
"window:preferences":"ctrl+,",
"zoom:reset":"ctrl+0",
"zoom:in":"ctrl+plus",
"zoom:out":"ctrl+-",
"window:new":"ctrl+shift+n",
"window:minimize": "ctrl+m",
"window:full": "f11",
"window:close":"ctrl+shift+w",

"tab:new":"Ctrl+Shift+T",
"tab:next":"Ctrl+Tab",
"tab:prev":"Ctrl+shift+Tab",
"pane:next":"Ctrl+Pageup",
"pane:prev":"Ctrl+Pagedown",
"pane:vertical":"Ctrl+Shift+D",
"pane:horizontal":"Ctrl+Shift+E",
"pane:close":"Ctrl+Shift+W",
"tab:new":"ctrl+shift+t",
"tab:next":"ctrl+tab",
"tab:prev":"ctrl+shift+tab",
"pane:next":"ctrl+pageup",
"pane:prev":"ctrl+pagedown",
"pane:vertical":"ctrl+shift+d",
"pane:horizontal":"ctrl+shift+e",
"pane:close":"ctrl+shift+w",

"editor:undo":"Ctrl+Shift+Z",
"editor:redo":"Ctrl+Shift+Y",
"editor:cut":"Ctrl+Shift+X",
"editor:copy":"Ctrl+Shift+C",
"editor:paste":"Ctrl+Shift+V",
"editor:selectAll":"Ctrl+Shift+A",
"editor:clearBuffer":"Ctrl+Shift+K",
"editor:undo":"ctrl+shift+z",
"editor:redo":"ctrl+shift+y",
"editor:cut":"ctrl+shift+x",
"editor:copy":"ctrl+shift+c",
"editor:paste":"ctrl+shift+v",
"editor:selectAll":"ctrl+shift+a",
"editor:clearBuffer":"ctrl+shift+k",

"plugins:update": "Ctrl+Shift+U"
"plugins:update": "ctrl+shift+u"
}
Loading

0 comments on commit 6de1a85

Please sign in to comment.