Skip to content

Commit 3183e73

Browse files
fix inserted snippet indent
1 parent a8771dd commit 3183e73

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/Playroom/CodeMirror/snippets.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ const addClass = (el, className) => {
2929
};
3030

3131
const showSnippets = (cm, config = {}, code, height, changeRenderedCode) => {
32+
const cursor = cm.getCursor();
33+
const token = cm.getTokenAt(cursor);
34+
const pad = Array(token.end)
35+
.fill()
36+
.map(() => ' ')
37+
.join('');
3238
const snippets = Object.keys(config).reduce((all, displayText) => {
3339
all.push({
34-
text: formatCode({ code: config[displayText], cursor: cm.getCursor() })
35-
.formattedCode,
36-
displayText
40+
displayText,
41+
text: formatCode({ code: config[displayText], cursor })
42+
.formattedCode.split('\n')
43+
.map(l => `${pad}${l}`)
44+
.join('\n')
3745
});
3846
return all;
3947
}, []);
@@ -67,8 +75,6 @@ const showSnippets = (cm, config = {}, code, height, changeRenderedCode) => {
6775
Esc: resetCode
6876
},
6977
hint: () => {
70-
const cursor = cm.getCursor();
71-
const token = cm.getTokenAt(cursor);
7278
const start =
7379
token.type === 'tag bracket' ? token.start + 1 : token.start;
7480
const end = cursor.ch;

0 commit comments

Comments
 (0)