Skip to content

Chore/emmet integration #1761

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

Merged
merged 4 commits into from
Mar 2, 2021
Merged
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
11 changes: 11 additions & 0 deletions 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 @@ -56,6 +57,8 @@ import * as UserActions from '../../User/actions';
import * as ToastActions from '../actions/toast';
import * as ConsoleActions from '../actions/console';

emmet(CodeMirror);

const beautifyCSS = beautifyJS.css;
const beautifyHTML = beautifyJS.html;

Expand Down Expand Up @@ -106,6 +109,11 @@ class Editor extends React.Component {
keyMap: 'sublime',
highlightSelectionMatches: true, // highlight current search match
matchBrackets: true,
emmet: {
preview: ['html'],
markTagPairs: true,
autoRenameTags: true
},
autoCloseBrackets: this.props.autocloseBracketsQuotes,
styleSelectedText: true,
lint: {
Expand All @@ -128,6 +136,7 @@ class Editor extends React.Component {
metaKey === 'Ctrl' ? `${metaKey}-H` : `${metaKey}-Option-F`;
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 @@ -136,6 +145,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
39 changes: 39 additions & 0 deletions client/styles/components/_editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,42 @@ pre.CodeMirror-line {
.editor__unsaved-changes {
margin-left: #{2 / $base-font-size}rem;
}

/** Inline abbreviation preview */

.emmet-abbreviation-preview {
@extend %modal;
position: absolute;
@include themify() {
background: getThemifyVariable('background-color');
}
& .CodeMirror-lines {
padding: 0;
}
& .CodeMirror {
height: auto;
max-width: #{400 / $base-font-size}rem;
max-height: #{300 / $base-font-size}rem;
border: none;
}
}

.emmet-abbreviation-preview:not(.has-error) .emmet-abbreviation-preview-error {
display: none;
}

.emmet-abbreviation-preview.has-error .CodeMirror {
display: none;
}

.emmet-abbreviation-preview .CodeMirror-cursors {
visibility: hidden !important;
}

.emmet-abbreviation-preview .emmet-error-snippet-message {
padding: 5px;
}

.emmet-open-tag, .emmet-close-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 @@ -142,6 +142,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.21.1",
Expand Down