From c428908211d4e5e9483457da65f15e277c8997e5 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Sun, 20 Feb 2011 17:13:15 +0100 Subject: [PATCH] Add examples for new command.bindKey to demo.js, update Pilot & Cockpit --- demo/demo.js | 64 +++++++++++++++++++++++++++++++++- lib/ace/keyboard/keybinding.js | 6 ++-- support/cockpit | 2 +- support/pilot | 2 +- 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index ee13653e..68afd3d6 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -40,7 +40,7 @@ define(function(require, exports, module) { exports.launch = function(env) { - + var canon = require("pilot/canon"); var event = require("pilot/event"); var Editor = require("ace/editor").Editor; var Renderer = require("ace/virtual_renderer").VirtualRenderer; @@ -354,6 +354,68 @@ exports.launch = function(env) { }); window.env = env; + + /** + * This demonstrates how you can define commands and bind shortcuts to them. + */ + + // Command to focus the command line from the editor. + canon.addCommand({ + name: "focuscli", + bindKey: { + win: "Ctrl-J", + mac: "Command-J", + sender: "editor" + }, + exec: function() { + env.cli.cliView.element.focus(); + } + }); + + // Command to focus the editor line from the command line. + canon.addCommand({ + name: "focuseditor", + bindKey: { + win: "Ctrl-J", + mac: "Command-J", + sender: "cli" + }, + exec: function() { + env.editor.focus(); + } + }); + + // Fake-Save, works from the editor and the command line. + canon.addCommand({ + name: "save", + bindKey: { + win: "Ctrl-S", + mac: "Command-S", + sender: "editor|cli" + }, + exec: function() { + alert("Fake Save File"); + } + }); + + // Fake-Print with custom lookup-sender-match function. + canon.addCommand({ + name: "save", + bindKey: { + win: "Ctrl-P", + mac: "Command-P", + sender: function(env, sender, hashId, keyString) { + if (sender == "editor") { + return true; + } else { + alert("Sorry, can only print from the editor"); + } + } + }, + exec: function() { + alert("Fake Print File"); + } + }); }; }); diff --git a/lib/ace/keyboard/keybinding.js b/lib/ace/keyboard/keybinding.js index 2fe89ca3..93fc3fa8 100644 --- a/lib/ace/keyboard/keybinding.js +++ b/lib/ace/keyboard/keybinding.js @@ -98,10 +98,8 @@ var KeyBinding = function(editor) { }; this.onCommandKey = function(e, hashId, keyCode) { - key = (keyUtil[keyCode] || - String.fromCharCode(keyCode)).toLowerCase(); - - this.$callKeyboardHandler(e, hashId, key, keyCode); + var keyString = keyUtil.keyCodeToString(keyCode); + this.$callKeyboardHandler(e, hashId, keyString, keyCode); }; this.onTextInput = function(text) { diff --git a/support/cockpit b/support/cockpit index 1fa3516d..7362e033 160000 --- a/support/cockpit +++ b/support/cockpit @@ -1 +1 @@ -Subproject commit 1fa3516d4d553af9f6edd81c20023bcfab08c2a3 +Subproject commit 7362e0331327321f4d743ad70a8ded16327443f2 diff --git a/support/pilot b/support/pilot index 5d07cccd..c5a615be 160000 --- a/support/pilot +++ b/support/pilot @@ -1 +1 @@ -Subproject commit 5d07cccd2e8d0ca22b170693afda5199a69de062 +Subproject commit c5a615beea2b6cda2920bc2779dae33065009939