Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/keymap/extra.js
1293 views
1
// A number of additional default bindings that are too obscure to
2
// include in the core codemirror.js file.
3
4
(function() {
5
"use strict";
6
7
var Pos = CodeMirror.Pos;
8
9
function moveLines(cm, start, end, dist) {
10
if (!dist || start > end) return 0;
11
12
var from = cm.clipPos(Pos(start, 0)), to = cm.clipPos(Pos(end));
13
var text = cm.getRange(from, to);
14
15
if (start <= cm.firstLine())
16
cm.replaceRange("", from, Pos(to.line + 1, 0));
17
else
18
cm.replaceRange("", Pos(from.line - 1), to);
19
var target = from.line + dist;
20
if (target <= cm.firstLine()) {
21
cm.replaceRange(text + "\n", Pos(target, 0));
22
return cm.firstLine() - from.line;
23
} else {
24
var targetPos = cm.clipPos(Pos(target - 1));
25
cm.replaceRange("\n" + text, targetPos);
26
return targetPos.line + 1 - from.line;
27
}
28
}
29
30
function moveSelectedLines(cm, dist) {
31
var head = cm.getCursor("head"), anchor = cm.getCursor("anchor");
32
cm.operation(function() {
33
var moved = moveLines(cm, Math.min(head.line, anchor.line), Math.max(head.line, anchor.line), dist);
34
cm.setSelection(Pos(anchor.line + moved, anchor.ch), Pos(head.line + moved, head.ch));
35
});
36
}
37
38
CodeMirror.commands.moveLinesUp = function(cm) { moveSelectedLines(cm, -1); };
39
CodeMirror.commands.moveLinesDown = function(cm) { moveSelectedLines(cm, 1); };
40
41
CodeMirror.keyMap["default"]["Alt-Up"] = "moveLinesUp";
42
CodeMirror.keyMap["default"]["Alt-Down"] = "moveLinesDown";
43
})();
44
45