Skip to content

Commit b51ba27

Browse files
authored
Merge pull request #1761 from processing/chore/emmet-integration
Chore/emmet integration
2 parents 0e917dd + eb565aa commit b51ba27

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

client/modules/IDE/components/Editor.jsx

+11
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';
@@ -56,6 +57,8 @@ import * as UserActions from '../../User/actions';
5657
import * as ToastActions from '../actions/toast';
5758
import * as ConsoleActions from '../actions/console';
5859

60+
emmet(CodeMirror);
61+
5962
const beautifyCSS = beautifyJS.css;
6063
const beautifyHTML = beautifyJS.html;
6164

@@ -106,6 +109,11 @@ class Editor extends React.Component {
106109
keyMap: 'sublime',
107110
highlightSelectionMatches: true, // highlight current search match
108111
matchBrackets: true,
112+
emmet: {
113+
preview: ['html'],
114+
markTagPairs: true,
115+
autoRenameTags: true
116+
},
109117
autoCloseBrackets: this.props.autocloseBracketsQuotes,
110118
styleSelectedText: true,
111119
lint: {
@@ -128,6 +136,7 @@ class Editor extends React.Component {
128136
metaKey === 'Ctrl' ? `${metaKey}-H` : `${metaKey}-Option-F`;
129137
this._cm.setOption('extraKeys', {
130138
Tab: (cm) => {
139+
if (!cm.execCommand('emmetExpandAbbreviation')) return;
131140
// might need to specify and indent more?
132141
const selection = cm.doc.getSelection();
133142
if (selection.length > 0) {
@@ -136,6 +145,8 @@ class Editor extends React.Component {
136145
cm.replaceSelection(' '.repeat(INDENTATION_AMOUNT));
137146
}
138147
},
148+
Enter: 'emmetInsertLineBreak',
149+
Esc: 'emmetResetAbbreviation',
139150
[`${metaKey}-Enter`]: () => null,
140151
[`Shift-${metaKey}-Enter`]: () => null,
141152
[`${metaKey}-F`]: 'findPersistent',

client/styles/components/_editor.scss

+39
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,42 @@ pre.CodeMirror-line {
422422
.editor__unsaved-changes {
423423
margin-left: #{2 / $base-font-size}rem;
424424
}
425+
426+
/** Inline abbreviation preview */
427+
428+
.emmet-abbreviation-preview {
429+
@extend %modal;
430+
position: absolute;
431+
@include themify() {
432+
background: getThemifyVariable('background-color');
433+
}
434+
& .CodeMirror-lines {
435+
padding: 0;
436+
}
437+
& .CodeMirror {
438+
height: auto;
439+
max-width: #{400 / $base-font-size}rem;
440+
max-height: #{300 / $base-font-size}rem;
441+
border: none;
442+
}
443+
}
444+
445+
.emmet-abbreviation-preview:not(.has-error) .emmet-abbreviation-preview-error {
446+
display: none;
447+
}
448+
449+
.emmet-abbreviation-preview.has-error .CodeMirror {
450+
display: none;
451+
}
452+
453+
.emmet-abbreviation-preview .CodeMirror-cursors {
454+
visibility: hidden !important;
455+
}
456+
457+
.emmet-abbreviation-preview .emmet-error-snippet-message {
458+
padding: 5px;
459+
}
460+
461+
.emmet-open-tag, .emmet-close-tag {
462+
text-decoration: underline;
463+
}

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
"@babel/core": "^7.8.4",
143143
"@babel/polyfill": "^7.8.3",
144144
"@babel/register": "^7.8.3",
145+
"@emmetio/codemirror-plugin": "^1.2.1",
145146
"archiver": "^1.1.0",
146147
"async": "^2.6.3",
147148
"axios": "^0.21.1",

0 commit comments

Comments
 (0)