-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblame_gutter.js
328 lines (282 loc) · 10.4 KB
/
blame_gutter.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/**
* Git Blame extension for the Cloud9 IDE client
*
* @copyright 2011, Ajax.org B.V.
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
*/
define(function(require, exports, module) {
"use strict";
var dom = require("ace/lib/dom");
var event = require("ace/lib/event");
dom.importCssString("\
.ace_resizer_v {\
top: 0px;\
width: 2px;\
z-index: 10;\
height: 100%;\
cursor: w-resize;\
position: absolute;\
border-right: 1px solid black;\
}\
.ace_resizer_v:hover {\
border-right-color: darkblue;\
}\
.ace_closeButton {\
top: -5px;\
left: -3px;\
width: 11px;\
height: 11px;\
cursor: pointer;\
position: absolute;\
border-radius: 11px;\
background: rgba(255, 0, 194, 0.33);\
}\
.ace_closeButton:hover {\
background: rgba(255, 0, 194, 0.5);\
}\
.ace_blame-gutter-layer {\
position: absolute !important;\
text-align: left !important;\
top: 0;\
z-index: 5;\
pointer-events: auto;\
}\
.ace_blame-cell{\
border-top: solid 1px;\
word-wrap: break-word;\
white-space: pre-wrap;\
box-sizing: border-box;\
-moz-box-sizing: border-box;\
overflow: hidden !important;\
padding: 0 8px;\
}\
.ace_blame-cell.selected{\
background: rgba(255, 237, 0, 0.31);\
}\
.ace_tooltip{\
position:fixed;\
background: #F8F7AC;\
border: solid 1px rgba(205, 237, 0, 0.81);\
border-radius:5px;\
z-index: 1000000;\
max-width: 500px;\
white-space: pre-wrap;\
}\
", "blameGutter");
var BlameGutter = function(editor, blameData) {
if (editor.blameGutter)
return;
var gutter = editor.renderer.$gutterLayer;
editor.blameGutter = this;
gutter.blameColumn = this;
this.element = dom.createElement("div");
this.element.className = "ace_layer ace_blame-gutter-layer";
var parentEl = editor.renderer.$gutter;
parentEl.appendChild(this.element);
this.resizer = dom.createElement("div");
this.resizer.className = "ace_resizer_v";
parentEl.appendChild(this.resizer);
this.closeButton = dom.createElement("div");
this.closeButton.className = "ace_closeButton";
this.resizer.appendChild(this.closeButton);
editor.tooltip = dom.createElement("div");
editor.tooltip.className = "ace_tooltip";
editor.tooltip.style.display = "none";
editor.container.appendChild(editor.tooltip);
this.onMousedown = this.onMousedown.bind(this);
this.onChangeSession = this.onChangeSession.bind(this);
this.onMousemove = this.onMousemove.bind(this);
this.onMouseout = this.onMouseout.bind(this);
this.editor = editor;
if (blameData)
this.setData(blameData);
else
this.removeData(blameData);
};
(function(){
this.update = function(config) {
this.$config = config;
var blameEl = this.blameColumn.element;
blameEl.style.marginTop = -config.offset + "px";
var html = [];
var i = config.firstRow;
var lastRow = config.lastRow;
var fold = this.session.getNextFoldLine(i);
var foldStart = fold ? fold.start.row : Infinity;
var foldWidgets = this.$showFoldWidgets && this.session.foldWidgets;
var lineHeight = config.lineHeight;
var blameData = this.blameData;
var selectedText = this.selectedText;
var blameHtml = [];
var $blameIndex, lastBlameCellIndex = 0;
var blameCell;
findBlameCell(i);
if (blameCell)
addBlameCell(blameCell.text, blameCell.title);
else
addBlameCell("", "");
// adjust top margin of first cell to always keep it on screen
if (!blameData[i + 1]) {
blameHtml[$blameIndex] -= config.offset - 1;
blameHtml.splice($blameIndex + 1, 0, "px;margin-top:", config.offset - 1);
}
while (true) {
if(i > foldStart) {
i = fold.end.row + 1;
fold = this.session.getNextFoldLine(i, fold);
if (fold) {
foldStart = fold.start.row;
lastBlameCellIndex = fold.end.row;
} else {
foldStart = Infinity;
}
}
if(i > lastRow)
break;
html.push("<div class='ace_gutter-cell",
"' style='height:", lineHeight, "px;'>", (i+1));
if (foldWidgets) {
var c = foldWidgets[i];
// check if cached value is invalidated and we need to recompute
if (c == null)
c = foldWidgets[i] = this.session.getFoldWidget(i);
if (c)
html.push(
"<span class='ace_fold-widget ace_", c,
c == "start" && i == foldStart && i < fold.end.row ? " ace_closed" : " ace_open",
"' style='height:", lineHeight, "px",
"'></span>"
);
}
var wrappedRowLength = this.session.getRowLength(i) - 1;
while (wrappedRowLength--) {
html.push("</div><div class='ace_gutter-cell' style='height:", lineHeight, "px'>\xA6");
}
html.push("</div>");
i++;
// html for blame column
findBlameCell(i);
if (blameCell)
addBlameCell(blameCell.text, blameCell.title);
else
blameHtml[$blameIndex] += this.session.getRowLength(i-1) * lineHeight;
}
this.element = dom.setInnerHtml(this.element, html.join(""));
this.blameColumn.element = dom.setInnerHtml(blameEl, blameHtml.join(""));
this.element.style.height = config.minHeight + "px";
var gutterWidth = this.element.parentNode.offsetWidth;
if (gutterWidth !== this.gutterWidth) {
this.gutterWidth = gutterWidth;
this._emit("changeGutterWidth", gutterWidth);
}
function addBlameCell(text, title) {
blameHtml.push(
"<div class='ace_blame-cell ", text == selectedText ? "selected" : "",
"' index='", lastBlameCellIndex - 1,"'",
"style='height:", lineHeight, "px'>",
text, " ", title,
"</div>"
);
$blameIndex = blameHtml.length - 6;
}
function findBlameCell(i) {
do {
blameCell = blameData[i];
} while (!blameCell && i-- > lastBlameCellIndex);
lastBlameCellIndex = i + 1;
}
};
this.setData = function(blameData) {
var gutter = this.editor.renderer.$gutterLayer;
gutter.blameData = blameData || [];
gutter.update = this.update;
this.element.style.display = "";
this.closeButton.style.display = "";
this.resizer.style.display = "";
this.editor.on("guttermousedown", this.onMousedown);
this.editor.on("changeSession", this.onChangeSession);
var gutterEl = this.editor.renderer.$gutter;
event.addListener(gutterEl, "mousemove", this.onMousemove);
event.addListener(gutterEl, "mouseout", this.onMouseout);
gutter.element.style.width = "";
this.resizer.style.right = "40px";
this.element.style.width = "260px";
this.element.parentNode.style.width = "300px";
gutter.update(this.editor.renderer.layerConfig);
};
this.removeData = function() {
var gutter = this.editor.renderer.$gutterLayer;
delete gutter.update;
this.editor.removeListener("guttermousedown", this.onMousedown);
this.editor.removeListener("changeSession", this.onChangeSession);
var gutterEl = this.editor.renderer.$gutter;
event.removeListener(gutterEl, "mousemove", this.onMousemove);
event.removeListener(gutterEl, "mouseout", this.onMouseout);
this.element.style.display = "none";
this.closeButton.style.display = "none";
this.resizer.style.display = "none";
this.element.parentNode.style.width = "";
gutter.update(this.editor.renderer.layerConfig);
};
this.onMousedown = function(e) {
var target = e.domEvent.target;
if (target == this.closeButton) {
this.removeData();
return e.stop();
}
if (target == this.resizer) {
var rect = this.editor.blameGutter.element.getBoundingClientRect();
var mouseHandler = this.editor.$mouseHandler;
mouseHandler.resizeBlameGutter = function() {
var gutterWidth = this.x + 40 - rect.left;
this.editor.renderer.$gutter.style.width = gutterWidth + "px";
this.editor.blameGutter.element.style.width = gutterWidth - 40 + "px";
this.editor.renderer.$gutterLayer._emit("changeGutterWidth", gutterWidth);
};
mouseHandler.captureMouse(e, "resizeBlameGutter");
return e.stop();
}
if (dom.hasCssClass(target, "ace_blame-cell")) {
var gutter = this.editor.renderer.$gutterLayer;
var index = parseInt(target.getAttribute("index"));
var blameCell = gutter.blameData[index];
if (!blameCell)
return e.stop();
gutter.selectedText = blameCell.text;
var ch = target.parentNode.children;
for (var i = ch.length; i--; ) {
var isSelected = ch[i].innerHTML.indexOf(gutter.selectedText) == 0;
ch[i].className = "ace_blame-cell" + (isSelected ? " selected" : "");
}
return e.stop();
}
};
this.onChangeSession = function() {
this.removeData();
};
this.onMousemove = function(e) {
var target = e.target;
var container = e.currentTarget;
var tooltip = this.editor.tooltip;
if (this.$highlightedCell != target) {
if (dom.hasCssClass(target, "ace_blame-cell")) {
tooltip.style.display = "block";
this.$highlightedCell = target;
tooltip.textContent = target.textContent;
}
}
if (this.$highlightedCell) {
tooltip.style.top = e.clientY + 10 + "px";
tooltip.style.left = e.clientX + 10 + "px";
} else {
this.onMouseout();
return
}
};
this.onMouseout = function(e) {
this.editor.tooltip.style.display = "none";
this.$highlightedCell = null
};
}).call(BlameGutter.prototype);
exports.BlameGutter = BlameGutter;
});