Skip to content

Commit d2f951a

Browse files
committed
adding emmet integration
1 parent 05c4373 commit d2f951a

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

client/modules/IDE/components/Editor.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
33
import CodeMirror from 'codemirror';
4+
import emmet from '@emmetio/codemirror-plugin';
45
import beautifyJS from 'js-beautify';
56
import { withTranslation } from 'react-i18next';
67
import 'codemirror/mode/css/css';
@@ -54,6 +55,7 @@ import * as ToastActions from '../actions/toast';
5455
import * as ConsoleActions from '../actions/console';
5556

5657
search(CodeMirror);
58+
emmet(CodeMirror);
5759

5860
const beautifyCSS = beautifyJS.css;
5961
const beautifyHTML = beautifyJS.html;
@@ -103,6 +105,11 @@ class Editor extends React.Component {
103105
keyMap: 'sublime',
104106
highlightSelectionMatches: true, // highlight current search match
105107
matchBrackets: true,
108+
mode: 'text/html',
109+
emmet: {
110+
preview: true,
111+
markTagPairs: true,
112+
},
106113
lint: {
107114
onUpdateLinting: ((annotations) => {
108115
this.props.hideRuntimeErrorWarning();
@@ -121,6 +128,7 @@ class Editor extends React.Component {
121128

122129
this._cm.setOption('extraKeys', {
123130
Tab: (cm) => {
131+
if (!cm.execCommand('emmetExpandAbbreviation')) return;
124132
// might need to specify and indent more?
125133
const selection = cm.doc.getSelection();
126134
if (selection.length > 0) {
@@ -129,6 +137,8 @@ class Editor extends React.Component {
129137
cm.replaceSelection(' '.repeat(INDENTATION_AMOUNT));
130138
}
131139
},
140+
Enter: 'emmetInsertLineBreak',
141+
Esc: 'emmetResetAbbreviation',
132142
[`${metaKey}-Enter`]: () => null,
133143
[`Shift-${metaKey}-Enter`]: () => null,
134144
[`${metaKey}-F`]: 'findPersistent',
@@ -184,7 +194,7 @@ class Editor extends React.Component {
184194

185195
componentDidUpdate(prevProps) {
186196
if (this.props.file.content !== prevProps.file.content &&
187-
this.props.file.content !== this._cm.getValue()) {
197+
this.props.file.content !== this._cm.getValue()) {
188198
const oldDoc = this._cm.swapDoc(this._docs[this.props.file.id]);
189199
this._docs[prevProps.file.id] = oldDoc;
190200
this._cm.focus();

client/styles/components/_editor.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,7 @@ pre.CodeMirror-line {
395395
.editor__unsaved-changes {
396396
margin-left: #{2 / $base-font-size}rem;
397397
}
398+
399+
.emmet-close-tag,.emmet-open-tag{
400+
text-decoration: underline;
401+
}

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
"@babel/core": "^7.8.4",
141141
"@babel/polyfill": "^7.8.3",
142142
"@babel/register": "^7.8.3",
143+
"@emmetio/codemirror-plugin": "^1.2.1",
143144
"archiver": "^1.1.0",
144145
"async": "^2.6.3",
145146
"axios": "^0.18.1",

0 commit comments

Comments
 (0)