add wrap_with_abbreviation emmet command

This commit is contained in:
Harutyun Amirjanyan 2013-05-27 11:49:38 -04:00
commit 8530e3837a

View file

@ -51,6 +51,8 @@ AceEmmetEditor.prototype = {
setupContext: function(editor) {
this.ace = editor;
this.indentation = editor.session.getTabString();
if (!emmet)
emmet = window.emmet;
emmet.require("resources").setVariable("indentation", this.indentation);
this.$syntax = null;
this.$syntax = this.getSyntax();
@ -161,7 +163,7 @@ AceEmmetEditor.prototype = {
*/
replaceContent: function(value, start, end, noIndent) {
if (end == null)
end = start == null ? content.length : start;
end = start == null ? this.getContent().length : start;
if (start == null)
start = 0;
var utils = emmet.require("utils");
@ -228,7 +230,7 @@ AceEmmetEditor.prototype = {
if (state.length > 1)
syntax = state[0];
else if (syntax == "php")
syntax = "html"
syntax = "html";
}
}
return syntax;
@ -309,12 +311,13 @@ var keymap = {
// update_image_size: {"mac": "shift+ctrl+i", "win": "ctrl+u"},
// expand_as_you_type: "ctrl+alt+enter",
// wrap_as_you_type: {"mac": "shift+ctrl+g", "win": "shift+ctrl+g"},
expand_abbreviation_with_tab: "Tab"
expand_abbreviation_with_tab: "Tab",
wrap_with_abbreviation: {"mac": "shift+ctrl+a", "win": "shift+ctrl+a"}
};
var editorProxy = new AceEmmetEditor();
exports.commands = new HashHandler();
function runEmmetCommand(editor) {
exports.runEmmetCommand = function(editor) {
editorProxy.setupContext(editor);
if (editorProxy.getSyntax() == "php")
return false;
@ -325,6 +328,13 @@ function runEmmetCommand(editor) {
return false;
}
if (this.action == "wrap_with_abbreviation") {
// without setTimeout prompt doesn't work on firefox
return setTimeout(function() {
actions.run("wrap_with_abbreviation", editorProxy);
}, 0);
}
try {
var result = actions.run(this.action, editorProxy);
} catch(e) {
@ -332,14 +342,14 @@ function runEmmetCommand(editor) {
console.log(e);
}
return result;
}
};
for (var command in keymap) {
exports.commands.addCommand({
name: "emmet:" + command,
action: command,
bindKey: keymap[command],
exec: runEmmetCommand,
exec: exports.runEmmetCommand,
multiSelectAction: "forEach"
});
}
@ -359,7 +369,7 @@ var onChangeMode = function(e, target) {
};
exports.AceEmmetEditor = AceEmmetEditor
exports.AceEmmetEditor = AceEmmetEditor;
require("ace/config").defineOptions(Editor.prototype, "editor", {
enableEmmet: {
set: function(val) {