-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
executable file
·100 lines (71 loc) · 2.74 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window, CodeMirror, document */
define(function (require, exports, module) {
"use strict";
require('jquery-ui-1.9.2.custom.min');
require('runmode');
var CommandManager = brackets.getModule("command/CommandManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
Editor = brackets.getModule("editor/Editor").Editor,
DocumentManager = brackets.getModule("document/DocumentManager"),
EditorUtils = brackets.getModule("editor/EditorUtils"),
Menus = brackets.getModule("command/Menus"),
COMMAND_ID = "me.drewh.brackets.minimap";
var loadCSSPromise = ExtensionUtils.loadStyleSheet(module, 'main.css');
function _drawMap() {
$('.main-view').append('<div id="mini-map"><div class="selection"></div><pre class="cm-s-default" id="mini-map-code"></pre></div>');
}
function lineToPx(line) {
return line * 4;
}
function pxToLine(px) {
return px / 8.4;
}
/* function _documentChange() {
var editor = EditorManager.getCurrentFullEditor();
$(editor).on('scroll', function(e){
var height = $(editor.getScrollerElement()).height();
var totalHeight = editor.totalHeight(true);
var miniSelectionEl = $('#mini-map .selection')[0];
miniSelectionEl.style.top = (e.delegateTarget.scrollTop/(totalHeight-height))*height+e.delegateTarget.scrollTop+"px";
});
_documentUpdate();
}*/
function _updateMiniMap(editor) {
var doc = editor.document;
var text = doc.getText();
var fileType = editor.getModeForDocument();
if (fileType === 'htmlmixed') {
fileType = 'html';
}
CodeMirror.runMode(text, "text/" + fileType, document.getElementById("mini-map-code"));
}
function _documentChange() {
var miniSelectionEl = $('#mini-map .selection');
var editor = EditorManager.getCurrentFullEditor();
var doc = editor.document;
var height = $(editor.getScrollerElement()).height();
var width = $(editor.getScrollerElement()).width();
var lineCount = editor.lineCount();
var totalHeight = editor.totalHeight(true);
var ratio = (height - 200) / totalHeight;
// $("#mini-map").css('-webkit-transform', 'scale('+ratio+','+ratio+')');
if (doc) {
_updateMiniMap(editor);
miniSelectionEl.css({
height: pxToLine(height) + 'px'
});
/* miniSelectionEl.css({
height: height + 'px',
width: width + 'px'
}); */
}
}
loadCSSPromise.then(function () {
_drawMap();
_documentChange();
$(DocumentManager).on('currentDocumentChange', _documentChange);
$(DocumentManager).on('documentSaved', _documentChange);
});
});