Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/keymap/extra.js
1293 views
// A number of additional default bindings that are too obscure to1// include in the core codemirror.js file.23(function() {4"use strict";56var Pos = CodeMirror.Pos;78function moveLines(cm, start, end, dist) {9if (!dist || start > end) return 0;1011var from = cm.clipPos(Pos(start, 0)), to = cm.clipPos(Pos(end));12var text = cm.getRange(from, to);1314if (start <= cm.firstLine())15cm.replaceRange("", from, Pos(to.line + 1, 0));16else17cm.replaceRange("", Pos(from.line - 1), to);18var target = from.line + dist;19if (target <= cm.firstLine()) {20cm.replaceRange(text + "\n", Pos(target, 0));21return cm.firstLine() - from.line;22} else {23var targetPos = cm.clipPos(Pos(target - 1));24cm.replaceRange("\n" + text, targetPos);25return targetPos.line + 1 - from.line;26}27}2829function moveSelectedLines(cm, dist) {30var head = cm.getCursor("head"), anchor = cm.getCursor("anchor");31cm.operation(function() {32var moved = moveLines(cm, Math.min(head.line, anchor.line), Math.max(head.line, anchor.line), dist);33cm.setSelection(Pos(anchor.line + moved, anchor.ch), Pos(head.line + moved, head.ch));34});35}3637CodeMirror.commands.moveLinesUp = function(cm) { moveSelectedLines(cm, -1); };38CodeMirror.commands.moveLinesDown = function(cm) { moveSelectedLines(cm, 1); };3940CodeMirror.keyMap["default"]["Alt-Up"] = "moveLinesUp";41CodeMirror.keyMap["default"]["Alt-Down"] = "moveLinesDown";42})();434445