add wrap_with_abbreviation emmet command
This commit is contained in:
parent
e97d7609b9
commit
8530e3837a
1 changed files with 17 additions and 7 deletions
|
|
@ -51,6 +51,8 @@ AceEmmetEditor.prototype = {
|
||||||
setupContext: function(editor) {
|
setupContext: function(editor) {
|
||||||
this.ace = editor;
|
this.ace = editor;
|
||||||
this.indentation = editor.session.getTabString();
|
this.indentation = editor.session.getTabString();
|
||||||
|
if (!emmet)
|
||||||
|
emmet = window.emmet;
|
||||||
emmet.require("resources").setVariable("indentation", this.indentation);
|
emmet.require("resources").setVariable("indentation", this.indentation);
|
||||||
this.$syntax = null;
|
this.$syntax = null;
|
||||||
this.$syntax = this.getSyntax();
|
this.$syntax = this.getSyntax();
|
||||||
|
|
@ -161,7 +163,7 @@ AceEmmetEditor.prototype = {
|
||||||
*/
|
*/
|
||||||
replaceContent: function(value, start, end, noIndent) {
|
replaceContent: function(value, start, end, noIndent) {
|
||||||
if (end == null)
|
if (end == null)
|
||||||
end = start == null ? content.length : start;
|
end = start == null ? this.getContent().length : start;
|
||||||
if (start == null)
|
if (start == null)
|
||||||
start = 0;
|
start = 0;
|
||||||
var utils = emmet.require("utils");
|
var utils = emmet.require("utils");
|
||||||
|
|
@ -228,7 +230,7 @@ AceEmmetEditor.prototype = {
|
||||||
if (state.length > 1)
|
if (state.length > 1)
|
||||||
syntax = state[0];
|
syntax = state[0];
|
||||||
else if (syntax == "php")
|
else if (syntax == "php")
|
||||||
syntax = "html"
|
syntax = "html";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return syntax;
|
return syntax;
|
||||||
|
|
@ -309,12 +311,13 @@ var keymap = {
|
||||||
// update_image_size: {"mac": "shift+ctrl+i", "win": "ctrl+u"},
|
// update_image_size: {"mac": "shift+ctrl+i", "win": "ctrl+u"},
|
||||||
// expand_as_you_type: "ctrl+alt+enter",
|
// expand_as_you_type: "ctrl+alt+enter",
|
||||||
// wrap_as_you_type: {"mac": "shift+ctrl+g", "win": "shift+ctrl+g"},
|
// 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();
|
var editorProxy = new AceEmmetEditor();
|
||||||
exports.commands = new HashHandler();
|
exports.commands = new HashHandler();
|
||||||
function runEmmetCommand(editor) {
|
exports.runEmmetCommand = function(editor) {
|
||||||
editorProxy.setupContext(editor);
|
editorProxy.setupContext(editor);
|
||||||
if (editorProxy.getSyntax() == "php")
|
if (editorProxy.getSyntax() == "php")
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -325,6 +328,13 @@ function runEmmetCommand(editor) {
|
||||||
return false;
|
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 {
|
try {
|
||||||
var result = actions.run(this.action, editorProxy);
|
var result = actions.run(this.action, editorProxy);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
@ -332,14 +342,14 @@ function runEmmetCommand(editor) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
|
|
||||||
for (var command in keymap) {
|
for (var command in keymap) {
|
||||||
exports.commands.addCommand({
|
exports.commands.addCommand({
|
||||||
name: "emmet:" + command,
|
name: "emmet:" + command,
|
||||||
action: command,
|
action: command,
|
||||||
bindKey: keymap[command],
|
bindKey: keymap[command],
|
||||||
exec: runEmmetCommand,
|
exec: exports.runEmmetCommand,
|
||||||
multiSelectAction: "forEach"
|
multiSelectAction: "forEach"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -359,7 +369,7 @@ var onChangeMode = function(e, target) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.AceEmmetEditor = AceEmmetEditor
|
exports.AceEmmetEditor = AceEmmetEditor;
|
||||||
require("ace/config").defineOptions(Editor.prototype, "editor", {
|
require("ace/config").defineOptions(Editor.prototype, "editor", {
|
||||||
enableEmmet: {
|
enableEmmet: {
|
||||||
set: function(val) {
|
set: function(val) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue