-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
interacting-with-the-editor-listening-to-mouse-events.html
166 lines (145 loc) · 3.98 KB
/
interacting-with-the-editor-listening-to-mouse-events.html
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
<!DOCTYPE html>
<!-- THIS IS A GENERATED FILE VIA gulp generate-test-samples -->
<html>
<head>
<base href="..">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<style>
/*----------------------------------------SAMPLE CSS START*/
.myGlyphMarginClass {
background: red;
}
.myContentClass {
background: lightblue;
}
/*----------------------------------------SAMPLE CSS END*/
</style>
<a class="loading-opts" href="playground.generated/index.html">[<< BACK]</a> <br/>
THIS IS A GENERATED FILE VIA gulp generate-test-samples
<div id="bar" style="margin-bottom: 6px;"></div>
<div style="clear:both"></div>
<div id="outer-container" style="width:800px;height:450px;border: 1px solid grey">
<!-- ----------------------------------------SAMPLE HTML START-->
<div id="output" style="height:29%;font-family:'Courier New', monospace;">Last 3 events:<br/></div>
<div style="background:#ccc;height:1%"></div>
<div id="container" style="height:70%;"></div>
<!-- ----------------------------------------SAMPLE HTML END-->
</div>
<div style="clear:both"></div>
<script src="../metadata.js"></script>
<script src="dev-setup.js"></script>
<script>
loadEditor(function() {
/*----------------------------------------SAMPLE JS START*/
var jsCode = [
'"use strict";',
'function Person(age) {',
' if (age) {',
' this.age = age;',
' }',
'}',
'Person.prototype.getAge = function () {',
' return this.age;',
'};'
].join('\n');
var editor = monaco.editor.create(document.getElementById("container"), {
value: jsCode,
language: "javascript",
glyphMargin: true,
contextmenu: false
});
var decorations = editor.deltaDecorations([], [
{
range: new monaco.Range(3,1,3,1),
options: {
isWholeLine: true,
className: 'myContentClass',
glyphMarginClassName: 'myGlyphMarginClass'
}
}
]);
// Add a zone to make hit testing more interesting
var viewZoneId = null;
editor.changeViewZones(function(changeAccessor) {
var domNode = document.createElement('div');
domNode.style.background = 'lightgreen';
viewZoneId = changeAccessor.addZone({
afterLineNumber: 3,
heightInLines: 3,
domNode: domNode
});
});
// Add a content widget (scrolls inline with text)
var contentWidget = {
domNode: null,
getId: function() {
return 'my.content.widget';
},
getDomNode: function() {
if (!this.domNode) {
this.domNode = document.createElement('div');
this.domNode.innerHTML = 'My content widget';
this.domNode.style.background = 'grey';
}
return this.domNode;
},
getPosition: function() {
return {
position: {
lineNumber: 7,
column: 8
},
preference: [monaco.editor.ContentWidgetPositionPreference.ABOVE, monaco.editor.ContentWidgetPositionPreference.BELOW]
};
}
};
editor.addContentWidget(contentWidget);
// Add an overlay widget
var overlayWidget = {
domNode: null,
getId: function() {
return 'my.overlay.widget';
},
getDomNode: function() {
if (!this.domNode) {
this.domNode = document.createElement('div');
this.domNode.innerHTML = 'My overlay widget';
this.domNode.style.background = 'grey';
this.domNode.style.right = '30px';
this.domNode.style.top = '50px';
}
return this.domNode;
},
getPosition: function() {
return null;
}
};
editor.addOverlayWidget(overlayWidget);
var output = document.getElementById('output');
function showEvent(str) {
while(output.childNodes.length > 6) {
output.removeChild(output.firstChild.nextSibling.nextSibling);
}
output.appendChild(document.createTextNode(str));
output.appendChild(document.createElement('br'));
}
editor.onMouseMove(function (e) {
showEvent('mousemove - ' + e.target.toString());
});
editor.onMouseDown(function (e) {
showEvent('mousedown - ' + e.target.toString());
});
editor.onContextMenu(function (e) {
showEvent('contextmenu - ' + e.target.toString());
});
editor.onMouseLeave(function (e) {
showEvent('mouseleave');
});
/*----------------------------------------SAMPLE JS END*/
});
</script>
</body>
</html>