UNPKG

558 BJavaScriptView Raw
1'use strict';
2
3var getIndent = require('./getIndent');
4
5/**
6 * User pressed Enter in an editor:
7 * Insert a new code line and start it with the indentation from previous line
8 */
9function onEnter(event, data, change, opts) {
10 var state = change.state;
11
12 if (!state.isCollapsed) {
13 return;
14 }
15
16 event.preventDefault();
17
18 var startBlock = state.startBlock;
19
20 var currentLineText = startBlock.text;
21 var indent = getIndent(currentLineText, '');
22
23 return change.splitBlock().insertText(indent).focus();
24}
25
26module.exports = onEnter;
\No newline at end of file