From 5d2bb091043c6fa52fcf6d599c9c698507b17452 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 20 Jul 2015 13:31:27 +0400 Subject: [PATCH] allow expand_abbreviation emmet command for all modes --- node_modules/ace/lib/ace/ext/emmet.js | 42 ++++++++++++++++++++------- package.json | 2 +- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/node_modules/ace/lib/ace/ext/emmet.js b/node_modules/ace/lib/ace/ext/emmet.js index 3c5d6344..6276ce98 100644 --- a/node_modules/ace/lib/ace/ext/emmet.js +++ b/node_modules/ace/lib/ace/ext/emmet.js @@ -343,11 +343,9 @@ var keymap = { var editorProxy = new AceEmmetEditor(); exports.commands = new HashHandler(); -exports.runEmmetCommand = function(editor) { +exports.runEmmetCommand = function runEmmetCommand(editor) { try { editorProxy.setupContext(editor); - if (editorProxy.getSyntax() == "php") - return false; var actions = emmet.require("actions"); if (this.action == "expand_abbreviation_with_tab") { @@ -369,6 +367,10 @@ exports.runEmmetCommand = function(editor) { var result = actions.run(this.action, editorProxy); } catch(e) { + if (!emmet) { + load(runEmmetCommand.bind(this, editor)); + return true; + } editor._signal("changeStatus", typeof e == "string" ? e : e.message); console.log(e); result = false; @@ -401,6 +403,22 @@ exports.isSupportedMode = function(mode) { return /css|less|scss|sass|stylus|html|php|twig|ejs|handlebars/.test(id); }; +exports.isAvailable = function(editor, command) { + if (/(evaluate_math_expression|expand_abbreviation)$/.test(command)) + return true; + var mode = editor.session.$mode; + var isSupported = exports.isSupportedMode(mode); + if (isSupported && mode.$modes) { + // TODO refactor mode delegates to make this simpler + try { + editorProxy.setupContext(editor); + if (/js|php/.test(editorProxy.getSyntax())) + isSupported = false; + } catch(e) {} + } + return isSupported; +} + var onChangeMode = function(e, target) { var editor = target; if (!editor) @@ -408,16 +426,20 @@ var onChangeMode = function(e, target) { var enabled = exports.isSupportedMode(editor.session.$mode); if (e.enableEmmet === false) enabled = false; - if (enabled) { - if (typeof emmetPath == "string") { - require("ace/config").loadModule(emmetPath, function() { - emmetPath = null; - }); - } - } + if (enabled) + load(); exports.updateCommands(editor, enabled); }; +var load = function(cb) { + if (typeof emmetPath == "string") { + require("ace/config").loadModule(emmetPath, function() { + emmetPath = null; + cb && cb(); + }); + } +}; + exports.AceEmmetEditor = AceEmmetEditor; require("ace/config").defineOptions(Editor.prototype, "editor", { enableEmmet: { diff --git a/package.json b/package.json index 40d80271..99dea221 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "c9.ide.find.replace": "#44772dd796", "c9.ide.run.debug": "#c7f1ed5d5d", "c9.automate": "#47e2c429c9", - "c9.ide.ace.emmet": "#0ab4c6cd68", + "c9.ide.ace.emmet": "#6dc4585e02", "c9.ide.ace.gotoline": "#a8ff07c8f4", "c9.ide.ace.keymaps": "#43445d6306", "c9.ide.ace.repl": "#f3a62c1f2a",