Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements Commands Key mapping #1876

Merged
merged 5 commits into from
Jun 3, 2017
Merged

Implements Commands Key mapping #1876

merged 5 commits into from
Jun 3, 2017

Conversation

ppot
Copy link
Contributor

@ppot ppot commented May 26, 2017

-> keymaps files
-> config structure change (file deconstruction)
-> plugins extends keymaps
-> update hterm to use commands-registry

@albinekb albinekb mentioned this pull request May 26, 2017
app/config.js Outdated

const watchers = [];

const scanInterval = 2000;
Copy link
Contributor

@albinekb albinekb May 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would:

// watch for changes on config every 2s on windows
// https://github.com/zeit/hyper/pull/1772
const watchConfig = process.platform === 'win32' ?  { interval: 2000 } : {}

...

gaze(confPath, watchConfig, function (err) {

easier to read?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah agree on that!

@albinekb
Copy link
Contributor

One thing that would be 💯^10 is to be consistent with variable names, I'm thinking of the words
cfg, conf and config that are mixed, it's easier to read and understand the code if you use the same name for these, chose one and stick to it 👌

watchers.forEach(fn => fn());
}
} catch (err) {
dialog.showMessageBox({
Copy link
Contributor

@albinekb albinekb May 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes from displaying a dialog to just a notification, correct?

I think it's nice with the dialog since you need to click "OK" to close it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't change it since using a dialog prevent hyper from opening.


exports.extendKeymaps = function (keymaps) {
if (keymaps) {
cfg.keymaps = keymaps;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. I don't like mutating stuff like this. But I think we do this in other places? Maybe that's a job for another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we do this alot...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with this for now, but we should clean it all up

const {writeFileSync, readFileSync} = require('fs');
const {defaultConfig, confPath} = require('./paths');
const _init = require('./init');
const _keys = require('./keymaps');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename this to _keymaps, easier to understand the code

return module.exports;
};

const _syntaxValidation = function (cfg) {
Copy link
Contributor

@albinekb albinekb May 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const _syntaxValidation = function (cfg) {
    try {
      return new vm.Script(cfg, { filename: '.hyper.js', displayErrors: true })
    } catch (error) {
      notify(`Error loading config: ${error.name}, see DevTools for more info`)
      console.error('Error loading config:', error)
      return
    }
}

tested:

_syntaxValidation(`
const c = 'a'
const b = 'd'
const c = '2'
`)

notify: Error loading config: SyntaxError, see DevTools for more info
console:

 Error loading config:
 .hyper.js:4
const c = '2'
          ^^^
SyntaxError: Identifier 'c' has already been declared

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you commenting as an error or a test?

Copy link
Contributor

@albinekb albinekb May 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha the comment was to update _syntaxValidation to the code i wrote in my comment,
making it show what type of error happened, and log the row in .hyper.js to console

the blocks under is to show what it does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍


const icon = resolve(__dirname, '../static/icon.png');

const keymapPath = resolve(__dirname, '../keymaps');
const darwinKeys = resolve(keymapPath, 'darwin.json');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should't these be path.join?
http://tips.tutorialhorizon.com/2017/05/01/path-join-vs-path-resolve-in-node-js/

don't know how resolve vs join is performance/resource-wise,
it's probably so tiny that it's non-existent 😄

🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that they contain .. resolve is probably better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they do not @MartyGentillon resolve(keymapPath, 'darwin.json') keymapPath is already expanded

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True enough for this particular path, but that would be the reasoning nonetheless.

};

const _import = function (customsKeys) {
const path = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not move this to app/config/paths.js and just expose it as defaultPlatformKeyPath?

Is there a need to get other platforms' keys?

@@ -0,0 +1,34 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run these trough http://jsonprettyprint.com or similar 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

pluginsMenu(updatePlugins),
windowMenu(),
helpMenu()
shellMenu(commands, createWindow),
Copy link
Contributor

@albinekb albinekb May 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ES6 style:

const menu = [
  ...(process.platform === 'darwin' ? darwinMenu(commands) : []),
  ...shellMenu(commands, createWindow),
  ...editMenu(commands),
  ...viewMenu(commands),
  ...pluginsMenu(commands, updatePlugins),
  ...windowMenu(commands),
  ...helpMenu(commands)
]

then remove this further down:

if (process.platform === 'darwin') {
   ...menu.unshift...
}

💅

to avoid mutations (unshift)

@@ -29,7 +27,7 @@ module.exports = function (createWindow) {
},
{
label: 'Split Vertically',
accelerator: accelerators.splitVertically,
accelerator: commands['pane:vertical'],
Copy link
Contributor

@albinekb albinekb May 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe pane:splitVertical or pane:split:vertical to make it clearer, same with horizontal

},
{
role: 'zoom'
role: 'zoom',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this actually do? 😂 never used it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently nothing on Windows?

Copy link
Contributor

@albinekb albinekb May 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, makes the window fill the screen (on macOS) 😄
It's the same thing as clicking the green traffc-light on macOS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it does nothing on Windows (and KDE), should it even be in the menus on Windows (or Linux)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternately, that could be a bug, It looks like that is supposed to be the same as "Maximize" in windows and linux, which don't appear anywhere in the menus on either (though they do appear in the window controls).

@@ -71,7 +70,7 @@ module.exports = function () {
},
{
role: 'togglefullscreen',
accelerators: accelerators.enterFullScreen
accelerators: commands['window:full']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window:toggleFullScreen, easier to understand

@albinekb albinekb added the 👩‍🔬 Status: In Progress Issue or PR is currently active and work is in progress label May 27, 2017
@ppot ppot force-pushed the keymap@part2 branch 2 times, most recently from 57cf0db to e867c29 Compare May 28, 2017 20:47
@ppot
Copy link
Contributor Author

ppot commented May 30, 2017

@albinekb Next review?

Copy link
Contributor

@albinekb albinekb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 Nice work!

@ppot ppot changed the title Part2 of keymaps Implements Commands Key mapping Jun 3, 2017
@ppot ppot merged commit 93b2229 into vercel:master Jun 3, 2017
@ppot ppot deleted the keymap@part2 branch June 3, 2017 00:03
@saadq
Copy link

saadq commented Aug 15, 2017

This is awesome. Is there going to be a way to see a list of available commands, or maybe have a way to allow commands to be logged to the console when you do some action (similar to Sublime Text's sublime.log_commands(True)?

@ppot
Copy link
Contributor Author

ppot commented Aug 15, 2017

mmm Make an issue for this as a suggestion ;) something like a command invocation actions

@stereokai
Copy link

@ppot Does this fix Command ctrl + C does not work #1121?

@computersarecool
Copy link

So,
Given the status of this pull request, how would one enable Readlines (emacs) style keybindings in Hyperterm?

@sindrenm
Copy link

Hype! Can confirm that this is indeed working! 🎉 👏

Any idea when it'll get released? 😀

@computersarecool
Copy link

To me it is unclear from the title "Implements Commands Key mapping" what this pull request will do but it closes a lot of open issues.

@ppot will this pull request make it so that keybindings in the Hyper terminal emulator will work as they should?

i.e. will these work?

@ELLIOTTCABLE
Copy link

Ditto @computersarecool, especially given that this is linked from the v1.4.0 release-notes — what, exactly, just got added? ^_^

@ynnoj
Copy link

ynnoj commented Aug 31, 2017

@computersarecool @ELLIOTTCABLE https://hyper.is/#keymaps

@iamstarkov
Copy link
Contributor

for @ELLIOTTCABLE and everyone else looking for available shortcuts

look 'em up here https://github.com/zeit/hyper/blob/master/app/keymaps/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet