commandline.js
来自「在线编辑器」· JavaScript 代码 · 共 502 行 · 第 1/2 页
JS
502 行
} }});// ** {{{ bespin.cmd.commandline.KeyBindings }}} **//// Handle key bindings for the command linedojo.declare("bespin.cmd.commandline.KeyBindings", null, { constructor: function(cl) { // -- Tie to the commandLine element itself dojo.connect(cl.commandLine, "onfocus", cl, function() { if (window['_editor']) _editor.setFocus(false); this.inCommandLine = true; dojo.byId('promptimg').src = 'images/icn_command_on.png'; }); dojo.connect(cl.commandLine, "onblur", cl, function() { this.inCommandLine = false; dojo.byId('promptimg').src = 'images/icn_command.png'; }); dojo.connect(cl.commandLine, "onkeyup", cl, function(e) { if (e.keyChar >= "A".charCodeAt() && e.keyChar < "Z".charCodeAt()) { // only real letters var completions = this.findCompletions(dojo.byId('command').value); var commandString = completions[0]; if (completions.length > 0) { var isAutoComplete = _settings.isOn(_settings.get('autocomplete')); if (isAutoComplete && completions.length == 1) { // if only one just set the value var command = this.commands[commandString] || this.commands[this.aliases[commandString]]; var spacing = (this.commandTakesArgs(command)) ? ' ' : ''; dojo.byId('command').value = commandString + spacing; if (command['completeText']) { this.showInfo(command['completeText']); } else { this.hideInfo(); } } else if (completions.length == 1) { if (completions[0] != dojo.byId('command').value) { this.showInfo(completions.join(', ')); } else { var command = this.commands[completions[0]] || this.commands[this.aliases[completions[0]]]; if (this.commandTakesArgs(command)) { this.complete(dojo.byId('command').value); // make it complete } else { this.hideInfo(); } } } else { this.showInfo(completions.join(', ')); } } } }); dojo.connect(cl.commandLine, "onkeypress", cl, function(e) { if (e.keyChar == 'j' && e.ctrlKey) { // send back dojo.stopEvent(e); dojo.byId('command').blur(); if (window['_editor']) _editor.setFocus(true); return false; } else if ((e.keyChar == 'n' && e.ctrlKey) || e.keyCode == dojo.keys.DOWN_ARROW) { this.commandLineHistory.setNext(); return false; } else if ((e.keyChar == 'p' && e.ctrlKey) || e.keyCode == dojo.keys.UP_ARROW) { this.commandLineHistory.setPrevious(); return false; } else if (e.keyCode == dojo.keys.ENTER) { this.executeCommand(dojo.byId('command').value); return false; } else if (e.keyCode == dojo.keys.TAB) { dojo.stopEvent(e); this.complete(dojo.byId('command').value); return false; } else if (e.keyCode == dojo.keys.ESCAPE) { this.hideInfo(); } }); }});// ** {{{ bespin.cmd.commandline.History }}} **//// Store command line history so you can go back and forthdojo.declare("bespin.cmd.commandline.History", null, { constructor: function(cl) { this.commandLine = cl; this.history = []; this.pointer = 0; this.store = new bespin.cmd.commandline.SimpleHistoryStore(); this.seed(); }, // TODO: get from the database seed: function() { this.history = this.store.seed(); }, add: function(command) { command = dojo.trim(command); if (this.last() != command) { this.store.add(command); this.history.push(command); this.pointer = this.history.length - 1; } }, next: function() { if (this.pointer < this.history.length) { return this.history[this.pointer++]; } }, previous: function() { if (this.pointer > 0) { return this.history[this.pointer--]; } }, last: function() { return this.history[this.history.length - 1]; }, first: function() { return this.history[0]; }, set: function(command) { this.commandLine.commandLine.value = command; }, setNext: function() { var next = this.next(); if (next) { this.set(next); } }, setPrevious: function() { var prev = this.previous(); if (prev) { this.set(prev); } }});// ** {{{ bespin.cmd.commandline.SimpleHistoryStore }}} **//// A simple store that keeps the commands in memory.// In the future we would want to store the history cross session.dojo.declare("bespin.cmd.commandline.SimpleHistoryStore", null, { constructor: function() { this.commands = []; }, seed: function() { this.add('ls'); this.add('clear'); this.add('status'); return dojo.clone(this.commands); }, add: function(command) { this.commands.push(command); }});// ** {{{ bespin.cmd.commandline.Events }}} **//// The custom events that the commandline participates indojo.declare("bespin.cmd.commandline.Events", null, { constructor: function(commandline) { this.commandline = commandline; // ** {{{ Event: bespin:cmdline:showinfo }}} ** // // Observe when others want to show the info bar for the command line bespin.subscribe("bespin:cmdline:showinfo", function(event) { var msg = event.msg; var autohide = event.autohide; if (msg) commandline.showInfo(msg, autohide); }); // ** {{{ Event: bespin:cmdline:executed }}} ** // // Once the command has been executed, do something. // In this case, save it for the history bespin.subscribe("bespin:cmdline:executed", function(event) { var commandname = event.command.name; var args = event.args; commandline.commandLineHistory.add(commandname + " " + args); // only add to the history when a valid command }); // ** {{{ Event: bespin:cmdline:executed }}} ** // // Once the command has been executed, do something. bespin.subscribe("bespin:cmdline:execute", function(event) { var command = event.name; var args = event.args; if (command && args) { // if we have a command and some args command += " " + args; } if (command) commandline.executeCommand(command); }); // -- Files // ** {{{ Event: bespin:editor:openfile:openfail }}} ** // // If an open file action failed, tell the user. bespin.subscribe("bespin:editor:openfile:openfail", function(event) { var filename = event.filename; commandline.showInfo('Could not open file: ' + filename + "<br/><br/><em>(maybe try » list)</em>"); }); // ** {{{ Event: bespin:editor:openfile:opensuccess }}} ** // // The open file action worked, so tell the user bespin.subscribe("bespin:editor:openfile:opensuccess", function(event) { var file = event.file; commandline.showInfo('Loaded file: ' + file.name, true); }); // -- Projects // ** {{{ Event: bespin:editor:project:set }}} ** // // When the project changes, alert the user bespin.subscribe("bespin:editor:project:set", function(event) { var project = event.project; _editSession.project = project; commandline.showInfo('Changed project to ' + project, true); }); }});
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?