11import PropTypes from 'prop-types' ;
22import React from 'react' ;
33import CodeMirror from 'codemirror' ;
4+ import emmet from '@emmetio/codemirror-plugin' ;
45import beautifyJS from 'js-beautify' ;
56import { withTranslation } from 'react-i18next' ;
67import 'codemirror/mode/css/css' ;
@@ -54,6 +55,7 @@ import * as ToastActions from '../actions/toast';
5455import * as ConsoleActions from '../actions/console' ;
5556
5657search ( CodeMirror ) ;
58+ emmet ( CodeMirror ) ;
5759
5860const beautifyCSS = beautifyJS . css ;
5961const 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 ( ) ;
0 commit comments