Skip to content
This repository was archived by the owner on Aug 22, 2019. It is now read-only.

Commit adfea61

Browse files
committed
Improved syntax detection
Plugin now registers all available actions, not only those with keybindings
1 parent ac13819 commit adfea61

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

dist/emmet.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,15 @@ var EmmetEditor = (function () {
170170
},
171171
getSyntax: {
172172
value: function getSyntax() {
173-
var syntax = this.context.getOption("mode");
174-
return modeMap[syntax] || emmet.utils.action.detectSyntax(this, syntax);
173+
var editor = this.context;
174+
var pos = editor.posFromIndex(this.getCaretPos());
175+
var mode = editor.getModeAt(editor.getCursor());
176+
var syntax = mode.name;
177+
if (syntax === "xml" && mode.configuration) {
178+
syntax = mode.configuration;
179+
}
180+
181+
return syntax || emmet.utils.action.detectSyntax(this, syntax);
175182
}
176183
},
177184
getProfileName: {
@@ -32471,6 +32478,7 @@ define(function(require, exports, module) {
3247132478
require: require,
3247232479

3247332480
// expose some useful data for plugin authors
32481+
actions: actions,
3247432482
file: file,
3247532483
preferences: preferences,
3247632484
resources: resources,
@@ -44495,9 +44503,9 @@ main.emmet = emmet;
4449544503
main.EmmetEditor = EmmetEditor;
4449644504
main.setup = function (CodeMirror) {
4449744505
// setup default Emmet actions
44498-
Object.keys(defaultKeymap).forEach(function (key) {
44499-
var command = defaultKeymap[key];
44500-
var action = command.replace(/^emmet\./, "");
44506+
emmet.actions.getList().forEach(function (obj) {
44507+
var action = obj.name;
44508+
var command = "emmet." + action;
4450144509

4450244510
if (!CodeMirror.commands[command]) {
4450344511
CodeMirror.commands[command] = ~singleSelectionActions.indexOf(action) ? actionDecorator(action) : multiSelectionActionDecorator(action);
@@ -44585,7 +44593,9 @@ function runAction(name, editor) {
4458544593
if (!result && name == "insert_formatted_line_break_only") {
4458644594
return noop();
4458744595
}
44588-
} catch (e) {}
44596+
} catch (e) {
44597+
console.error(e);
44598+
}
4458944599

4459044600
return result;
4459144601
}

editor.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,15 @@ export default class EmmetEditor {
131131
}
132132

133133
getSyntax() {
134-
var syntax = this.context.getOption('mode');
135-
return modeMap[syntax] || emmet.utils.action.detectSyntax(this, syntax);
134+
var editor = this.context;
135+
var pos = editor.posFromIndex(this.getCaretPos());
136+
var mode = editor.getModeAt(editor.getCursor());
137+
var syntax = mode.name;
138+
if (syntax === 'xml' && mode.configuration) {
139+
syntax = mode.configuration;
140+
}
141+
142+
return syntax || emmet.utils.action.detectSyntax(this, syntax);
136143
}
137144

138145
/**

index.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<script src="./node_modules/codemirror/mode/xml/xml.js"></script>
88
<script src="./node_modules/codemirror/mode/css/css.js"></script>
99
<script src="./node_modules/codemirror/mode/htmlmixed/htmlmixed.js"></script>
10-
<script src="./dist/plugin.js"></script>
10+
<script src="./dist/emmet.js"></script>
1111

1212
<style>
1313
.CodeMirror {
@@ -27,6 +27,11 @@ <h1>Emmet for CodeMirror 4</h1>
2727
&lt;!-- this is a comment --&gt;
2828
&lt;head&gt;
2929
&lt;title&gt;HTML Example&lt;/title&gt;
30+
&lt;style&gt;
31+
body {
32+
padding: 10px;
33+
}
34+
&lt;/style&gt;
3035
&lt;/head&gt;
3136
&lt;body&gt;
3237
The indentation tries to be &lt;em&gt;somewhat &amp;quot;do what

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"homepage": "https://github.com/emmetio/codemirror",
2828
"dependencies": {
29-
"emmet": "^1.2.3"
29+
"emmet": "^1.2.4"
3030
},
3131
"devDependencies": {
3232
"codemirror": "^5.0.0",

plugin.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ main.emmet = emmet;
6666
main.EmmetEditor = EmmetEditor;
6767
main.setup = function(CodeMirror) {
6868
// setup default Emmet actions
69-
Object.keys(defaultKeymap).forEach(key => {
70-
var command = defaultKeymap[key]
71-
var action = command.replace(/^emmet\./, '');
69+
emmet.actions.getList().forEach(obj => {
70+
var action = obj.name;
71+
var command = 'emmet.' + action;
7272

7373
if (!CodeMirror.commands[command]) {
7474
CodeMirror.commands[command] = ~singleSelectionActions.indexOf(action)
@@ -156,7 +156,9 @@ function runAction(name, editor) {
156156
if (!result && name == 'insert_formatted_line_break_only') {
157157
return noop();
158158
}
159-
} catch (e) {}
159+
} catch (e) {
160+
console.error(e);
161+
}
160162

161163
return result;
162164
}

0 commit comments

Comments
 (0)