45 lines
1.1 KiB
JavaScript
Raw Normal View History

// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
2017-12-05 11:56:56 +01:00
var CodeMirror = require('codemirror');
CodeMirror.commands.tabAndIndentMarkdownList = function (cm) {
2017-12-05 11:51:36 +01:00
var ranges = cm.listSelections();
var pos = ranges[0].head;
var eolState = cm.getStateAfter(pos.line);
var inList = eolState.list !== false;
2017-12-05 11:51:36 +01:00
if (inList) {
2017-12-05 11:56:56 +01:00
cm.execCommand('indentMore');
2017-12-05 11:51:36 +01:00
return;
}
2017-12-05 11:51:36 +01:00
if (cm.options.indentWithTabs) {
2017-12-05 11:56:56 +01:00
cm.execCommand('insertTab');
2017-12-05 11:51:36 +01:00
}
else {
2017-12-05 11:56:56 +01:00
var spaces = Array(cm.options.tabSize + 1).join(' ');
2017-12-05 11:51:36 +01:00
cm.replaceSelection(spaces);
}
};
CodeMirror.commands.shiftTabAndUnindentMarkdownList = function (cm) {
2017-12-05 11:51:36 +01:00
var ranges = cm.listSelections();
var pos = ranges[0].head;
var eolState = cm.getStateAfter(pos.line);
var inList = eolState.list !== false;
2017-12-05 11:51:36 +01:00
if (inList) {
2017-12-05 11:56:56 +01:00
cm.execCommand('indentLess');
2017-12-05 11:51:36 +01:00
return;
}
2017-12-05 11:51:36 +01:00
if (cm.options.indentWithTabs) {
2017-12-05 11:56:56 +01:00
cm.execCommand('insertTab');
2017-12-05 11:51:36 +01:00
}
else {
2017-12-05 11:56:56 +01:00
var spaces = Array(cm.options.tabSize + 1).join(' ');
2017-12-05 11:51:36 +01:00
cm.replaceSelection(spaces);
}
};