LaravelTest
48 строк · 1.5 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineOption("scrollPastEnd", false, function(cm, val, old) {15if (old && old != CodeMirror.Init) {16cm.off("change", onChange);17cm.off("refresh", updateBottomMargin);18cm.display.lineSpace.parentNode.style.paddingBottom = "";19cm.state.scrollPastEndPadding = null;20}21if (val) {22cm.on("change", onChange);23cm.on("refresh", updateBottomMargin);24updateBottomMargin(cm);25}26});27
28function onChange(cm, change) {29if (CodeMirror.changeEnd(change).line == cm.lastLine())30updateBottomMargin(cm);31}32
33function updateBottomMargin(cm) {34var padding = "";35if (cm.lineCount() > 1) {36var totalH = cm.display.scroller.clientHeight - 30,37lastLineH = cm.getLineHandle(cm.lastLine()).height;38padding = (totalH - lastLineH) + "px";39}40if (cm.state.scrollPastEndPadding != padding) {41cm.state.scrollPastEndPadding = padding;42cm.display.lineSpace.parentNode.style.paddingBottom = padding;43cm.off("refresh", updateBottomMargin);44cm.setSize();45cm.on("refresh", updateBottomMargin);46}47}48});49