83 lines
2.9 KiB
JavaScript
83 lines
2.9 KiB
JavaScript
/*
|
|
* @Author: Zh_Strong
|
|
* @Date: 2023-03-30 10:01:12
|
|
* @LastEditTime: 2023-04-04 15:19:52
|
|
* @LastEditors: Zh_Strong
|
|
* @Description: Zh_Strong
|
|
* @FilePath: \view\lib\ace\src-noconflict\ext-minimap.js
|
|
*/
|
|
ace.define("ace/ext/minimap", ["require", "exports", "module", "ace/editor", "ace/config"], function (require, exports, module) {
|
|
|
|
function minimap(isShow = true) {
|
|
if (!isShow) {
|
|
return false;
|
|
};
|
|
var canvas = document.createElement("canvas");
|
|
canvas.style.position = "absolute";
|
|
canvas.style.right = "0";
|
|
canvas.style.top = "0";
|
|
canvas.style.width = "150px";
|
|
canvas.style.height = "150px";
|
|
canvas.style.border = "1px solid black";
|
|
document.body.appendChild(canvas);
|
|
|
|
var ctx = canvas.getContext("2d");
|
|
// var editorCanvas = editor.renderer.canvas;
|
|
var editorCanvas = document.createElement("canvas");
|
|
var editorCtx = editorCanvas.getContext("2d");
|
|
|
|
function drawMiniMap() {
|
|
var lines = EDITOR.session.getDocument().getAllLines();
|
|
var lineHeight = EDITOR.renderer.lineHeight;
|
|
var content = EDITOR.renderer.content;
|
|
var canvasHeight = canvas.height;
|
|
var canvasWidth = canvas.width;
|
|
var editorHeight = EDITOR.renderer.$size.scrollerHeight;
|
|
var editorWidth = EDITOR.renderer.$size.scrollerWidth;
|
|
var ratio = canvasHeight / editorHeight;
|
|
var y = 0;
|
|
var x = 0;
|
|
var i = 0;
|
|
var len = lines.length;
|
|
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
for (; i < len; i++) {
|
|
var line = lines[i];
|
|
var lineLength = line.length;
|
|
var j = 0;
|
|
for (; j < lineLength; j++) {
|
|
var char = line[j];
|
|
var width = editorCtx.measureText(char).width;
|
|
console.log(char);
|
|
console.log(editorCtx);
|
|
ctx.fillStyle = editorCtx.fillStyle;
|
|
// if (char !== " ") {
|
|
// ctx.fillStyle = "red";
|
|
// } else {
|
|
// ctx.fillStyle = editorCtx.fillStyle;
|
|
// }
|
|
ctx.fillRect(x, y, width * ratio, lineHeight * ratio);
|
|
x += width * ratio;
|
|
}
|
|
y += lineHeight * ratio;
|
|
x = 0;
|
|
}
|
|
}
|
|
|
|
EDITOR.on("change", function () {
|
|
drawMiniMap();
|
|
});
|
|
|
|
drawMiniMap();
|
|
}
|
|
setTimeout(() => {
|
|
minimap();
|
|
}, 10000)
|
|
exports.minimap = minimap;
|
|
});
|
|
(function () {
|
|
ace.require(["ace/ext/minimap"], function (m) {
|
|
if (typeof module == "object" && typeof exports == "object" && module) {
|
|
module.exports = m;
|
|
}
|
|
});
|
|
})(); |