forked from iann0036/cloud9-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderManager.js
108 lines (108 loc) · 5.23 KB
/
renderManager.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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var vscode = require("vscode");
var Color = /** @class */ (function () {
function Color(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
}
return Color;
}());
var RenderManager = /** @class */ (function () {
function RenderManager(clientId, name, userManager, color) {
this.clientId = clientId;
this.name = name;
this.userManager = userManager;
this.color = color;
this.rangedecorator = vscode.window.createTextEditorDecorationType({
backgroundColor: 'rgba(' + this.color.r.toString() + ',' + this.color.g.toString() + ',' + this.color.b.toString() + ',0.3)',
borderRadius: '0.1rem',
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed
});
this.cursordecorator = vscode.window.createTextEditorDecorationType({
before: {
color: 'rgba(' + this.color.r.toString() + ',' + this.color.g.toString() + ',' + this.color.b.toString() + ',1)',
contentText: '|',
margin: '0px 0px 0px -0.42ch',
textDecoration: 'none; position: absolute; display: inline-block; top: 0; font-size: 135%; font-weight: bold; z-index: 1;'
},
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed
});
// TODO: Fix missing cap when at end of file
this.cursortopdecorator = vscode.window.createTextEditorDecorationType({
before: {
color: 'rgba(' + this.color.r.toString() + ',' + this.color.g.toString() + ',' + this.color.b.toString() + ',1)',
contentText: '▀',
margin: '-0.8ch 0px 0px -0.42ch',
textDecoration: 'none; position: absolute; display: inline-block; top: 0; font-size: 80%; font-weight: bold; z-index: 1;'
},
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed
});
this.clientdecorator = null;
}
RenderManager.prototype.getClientDecorator = function () {
if (this.clientdecorator == null) {
this.clientdecorator = vscode.window.createTextEditorDecorationType({
backgroundColor: 'rgba(' + this.color.r.toString() + ',' + this.color.g.toString() + ',' + this.color.b.toString() + ',1)',
textDecoration: 'none; position: relative; z-index: 1;',
after: {
backgroundColor: 'rgba(' + this.color.r.toString() + ',' + this.color.g.toString() + ',' + this.color.b.toString() + ',1)',
contentText: this.name,
textDecoration: 'none; position: absolute; display: inline-block; top: 1rem; font-size: 0.7rem; font-weight: bold; z-index: 1; border-radius: 0.15rem; padding: 0px 0.5ch; pointer-events: none; color: white;'
},
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed
});
}
clearTimeout(this.clientdecoratortimeout);
this.clientdecoratortimeout = setTimeout(function (renderManager) {
renderManager.clientdecorator.dispose();
renderManager.clientdecorator = null;
}, 2000, this);
return this.clientdecorator;
};
RenderManager.prototype.getLatestPosition = function () {
var _this = this;
this.position = this.userManager.getPosition(this.clientId);
if (this.position) {
vscode.window.visibleTextEditors.forEach(function (editor) {
if (editor.document.uri.toString() == _this.position.documentUri) {
_this.editor = editor;
}
});
}
return this.position;
};
RenderManager.prototype.refresh = function () {
if (!this.getLatestPosition())
return;
this.editor.setDecorations(this.rangedecorator, [{
hoverMessage: new vscode.MarkdownString(this.name),
range: this.position.range
}]);
this.editor.setDecorations(this.cursordecorator, [{
range: (this.position.isReversed ?
new vscode.Range(this.position.range.start, this.position.range.start) :
new vscode.Range(this.position.range.end, this.position.range.end))
}]);
this.editor.setDecorations(this.cursortopdecorator, [{
range: (this.position.isReversed ?
new vscode.Range(this.position.range.start, this.position.range.start) :
new vscode.Range(this.position.range.end, this.position.range.end))
}]);
this.editor.setDecorations(this.getClientDecorator(), [{
range: (this.position.isReversed ?
new vscode.Range(this.position.range.start, this.position.range.start) :
new vscode.Range(this.position.range.end, this.position.range.end))
}]);
};
RenderManager.prototype.destroy = function () {
clearTimeout(this.clientdecoratortimeout);
this.rangedecorator.dispose();
this.cursordecorator.dispose();
this.cursortopdecorator.dispose();
this.clientdecorator.dispose();
};
return RenderManager;
}());
exports.RenderManager = RenderManager;