Skip to content

Commit afdccf8

Browse files
committed
convert to es6 classes
1 parent 469ea5d commit afdccf8

53 files changed

Lines changed: 2969 additions & 3163 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

demo/kitchen-sink/token_tooltip.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@ var event = require("ace/lib/event");
66
var Range = require("ace/range").Range;
77
var Tooltip = require("ace/tooltip").Tooltip;
88

9-
function TokenTooltip (editor) {
10-
if (editor.tokenTooltip)
11-
return;
12-
Tooltip.call(this, editor.container);
13-
editor.tokenTooltip = this;
14-
this.editor = editor;
15-
16-
this.update = this.update.bind(this);
17-
this.onMouseMove = this.onMouseMove.bind(this);
18-
this.onMouseOut = this.onMouseOut.bind(this);
19-
event.addListener(editor.renderer.scroller, "mousemove", this.onMouseMove);
20-
event.addListener(editor.renderer.content, "mouseout", this.onMouseOut);
21-
}
22-
23-
oop.inherits(TokenTooltip, Tooltip);
24-
25-
(function(){
26-
this.token = {};
27-
this.range = new Range();
9+
class TokenTooltip extends Tooltip {
10+
constructor(editor) {
11+
if (editor.tokenTooltip)
12+
return;
13+
super(editor.container);
14+
editor.tokenTooltip = this;
15+
this.editor = editor;
16+
17+
this.update = this.update.bind(this);
18+
this.onMouseMove = this.onMouseMove.bind(this);
19+
this.onMouseOut = this.onMouseOut.bind(this);
20+
event.addListener(editor.renderer.scroller, "mousemove", this.onMouseMove);
21+
event.addListener(editor.renderer.content, "mouseout", this.onMouseOut);
22+
}
23+
token = {};
24+
25+
range = new Range();
2826

29-
this.update = function() {
27+
update() {
3028
this.$timer = null;
3129

3230
var r = this.editor.renderer;
@@ -83,7 +81,7 @@ oop.inherits(TokenTooltip, Tooltip);
8381
this.marker = session.addMarker(this.range, "ace_bracket", "text");
8482
};
8583

86-
this.onMouseMove = function(e) {
84+
onMouseMove(e) {
8785
this.x = e.clientX;
8886
this.y = e.clientY;
8987
if (this.isOpen) {
@@ -94,15 +92,15 @@ oop.inherits(TokenTooltip, Tooltip);
9492
this.$timer = setTimeout(this.update, 100);
9593
};
9694

97-
this.onMouseOut = function(e) {
95+
onMouseOut(e) {
9896
if (e && e.currentTarget.contains(e.relatedTarget))
9997
return;
10098
this.hide();
10199
this.editor.session.removeMarker(this.marker);
102100
this.$timer = clearTimeout(this.$timer);
103101
};
104102

105-
this.setPosition = function(x, y) {
103+
setPosition(x, y) {
106104
if (x + 10 + this.width > this.maxWidth)
107105
x = window.innerWidth - this.width - 10;
108106
if (y > window.innerHeight * 0.75 || y + 20 + this.height > this.maxHeight)
@@ -111,13 +109,13 @@ oop.inherits(TokenTooltip, Tooltip);
111109
Tooltip.prototype.setPosition.call(this, x + 10, y + 20);
112110
};
113111

114-
this.destroy = function() {
112+
destroy() {
115113
this.onMouseOut();
116114
event.removeListener(this.editor.renderer.scroller, "mousemove", this.onMouseMove);
117115
event.removeListener(this.editor.renderer.content, "mouseout", this.onMouseOut);
118116
delete this.editor.tokenTooltip;
119117
};
120118

121-
}).call(TokenTooltip.prototype);
119+
}
122120

123121
exports.TokenTooltip = TokenTooltip;

src/anchor.js

Lines changed: 67 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,31 @@ var oop = require("./lib/oop");
44
var EventEmitter = require("./lib/event_emitter").EventEmitter;
55

66
/**
7-
*
87
* Defines a floating pointer in the document. Whenever text is inserted or deleted before the cursor, the position of the anchor is updated.
9-
*
10-
* @class Anchor
118
**/
12-
13-
/**
14-
* Creates a new `Anchor` and associates it with a document.
15-
*
16-
* @param {Document} doc The document to associate with the anchor
17-
* @param {Number} row The starting row position
18-
* @param {Number} column The starting column position
19-
*
20-
* @constructor
21-
**/
22-
23-
var Anchor = exports.Anchor = function(doc, row, column) {
24-
this.$onChange = this.onChange.bind(this);
25-
this.attach(doc);
9+
class Anchor {
10+
/**
11+
* Creates a new `Anchor` and associates it with a document.
12+
*
13+
* @param {Document} doc The document to associate with the anchor
14+
* @param {Number} row The starting row position
15+
* @param {Number} column The starting column position
16+
**/
17+
constructor(doc, row, column) {
18+
this.$onChange = this.onChange.bind(this);
19+
this.attach(doc);
20+
21+
if (typeof column == "undefined")
22+
this.setPosition(row.row, row.column);
23+
else
24+
this.setPosition(row, column);
25+
};
2626

27-
if (typeof column == "undefined")
28-
this.setPosition(row.row, row.column);
29-
else
30-
this.setPosition(row, column);
31-
};
32-
33-
(function() {
34-
35-
oop.implement(this, EventEmitter);
36-
3727
/**
3828
* Returns an object identifying the `row` and `column` position of the current anchor.
3929
* @returns {Ace.Point}
4030
**/
41-
this.getPosition = function() {
31+
getPosition() {
4232
return this.$clipPositionToDocument(this.row, this.column);
4333
};
4434

@@ -47,14 +37,14 @@ var Anchor = exports.Anchor = function(doc, row, column) {
4737
* Returns the current document.
4838
* @returns {Document}
4939
**/
50-
this.getDocument = function() {
40+
getDocument() {
5141
return this.document;
5242
};
5343

5444
/**
5545
* experimental: allows anchor to stick to the next on the left
5646
*/
57-
this.$insertRight = false;
47+
$insertRight = false;
5848
/**
5949
* Fires whenever the anchor position changes.
6050
*
@@ -72,7 +62,7 @@ var Anchor = exports.Anchor = function(doc, row, column) {
7262
* Internal function called when `"change"` event fired.
7363
* @param {Ace.Delta} delta
7464
*/
75-
this.onChange = function(delta) {
65+
onChange(delta) {
7666
if (delta.start.row == delta.end.row && delta.start.row != this.row)
7767
return;
7868

@@ -82,44 +72,6 @@ var Anchor = exports.Anchor = function(doc, row, column) {
8272
var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
8373
this.setPosition(point.row, point.column, true);
8474
};
85-
86-
function $pointsInOrder(point1, point2, equalPointsInOrder) {
87-
var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
88-
return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
89-
}
90-
91-
function $getTransformedPoint(delta, point, moveIfEqual) {
92-
// Get delta info.
93-
var deltaIsInsert = delta.action == "insert";
94-
var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
95-
var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
96-
var deltaStart = delta.start;
97-
var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
98-
99-
// DELTA AFTER POINT: No change needed.
100-
if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
101-
return {
102-
row: point.row,
103-
column: point.column
104-
};
105-
}
106-
107-
// DELTA BEFORE POINT: Move point by delta shift.
108-
if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
109-
return {
110-
row: point.row + deltaRowShift,
111-
column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
112-
};
113-
}
114-
115-
// DELTA ENVELOPS POINT (delete only): Move point to delta start.
116-
// TODO warn if delta.action != "remove" ?
117-
118-
return {
119-
row: deltaStart.row,
120-
column: deltaStart.column
121-
};
122-
}
12375

12476
/**
12577
* Sets the anchor position to the specified row and column. If `noClip` is `true`, the position is not clipped.
@@ -128,7 +80,7 @@ var Anchor = exports.Anchor = function(doc, row, column) {
12880
* @param {Boolean} noClip Identifies if you want the position to be clipped
12981
*
13082
**/
131-
this.setPosition = function(row, column, noClip) {
83+
setPosition(row, column, noClip) {
13284
var pos;
13385
if (noClip) {
13486
pos = {
@@ -159,7 +111,7 @@ var Anchor = exports.Anchor = function(doc, row, column) {
159111
* When called, the `"change"` event listener is removed.
160112
*
161113
**/
162-
this.detach = function() {
114+
detach() {
163115
this.document.off("change", this.$onChange);
164116
};
165117

@@ -168,7 +120,7 @@ var Anchor = exports.Anchor = function(doc, row, column) {
168120
* @param {Document} doc The document to associate with
169121
*
170122
**/
171-
this.attach = function(doc) {
123+
attach(doc) {
172124
this.document = doc || this.document;
173125
this.document.on("change", this.$onChange);
174126
};
@@ -180,7 +132,7 @@ var Anchor = exports.Anchor = function(doc, row, column) {
180132
* @returns {Ace.Point}
181133
*
182134
**/
183-
this.$clipPositionToDocument = function(row, column) {
135+
$clipPositionToDocument(row, column) {
184136
var pos = {};
185137

186138
if (row >= this.document.getLength()) {
@@ -201,5 +153,46 @@ var Anchor = exports.Anchor = function(doc, row, column) {
201153

202154
return pos;
203155
};
156+
}
157+
158+
oop.implement(Anchor.prototype, EventEmitter);
159+
160+
function $pointsInOrder(point1, point2, equalPointsInOrder) {
161+
var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
162+
return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
163+
}
164+
165+
function $getTransformedPoint(delta, point, moveIfEqual) {
166+
// Get delta info.
167+
var deltaIsInsert = delta.action == "insert";
168+
var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
169+
var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
170+
var deltaStart = delta.start;
171+
var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
172+
173+
// DELTA AFTER POINT: No change needed.
174+
if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
175+
return {
176+
row: point.row,
177+
column: point.column
178+
};
179+
}
180+
181+
// DELTA BEFORE POINT: Move point by delta shift.
182+
if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
183+
return {
184+
row: point.row + deltaRowShift,
185+
column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
186+
};
187+
}
188+
189+
// DELTA ENVELOPS POINT (delete only): Move point to delta start.
190+
// TODO warn if delta.action != "remove" ?
191+
192+
return {
193+
row: deltaStart.row,
194+
column: deltaStart.column
195+
};
196+
}
204197

205-
}).call(Anchor.prototype);
198+
exports.Anchor = Anchor;

0 commit comments

Comments
 (0)