Skip to content

Instantly share code, notes, and snippets.

@jviereck
Created February 16, 2010 19:19
Show Gist options
  • Save jviereck/305810 to your computer and use it in GitHub Desktop.
Save jviereck/305810 to your computer and use it in GitHub Desktop.
Adds CMD + L shortcut that sets the commandline's value to "goto ".
diff --git a/plugins/supported/CommandLine/views/cli.js b/plugins/supported/CommandLine/views/cli.js
--- a/plugins/supported/CommandLine/views/cli.js
+++ b/plugins/supported/CommandLine/views/cli.js
@@ -430,16 +430,36 @@ console.log("trying to set completion to
/**
* Push the focus into the input element
*/
focus: function() {
this.getPath("contentView.input").becomeFirstResponder();
},
/**
+ * Sets the value of the commandline.
+ *
+ * @param text{String} Value to use as commandline value.
+ * @param setCursorToEnd{Boolean} If true, the commandline's cursor is
+ * set to the of the new text.
+ */
+ setValue: function(text, setCursorToEnd) {
+ var input = this.getPath("contentView.input");
+ input.set('value', text);
+ if (setCursorToEnd) {
+ window.setTimeout(function() {
+ var sel = new SC.TextSelection();
+ sel.set('start', text.length);
+ sel.set('end', text.length);
+ input.set('selection', sel);
+ }, 1);
+ }
+ },
+
+ /**
* There's no good reason for having this contentView - the childViews could
* be directly on CliInputView, except that the observes() on focusChanged
* is borked without it.
* TODO: Work out what the borkage is about and fix
*/
contentView: SC.View.design({
childViews: [ "display", "prompt", "input", "submit" ],
diff --git a/plugins/supported/Editor/commands/editor.js b/plugins/supported/Editor/commands/editor.js
--- a/plugins/supported/Editor/commands/editor.js
+++ b/plugins/supported/Editor/commands/editor.js
@@ -32,32 +32,40 @@
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var util = require("bespin:util/util");
var settings = require("Settings").settings;
+var pluginCatalog = require("bespin:plugins").catalog;
/**
* 'goto' command
*/
exports.gotoCommand = function(env, args, request) {
if (args.value) {
var textView = env.get("view");
+ textView.focus();
textView._moveCursorTo({
- row: args.value - 1,
- column: 0
- });
- textView.focus();
+ row: args.value - 1,
+ column: 0
+ });
}
-
};
+exports.jumpCommandlineAndGoto = function() {
+ var cli = pluginCatalog.getObject("cli");
+ if (cli) {
+ cli.focus();
+ cli.setValue('goto ', true);
+ }
+}
+
/**
* 'replace' command
*/
exports.replaceCommand = function(env, args, request) {
editor.replace(args);
};
/**
diff --git a/plugins/supported/Editor/plugin.json b/plugins/supported/Editor/plugin.json
--- a/plugins/supported/Editor/plugin.json
+++ b/plugins/supported/Editor/plugin.json
@@ -282,11 +282,18 @@
"pointer": "commands/editor#ucCommand"
},
{
"ep": "command",
"name": "lc",
"description": "Change all selected text to lowercase",
"withKey": "CMD SHIFT L",
"pointer": "commands/editor#lcCommand"
+ },
+ {
+ "ep": "command",
+ "name": "goto-commandline",
+ "key": "ctrl_l",
+ "predicates": { "isTextView": true },
+ "pointer": "commands/editor#jumpCommandlineAndGoto"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment