forked from MiguelCastillo/Brackets-InteractiveLinter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProblemWidget.js
58 lines (43 loc) · 1.77 KB
/
ProblemWidget.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
/**
* Interactive Linter Copyright (c) 2015 Miguel Castillo.
*
* Licensed under MIT
*/
define(function (require, exports, module) {
"use strict";
var _ = brackets.getModule("thirdparty/lodash");
var InlineWidget = brackets.getModule("editor/InlineWidget").InlineWidget;
var widgetTemplate = require("text!templates/inlineWidgetLint.html");
function ProblemWidget(mark, line) {
InlineWidget.call(this);
var problems = [].concat(mark.warnings, mark.errors);
var $html = $(Mustache.render(widgetTemplate, { messages: problems }));
this.$wrapperDiv = $html;
this.$wrapperDiv
.appendTo(this.$htmlContent)
.on("mousedown", function (e) {
e.stopPropagation();
});
this.line = line;
this._sizeEditorToContent = _.debounce(sizeEditorToContent.bind(this), 250);
}
ProblemWidget.prototype = Object.create(InlineWidget.prototype);
ProblemWidget.prototype.constructor = ProblemWidget;
ProblemWidget.prototype.onAdded = function() {
InlineWidget.prototype.onAdded.apply(this, arguments);
// Set height initially, and again whenever width might have changed (word wrap)
this._sizeEditorToContent();
$(window).on("resize", this._sizeEditorToContent);
};
ProblemWidget.prototype.onClosed = function() {
InlineWidget.prototype.onClosed.apply(this, arguments);
$(window).off("resize", this._sizeEditorToContent);
};
ProblemWidget.prototype.refresh = function() {
this._sizeEditorToContent();
};
function sizeEditorToContent () {
this.hostEditor.setInlineWidgetHeight(this, this.$wrapperDiv.height() + 20, true);
}
module.exports = ProblemWidget;
});