forked from iann0036/cloud9-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderManager.ts
142 lines (125 loc) · 4.47 KB
/
renderManager.ts
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
import * as vscode from 'vscode';
import * as UserManager from './userManager';
class Color {
constructor(
public readonly r: number,
public readonly g: number,
public readonly b: number
) {}
}
export class RenderManager {
private editor
private position
private rangedecorator
private cursordecorator
private cursortopdecorator
public clientdecorator // needed to be public?
private clientdecoratortimeout
constructor(
public readonly clientId: string,
public readonly name: string,
public readonly userManager: UserManager.UserManager,
public readonly 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;
}
getClientDecorator() {
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;
}
getLatestPosition() {
this.position = this.userManager.getPosition(this.clientId);
if (this.position) {
vscode.window.visibleTextEditors.forEach((editor) => {
if (editor.document.uri.toString() == this.position.documentUri) {
this.editor = editor;
}
});
}
return this.position;
}
refresh() {
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)
)
}]
);
}
destroy() {
clearTimeout(this.clientdecoratortimeout);
this.rangedecorator.dispose();
this.cursordecorator.dispose();
this.cursortopdecorator.dispose();
this.clientdecorator.dispose();
}
}