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

Change shortcut keys on Mac #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/data/os.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

module.exports = {
isMac: (/^Mac/).test(window.navigator.platform)
};
13 changes: 13 additions & 0 deletions src/ui/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function jack() {/*

"Right-Click in the area to the left to create a new repo"

-- If you are on ChromeOS, Linux, Windows
Global-Controls = {
Control-Shift-R: "Reload the app"
Control-Plus: "Increase font size"
Expand All @@ -189,6 +190,18 @@ function jack() {/*
-- If you manually close the tree by dragging, toggle remembers this.
}

-- But if you are on a Mac
Global-Controls-On-Mac = {
Command-Shift-R: "Reload the app"
Command-Plus: "Increase font size"
Command-Minus: "Decrease font size"
Command-B: "Apply next Theme"
Command-Shift-B: "Apply previous Theme"
Command-E: "Toggle focus between editor and file tree"
Command-N: "Create new file relative to current or selected"
Control-Tilde: "Switch between recently opened files"
}

File-Tree-Controls = {
Up: "Move the selection up"
Down: "Move the selection down"
Expand Down
18 changes: 10 additions & 8 deletions src/ui/global-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ var editor = require('./editor');
var tree = require('./tree');
var dialog = require('./dialog');
var doc = require('data/document');
var os = require('data/os');
var pending;

window.addEventListener("keydown", onDown, true);
window.addEventListener("keyup", onUp, true);
window.addEventListener("keypress", onPress, true);
function onDown(evt) {
var ctrlOrMeta = os.isMac ? evt.metaKey : evt.ctrlKey;
// Ctrl-0
if (evt.ctrlKey && !evt.shiftKey && evt.keyCode === 48) zoom.reset();
if (ctrlOrMeta && !evt.shiftKey && evt.keyCode === 48) zoom.reset();
// Ctrl-"+"
else if (evt.ctrlKey && !evt.shiftKey && evt.keyCode === 187) zoom.bigger();
else if (ctrlOrMeta && !evt.shiftKey && evt.keyCode === 187) zoom.bigger();
// Ctrl-"-"
else if (evt.ctrlKey && !evt.shiftKey && evt.keyCode === 189) zoom.smaller();
else if (ctrlOrMeta && !evt.shiftKey && evt.keyCode === 189) zoom.smaller();
// Ctrl-Shift-R
else if (evt.ctrlKey && evt.shiftKey && evt.keyCode === 82) chrome.runtime.reload();
else if (evt.ctrlKey && evt.keyCode === 66) {
else if (ctrlOrMeta && evt.shiftKey && evt.keyCode === 82) chrome.runtime.reload();
else if (ctrlOrMeta && evt.keyCode === 66) {
// Ctrl-Shift-B
if (evt.shiftKey) editor.prevTheme();
// Ctrl-B
Expand All @@ -32,16 +34,16 @@ function onDown(evt) {
else return;
}
// Alt+` switches between documents
else if (evt.altKey && evt.keyCode === 192) {
else if ((os.isMac ? evt.ctrlKey : evt.altKey) && evt.keyCode === 192) {
pending = true;
doc.next();
}
// Control-E Toggles Tree
else if (evt.ctrlKey && evt.keyCode === 69) {
else if (ctrlOrMeta && evt.keyCode === 69) {
tree.toggle();
}
// Control-N Create new file
else if (evt.ctrlKey && !evt.shiftKey && evt.keyCode === 78) {
else if (ctrlOrMeta && !evt.shiftKey && evt.keyCode === 78) {
tree.newFile();
}
else if (!tree.isFocused()) return;
Expand Down