69 lines
2.4 KiB
JavaScript
69 lines
2.4 KiB
JavaScript
/*
|
|
* ISC License
|
|
*
|
|
* Copyright (c) 2024 idnovate.com
|
|
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
|
|
*
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
*
|
|
* @author idnovate
|
|
* @copyright 2024 idnovate
|
|
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
|
|
*/
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.defineOption("scrollPastEnd", false, function(cm, val, old) {
|
|
if (old && old != CodeMirror.Init) {
|
|
cm.off("change", onChange);
|
|
cm.off("refresh", updateBottomMargin);
|
|
cm.display.lineSpace.parentNode.style.paddingBottom = "";
|
|
cm.state.scrollPastEndPadding = null;
|
|
}
|
|
if (val) {
|
|
cm.on("change", onChange);
|
|
cm.on("refresh", updateBottomMargin);
|
|
updateBottomMargin(cm);
|
|
}
|
|
});
|
|
|
|
function onChange(cm, change) {
|
|
if (CodeMirror.changeEnd(change).line == cm.lastLine())
|
|
updateBottomMargin(cm);
|
|
}
|
|
|
|
function updateBottomMargin(cm) {
|
|
var padding = "";
|
|
if (cm.lineCount() > 1) {
|
|
var totalH = cm.display.scroller.clientHeight - 30,
|
|
lastLineH = cm.getLineHandle(cm.lastLine()).height;
|
|
padding = (totalH - lastLineH) + "px";
|
|
}
|
|
if (cm.state.scrollPastEndPadding != padding) {
|
|
cm.state.scrollPastEndPadding = padding;
|
|
cm.display.lineSpace.parentNode.style.paddingBottom = padding;
|
|
cm.off("refresh", updateBottomMargin);
|
|
cm.setSize();
|
|
cm.on("refresh", updateBottomMargin);
|
|
}
|
|
}
|
|
});
|