Permalink
Browse files

Added interactive commands

  • Loading branch information...
1 parent dc6f55d commit e1f341ff9f3830522de5a5624252e31b1f4b5c8a @sergeche sergeche committed May 2, 2014
Showing with 86 additions and 32 deletions.
  1. +3 −6 brackets-fs.js
  2. +34 −4 interactive.js
  3. +1 −0 keymap.json
  4. +45 −21 main.js
  5. +1 −1 package.json
  6. +2 −0 prompt.js
View
@@ -4,10 +4,7 @@ define(function(require, exports, module) {
var FileSystem = brackets.getModule('filesystem/FileSystem');
emmetFile({
- _exists: function(file) {
-
- },
- read: function(file, size, callback) {
+ read: function(file, callback) {
var fd = FileSystem.getFileForPath(file);
if (!fd) {
return callback('File "' + path + '" does not exists.');
@@ -16,8 +13,8 @@ define(function(require, exports, module) {
fd.read({encoding: 'utf8'}, callback);
},
- readText: function(file, size, callback) {
- return this.read(file, size, callback);
+ readText: function(file, callback) {
+ return this.read(file, callback);
},
locateFile: function(editorFile, fileName) {
View
@@ -70,13 +70,43 @@ define(function(require, exports, module) {
editor.setCaretPos(selCtx[i].caret);
}
}
- editor.editor.focus();
}
return {
- wrapWithAbbreviation: function(editor) {
- // first we have to cache context for each selection
- var selCtx = selectionContext(editor);
+ run: function(cmd, editor) {
+ if (cmd === 'wrap_with_abbreviation') {
+ return this.wrapWithAbbreviation(editor);
+ }
+
+ if (cmd === 'update_tag') {
+ return this.updateTag(editor);
+ }
+
+ if (cmd === 'interactive_expand_abbreviation') {
+ return this.expandAbbreviation(editor);
+ }
+ },
+
+ expandAbbreviation: function(editor) {
+ var info = editorUtils.outputInfo(editor);
+ var selCtx = editor.selectionList().map(function(sel, i) {
+ editor.selectionIndex = i;
+ var r = range(editor.getSelectionRange());
+ return {
+ selection: r,
+ caret: r.start,
+ syntax: info.syntax,
+ profile: info.profile || null,
+ counter: editor.selectionIndex + 1,
+ contextNode: actionUtils.captureContext(editor, r.start)
+ };
+ });
+
+ return this.wrapWithAbbreviation(editor, selCtx);
+ },
+
+ wrapWithAbbreviation: function(editor, selCtx) {
+ selCtx = selCtx || selectionContext(editor);
// show prompt dialog that will wrap each selection
// on user typing
View
@@ -14,6 +14,7 @@
"split_join_tag": "Ctrl-Shift-J",
"remove_tag": "Ctrl-Shift-K",
"evaluate_math_expression": "Shift-Ctrl-Y",
+ "update_tag": "Shift-Ctrl-I",
"increment_number_by_1": "Ctrl-Shift-Up",
"decrement_number_by_1": "Ctrl-Shift-Down",
View
@@ -6,12 +6,12 @@ define(function(require, exports, module) {
var prompt = require('./prompt');
var interactive = require('./interactive');
- var emmet = require('emmet/emmet');
- var resources = require('emmet/assets/resources');
- var actions = require('emmet/action/main');
- var keymap = require('text!keymap.json');
- var snippets = require('text!emmet/snippets.json');
- var ciu = require('text!emmet/caniuse.json');
+ var emmet = require('emmet/emmet');
+ var resources = require('emmet/assets/resources');
+ var actions = require('emmet/action/main');
+ var keymap = require('text!keymap.json');
+ var snippets = require('text!emmet/snippets.json');
+ var ciu = require('text!emmet/caniuse.json');
var CommandManager = brackets.getModule('command/CommandManager');
var KeyBindingManager = brackets.getModule('command/KeyBindingManager');
@@ -161,6 +161,31 @@ define(function(require, exports, module) {
}
}
+ /**
+ * Register special, interactive versions of some Emmet actions
+ */
+ function registerInteractiveCommands(menu) {
+ ['wrap_with_abbreviation', 'update_tag', 'interactive_expand_abbreviation'].forEach(function(cmd) {
+ var action = actions.get(cmd);
+ CommandManager.register(actionLabel(action, cmd), 'io.emmet.' + cmd, function() {
+ editor.setup(EditorManager.getFocusedEditor());
+ interactive.run(cmd, editor);
+ });
+ });
+
+ menu.addMenuItem('io.emmet.interactive_expand_abbreviation', 'Alt-Enter');
+ }
+
+ function actionLabel(action, fallback) {
+ if (action && action.options.label) {
+ return action.options.label.split('/').pop().replace(/\\/g, '/');
+ }
+
+ return fallback.replace(/^[a-z]|_([a-z])/g, function(str, ch) {
+ return str.toUpperCase().replace('_', ' ');
+ });
+ }
+
function init() {
try {
if (typeof keymap == 'string') {
@@ -173,21 +198,27 @@ define(function(require, exports, module) {
emmet.loadSystemSnippets(snippets);
emmet.loadCIU(ciu);
- // register all commands
var menu = Menus.addMenu('Emmet', 'io.emmet.EmmetMainMenu');
+ registerInteractiveCommands(menu);
+
+ // register all commands
actions.getList().forEach(function(action) {
- if (~skippedActions.indexOf(action)) {
+ if (~skippedActions.indexOf(action.name)) {
return;
}
var id = 'io.emmet.' + action.name;
- var shortcut = keymap[action.name];
- var cmd = ~singleSelectionActions.indexOf(action.name)
- ? actionDecorator(action.name)
- : multiSelectionActionDecorator(action.name);
-
- CommandManager.register(action.options.label, id, cmd);
+
+ if (!CommandManager.get(id)) {
+ // regiester new command only if wasn’t defined previously
+ var cmd = ~singleSelectionActions.indexOf(action.name)
+ ? actionDecorator(action.name)
+ : multiSelectionActionDecorator(action.name);
+
+ CommandManager.register(actionLabel(action), id, cmd);
+ }
+ var shortcut = keymap[action.name];
if (!action.options.hidden) {
menu.addMenuItem(id, shortcut);
} else if (shortcut) {
@@ -197,13 +228,6 @@ define(function(require, exports, module) {
menu.addMenuDivider();
- // debug panel
- CommandManager.register('Show Emmet panel', 'io.emmet.show_panel', function() {
- editor.setup(EditorManager.getFocusedEditor());
- interactive.updateTag(editor);
- });
- KeyBindingManager.addBinding('io.emmet.show_panel', 'Alt-F1');
-
// Allow enable and disable Emmet
var cmdEnable = CommandManager.register('Enable Emmet', 'io.emmet.enabled', function() {
this.setChecked(!this.getChecked());
View
@@ -17,6 +17,6 @@
"brackets": ">=0.38.0"
},
"dependencies": {
- "emmet": "^1.1.2"
+ "emmet": "^1.1.3"
}
}
View
@@ -82,12 +82,14 @@ define(function(require, exports, module) {
})
.on('confirm.emmet', function(evt, value) {
method(delegate, 'confirm')();
+ delegate.editor.focus();
})
.on('cancel.emmet', function(evt) {
if (updated) {
delegate.editor.undo();
}
method(delegate, 'cancel')();
+ delegate.editor.focus();
});
input.focus();

0 comments on commit e1f341f

Please sign in to comment.