Skip to content

Commit f5ffcb8

Browse files
committed
fixes #86
1 parent de1c4b9 commit f5ffcb8

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

app/appshell/app-menu.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as _ from "lodash";
88
import * as assert from "assert";
99
import { app, Menu } from "electron";
1010
import * as shell from "./shell";
11-
import * as electronLocalshortcut from "electron-localshortcut";
1211

1312
const menuTemplate: MenuItemOptions[] = [];
1413

@@ -21,15 +20,11 @@ app.on("browser-window-blur", function () {
2120
_refreshMenu();
2221
});
2322

24-
// if overriden, these won't work in Brackets modal windows like Git commit
25-
const systemShortcuts = ["Ctrl+Z", "Ctrl+Y", "Ctrl+X", "Ctrl+C", "Ctrl+V", "Ctrl+A"];
23+
let currentShortcuts: { [accelerator: string]: string } = {};
2624

2725
function registerShortcuts(win: Electron.BrowserWindow, menuItem: MenuItemOptions) {
28-
if (
29-
menuItem.accelerator &&
30-
systemShortcuts.find((x) => x === menuItem.accelerator) == null
31-
) {
32-
electronLocalshortcut.register(win, menuItem.accelerator, menuItem.click as Function);
26+
if (menuItem.accelerator && menuItem.id) {
27+
currentShortcuts[menuItem.accelerator] = menuItem.id;
3328
}
3429
if (Array.isArray(menuItem.submenu)) {
3530
menuItem.submenu.forEach((i) => registerShortcuts(win, i));
@@ -39,9 +34,10 @@ function registerShortcuts(win: Electron.BrowserWindow, menuItem: MenuItemOption
3934
const __refreshMenu = _.debounce(function () {
4035
Menu.setApplicationMenu(Menu.buildFromTemplate(_.cloneDeep(menuTemplate)));
4136
const mainWindow = shell.getMainWindow();
42-
electronLocalshortcut.unregisterAll(mainWindow);
4337
if (mainWindow.isFocused()) {
38+
currentShortcuts = {};
4439
menuTemplate.forEach((menuItem) => registerShortcuts(mainWindow, menuItem));
40+
mainWindow.webContents.send("updateShortcuts", JSON.stringify(currentShortcuts));
4541
}
4642
}, 100);
4743

app/electron-localshortcut.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"async": "2.3.0",
6767
"chokidar": "1.6.1",
6868
"decompress-zip": "0.3.0",
69-
"electron-localshortcut": "1.1.1",
7069
"fs-extra": "2.1.2",
7170
"isbinaryfile": "3.0.2",
7271
"lodash": "4.17.4",

src/editor/Editor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ define(function (require, exports, module) {
365365

366366
// Editor supplies some standard keyboard behavior extensions of its own
367367
var codeMirrorKeyMap = {
368+
"Ctrl-D": function () { window.triggerKeyboardShortcut("Ctrl-D"); },
369+
368370
"Tab": function () { self._handleTabKey(); },
369371
"Shift-Tab": "indentLess",
370372

src/utils/ShellAPI.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ define(function (require, exports, module) {
77
const Commands = require("command/Commands");
88

99
let appReady = false; // Set to true after app is fully initialized
10+
let appShortcuts: { [shortcut: string]: string } = {};
1011

11-
electron.ipcRenderer.on("executeCommand", function (evt: any, eventName: string) {
12+
electron.ipcRenderer.on("updateShortcuts", function (evt: any, data: string) {
13+
appShortcuts = JSON.parse(data);
14+
});
15+
16+
function executeCommand(eventName: string) {
1217
// Temporary fix for #2616 - don't execute the command if a modal dialog is open.
1318
// This should really be fixed with proper menu enabling.
1419
if ($(".modal.instance").length || !appReady) {
@@ -25,6 +30,18 @@ define(function (require, exports, module) {
2530

2631
const promise = CommandManager.execute(eventName);
2732
return (promise && promise.state() === "rejected") ? false : true;
33+
}
34+
35+
(window as any).triggerKeyboardShortcut = (shortcut: string) => {
36+
const normalized = shortcut.replace(/-/g, "+");
37+
if (appShortcuts[normalized]) {
38+
return executeCommand(appShortcuts[normalized]);
39+
}
40+
return null;
41+
};
42+
43+
electron.ipcRenderer.on("executeCommand", function (evt: any, eventName: string) {
44+
return executeCommand(eventName);
2845
});
2946

3047
electron.ipcRenderer.on("console-msg", function (evt: any, method: string, ...args: string[]) {

0 commit comments

Comments
 (0)