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' ;
@@ -56,13 +57,14 @@ import * as UserActions from '../../User/actions';
5657import * as ToastActions from '../actions/toast' ;
5758import * as ConsoleActions from '../actions/console' ;
5859
60+ emmet ( CodeMirror ) ;
61+
5962const beautifyCSS = beautifyJS . css ;
6063const beautifyHTML = beautifyJS . html ;
6164
6265window . JSHINT = JSHINT ;
6366window . CSSLint = CSSLint ;
6467window . HTMLHint = HTMLHint ;
65- delete CodeMirror . keyMap . sublime [ 'Shift-Tab' ] ;
6668
6769const IS_TAB_INDENT = false ;
6870const INDENTATION_AMOUNT = 2 ;
@@ -107,6 +109,11 @@ class Editor extends React.Component {
107109 keyMap : 'sublime' ,
108110 highlightSelectionMatches : true , // highlight current search match
109111 matchBrackets : true ,
112+ emmet : {
113+ preview : [ 'html' ] ,
114+ markTagPairs : true ,
115+ autoRenameTags : true
116+ } ,
110117 autoCloseBrackets : this . props . autocloseBracketsQuotes ,
111118 styleSelectedText : true ,
112119 lint : {
@@ -129,6 +136,7 @@ class Editor extends React.Component {
129136 metaKey === 'Ctrl' ? `${ metaKey } -H` : `${ metaKey } -Option-F` ;
130137 this . _cm . setOption ( 'extraKeys' , {
131138 Tab : ( cm ) => {
139+ if ( ! cm . execCommand ( 'emmetExpandAbbreviation' ) ) return ;
132140 // might need to specify and indent more?
133141 const selection = cm . doc . getSelection ( ) ;
134142 if ( selection . length > 0 ) {
@@ -137,6 +145,8 @@ class Editor extends React.Component {
137145 cm . replaceSelection ( ' ' . repeat ( INDENTATION_AMOUNT ) ) ;
138146 }
139147 } ,
148+ Enter : 'emmetInsertLineBreak' ,
149+ Esc : 'emmetResetAbbreviation' ,
140150 [ `${ metaKey } -Enter` ] : ( ) => null ,
141151 [ `Shift-${ metaKey } -Enter` ] : ( ) => null ,
142152 [ `${ metaKey } -F` ] : 'findPersistent' ,
@@ -168,8 +178,14 @@ class Editor extends React.Component {
168178 } ) ;
169179
170180 this . _cm . on ( 'keydown' , ( _cm , e ) => {
171- // 9 === Tab
172- if ( e . keyCode === 9 && e . shiftKey ) {
181+ // 70 === f
182+ if (
183+ ( ( metaKey === 'Cmd' && e . metaKey ) ||
184+ ( metaKey === 'Ctrl' && e . ctrlKey ) ) &&
185+ e . shiftKey &&
186+ e . keyCode === 70
187+ ) {
188+ e . preventDefault ( ) ;
173189 this . tidyCode ( ) ;
174190 }
175191 } ) ;
@@ -284,7 +300,7 @@ class Editor extends React.Component {
284300 mode = 'javascript' ;
285301 } else if ( fileName . match ( / .+ \. c s s $ / i) ) {
286302 mode = 'css' ;
287- } else if ( fileName . match ( / .+ \. h t m l $ / i) ) {
303+ } else if ( fileName . match ( / .+ \. ( h t m l | x m l ) $ / i) ) {
288304 mode = 'htmlmixed' ;
289305 } else if ( fileName . match ( / .+ \. j s o n $ / i) ) {
290306 mode = 'application/json' ;
0 commit comments