Skip to content

Emmet integration #1610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion client/modules/IDE/components/Editor.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import CodeMirror from 'codemirror';
import emmet from '@emmetio/codemirror-plugin';
import beautifyJS from 'js-beautify';
import { withTranslation } from 'react-i18next';
import 'codemirror/mode/css/css';
Expand Down Expand Up @@ -54,6 +55,7 @@ import * as ToastActions from '../actions/toast';
import * as ConsoleActions from '../actions/console';

search(CodeMirror);
emmet(CodeMirror);

const beautifyCSS = beautifyJS.css;
const beautifyHTML = beautifyJS.html;
Expand Down Expand Up @@ -103,6 +105,11 @@ class Editor extends React.Component {
keyMap: 'sublime',
highlightSelectionMatches: true, // highlight current search match
matchBrackets: true,
mode: 'text/html',
emmet: {
preview: true,
markTagPairs: true,
},
lint: {
onUpdateLinting: ((annotations) => {
this.props.hideRuntimeErrorWarning();
Expand All @@ -121,6 +128,7 @@ class Editor extends React.Component {

this._cm.setOption('extraKeys', {
Tab: (cm) => {
if (!cm.execCommand('emmetExpandAbbreviation')) return;
// might need to specify and indent more?
const selection = cm.doc.getSelection();
if (selection.length > 0) {
Expand All @@ -129,6 +137,8 @@ class Editor extends React.Component {
cm.replaceSelection(' '.repeat(INDENTATION_AMOUNT));
}
},
Enter: 'emmetInsertLineBreak',
Esc: 'emmetResetAbbreviation',
[`${metaKey}-Enter`]: () => null,
[`Shift-${metaKey}-Enter`]: () => null,
[`${metaKey}-F`]: 'findPersistent',
Expand Down Expand Up @@ -184,7 +194,7 @@ class Editor extends React.Component {

componentDidUpdate(prevProps) {
if (this.props.file.content !== prevProps.file.content &&
this.props.file.content !== this._cm.getValue()) {
this.props.file.content !== this._cm.getValue()) {
const oldDoc = this._cm.swapDoc(this._docs[this.props.file.id]);
this._docs[prevProps.file.id] = oldDoc;
this._cm.focus();
Expand Down
4 changes: 4 additions & 0 deletions client/styles/components/_editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,7 @@ pre.CodeMirror-line {
.editor__unsaved-changes {
margin-left: #{2 / $base-font-size}rem;
}

.emmet-close-tag,.emmet-open-tag{
text-decoration: underline;
}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"@babel/core": "^7.8.4",
"@babel/polyfill": "^7.8.3",
"@babel/register": "^7.8.3",
"@emmetio/codemirror-plugin": "^1.2.1",
"archiver": "^1.1.0",
"async": "^2.6.3",
"axios": "^0.18.1",
Expand Down