WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 47a6321

Browse files
committed
refactor gutter tooltip: improve type definitions, remove unused constants, replace const with var for consistency, and adjust destroy logic.
1 parent 1d6d3b9 commit 47a6321

File tree

4 files changed

+42
-32
lines changed

4 files changed

+42
-32
lines changed

src/mouse/default_gutter_handler.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @typedef {import("./mouse_handler").MouseHandler} MouseHandler
44
*/
55
var dom = require("../lib/dom");
6-
const MouseEvent = require("./mouse_event").MouseEvent;
6+
var MouseEvent = require("./mouse_event").MouseEvent;
77
var HoverTooltip = require("../tooltip").HoverTooltip;
88
var nls = require("../config").nls;
99
var Range = require("../range").Range;
@@ -99,8 +99,10 @@ class GutterTooltip extends HoverTooltip {
9999
super.removeFromEditor(editor);
100100
}
101101

102-
destroy(editor) {
103-
this.removeFromEditor(editor);
102+
destroy() {
103+
if (this.editor) {
104+
this.removeFromEditor(this.editor);
105+
}
104106
super.destroy();
105107
}
106108

@@ -129,6 +131,9 @@ class GutterTooltip extends HoverTooltip {
129131
};
130132
}
131133

134+
/**
135+
* @param {number} row
136+
*/
132137
showTooltip(row) {
133138
var gutter = this.editor.renderer.$gutterLayer;
134139
var annotationsInRow = gutter.$annotations[row];
@@ -149,7 +154,7 @@ class GutterTooltip extends HoverTooltip {
149154
var severityRank = {error: 1, security: 2, warning: 3, info: 4, hint: 5};
150155
var mostSevereAnnotationTypeInFold;
151156

152-
for (let i = row + 1; i <= fold.end.row; i++) {
157+
for (var i = row + 1; i <= fold.end.row; i++) {
153158
if (!gutter.$annotations[i]) continue;
154159

155160
for (var j = 0; j < gutter.$annotations[i].text.length; j++) {
@@ -181,7 +186,7 @@ class GutterTooltip extends HoverTooltip {
181186
var iconClassName = gutter.$useSvgGutterIcons ? "ace_icon_svg" : "ace_icon";
182187

183188
// Construct the contents of the tooltip.
184-
for (let i = 0; i < annotation.displayText.length; i++) {
189+
for (var i = 0; i < annotation.displayText.length; i++) {
185190
var lineElement = dom.createElement("span");
186191

187192
var iconElement = dom.createElement("span");
@@ -212,26 +217,26 @@ class GutterTooltip extends HoverTooltip {
212217

213218
tooltipElement.setAttribute("aria-live", "polite");
214219

215-
const annotationNode = this.$findLinkedAnnotationNode(row);
220+
var annotationNode = this.$findLinkedAnnotationNode(row);
216221
if (annotationNode) {
217222
annotationNode.setAttribute("aria-describedby", this.id);
218223
}
219224

220-
const range = Range.fromPoints({row, column: 0}, {row, column: 0});
225+
var range = Range.fromPoints({row, column: 0}, {row, column: 0});
221226
this.showForRange(this.editor, range, tooltipElement);
222227
this.visibleTooltipRow = row;
223228
this.editor._signal("showGutterTooltip", this);
224229
}
225230

226231
$setPosition(editor, _ignoredPosition, range) {
227-
const gutterCell = this.$findCellByRow(range.start.row);
232+
var gutterCell = this.$findCellByRow(range.start.row);
228233
if (!gutterCell) return;
229-
const el = gutterCell && gutterCell.element;
230-
const anchorEl = el && (el.querySelector(".ace_gutter_annotation"));
234+
var el = gutterCell && gutterCell.element;
235+
var anchorEl = el && (el.querySelector(".ace_gutter_annotation"));
231236
if (!anchorEl) return;
232-
const r = anchorEl.getBoundingClientRect();
237+
var r = anchorEl.getBoundingClientRect();
233238
if (!r) return;
234-
const point = {
239+
var point = {
235240
pageX: r.right,
236241
pageY: r.top
237242
};
@@ -246,9 +251,9 @@ class GutterTooltip extends HoverTooltip {
246251
}
247252

248253
$findLinkedAnnotationNode(row) {
249-
const cell = this.$findCellByRow(row);
254+
var cell = this.$findCellByRow(row);
250255
if (cell) {
251-
const element = cell.element;
256+
var element = cell.element;
252257
if (element.childNodes.length > 2) {
253258
return element.childNodes[2];
254259
}
@@ -266,7 +271,7 @@ class GutterTooltip extends HoverTooltip {
266271
this.$element.removeAttribute("aria-live");
267272

268273
if (this.visibleTooltipRow != undefined) {
269-
const annotationNode = this.$findLinkedAnnotationNode(this.visibleTooltipRow);
274+
var annotationNode = this.$findLinkedAnnotationNode(this.visibleTooltipRow);
270275
if (annotationNode) {
271276
annotationNode.removeAttribute("aria-describedby");
272277
}
@@ -277,11 +282,11 @@ class GutterTooltip extends HoverTooltip {
277282
}
278283

279284
static annotationsToSummaryString(annotations) {
280-
const summary = [];
281-
const annotationTypes = ["error", "security", "warning", "info", "hint"];
282-
for (const annotationType of annotationTypes) {
285+
var summary = [];
286+
var annotationTypes = ["error", "security", "warning", "info", "hint"];
287+
for (var annotationType of annotationTypes) {
283288
if (!annotations[annotationType].length) continue;
284-
const label = annotations[annotationType].length === 1 ? GutterTooltip.annotationLabels[annotationType].singular : GutterTooltip.annotationLabels[annotationType].plural;
289+
var label = annotations[annotationType].length === 1 ? GutterTooltip.annotationLabels[annotationType].singular : GutterTooltip.annotationLabels[annotationType].plural;
285290
summary.push(`${annotations[annotationType].length} ${label}`);
286291
}
287292
return summary.join(", ");

src/mouse/mouse_handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class MouseHandler {
213213
}
214214
destroy() {
215215
if (this.releaseMouse) this.releaseMouse();
216-
if (this.tooltip) this.tooltip.destroy(this.editor);
216+
if (this.tooltip) this.tooltip.destroy();
217217
}
218218
}
219219

src/tooltip.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class PopupManager {
152152
* @param {Tooltip} popup
153153
*/
154154
removePopup(popup) {
155-
const index = this.popups.indexOf(popup);
155+
var index = this.popups.indexOf(popup);
156156
if (index !== -1) {
157157
this.popups.splice(index, 1);
158158
this.updatePopups();
@@ -188,8 +188,8 @@ class PopupManager {
188188
* @return {boolean}
189189
*/
190190
doPopupsOverlap(popupA, popupB) {
191-
const rectA = popupA.getElement().getBoundingClientRect();
192-
const rectB = popupB.getElement().getBoundingClientRect();
191+
var rectA = popupA.getElement().getBoundingClientRect();
192+
var rectB = popupB.getElement().getBoundingClientRect();
193193

194194
return (rectA.left < rectB.right && rectA.right > rectB.left && rectA.top < rectB.bottom && rectA.bottom
195195
> rectB.top);
@@ -236,7 +236,7 @@ class HoverTooltip extends Tooltip {
236236
addToEditor(editor) {
237237
editor.on("mousemove", this.onMouseMove);
238238
editor.on("mousedown", this.hide);
239-
const target = editor.renderer.getMouseEventTarget();
239+
var target = editor.renderer.getMouseEventTarget();
240240
if (target && typeof target.removeEventListener === "function") {
241241
target.addEventListener("mouseout", this.onMouseOut, true);
242242
}
@@ -249,7 +249,7 @@ class HoverTooltip extends Tooltip {
249249
removeFromEditor(editor) {
250250
editor.off("mousemove", this.onMouseMove);
251251
editor.off("mousedown", this.hide);
252-
const target = editor.renderer.getMouseEventTarget();
252+
var target = editor.renderer.getMouseEventTarget();
253253
if (target && typeof target.removeEventListener === "function") {
254254
target.removeEventListener("mouseout", this.onMouseOut, true);
255255
}
@@ -382,8 +382,8 @@ class HoverTooltip extends Tooltip {
382382
var spaceBelow = window.innerHeight - anchorTop - renderer.lineHeight;
383383

384384
// if tooltip fits above the line, or space below the line is smaller, show tooltip above
385-
const metrics = { labelHeight, anchorTop, spaceBelow};
386-
const isAbove = this.$shouldPlaceAbove(metrics);
385+
var metrics = { labelHeight, anchorTop, spaceBelow};
386+
var isAbove = this.$shouldPlaceAbove(metrics);
387387

388388
var rootRect = element.offsetParent && element.offsetParent.getBoundingClientRect();
389389

types/ace-modules.d.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,10 @@ declare module "ace-code/src/tooltip" {
17631763
setPosition(x: number, y: number): void;
17641764
setClassName(className: string): void;
17651765
setTheme(theme: import("ace-code").Ace.Theme): void;
1766+
theme: {
1767+
isDark: boolean;
1768+
cssClass: string;
1769+
};
17661770
show(text?: string, x?: number, y?: number): void;
17671771
hide(e: any): void;
17681772
getHeight(): number;
@@ -1786,8 +1790,6 @@ declare module "ace-code/src/mouse/default_gutter_handler" {
17861790
export interface GutterHandler {
17871791
}
17881792
export type MouseHandler = import("ace-code/src/mouse/mouse_handler").MouseHandler;
1789-
export const GUTTER_TOOLTIP_LEFT_OFFSET: 3;
1790-
export const GUTTER_TOOLTIP_TOP_OFFSET: 3;
17911793
export class GutterTooltip extends HoverTooltip {
17921794
static get annotationLabels(): {
17931795
error: {
@@ -1812,15 +1814,15 @@ declare module "ace-code/src/mouse/default_gutter_handler" {
18121814
};
18131815
};
18141816
static annotationsToSummaryString(annotations: any): string;
1815-
constructor(editor: any);
1817+
constructor(editor: import("ace-code/src/editor").Editor);
18161818
id: string;
1817-
editor: any;
1819+
editor: import("ace-code/src/editor").Editor;
18181820
visibleTooltipRow: number | undefined;
18191821
onDomMouseMove(domEvent: any): void;
18201822
onDomMouseOut(domEvent: any): void;
18211823
addToEditor(editor: any): void;
18221824
removeFromEditor(editor: any): void;
1823-
showTooltip(row: any): void;
1825+
showTooltip(row: number): void;
18241826
/**
18251827
* Check if cursor is outside gutter
18261828
*/
@@ -1874,20 +1876,23 @@ declare module "ace-code/src/mouse/mouse_handler" {
18741876
startSelect?: (pos?: import("ace-code").Ace.Point, waitForClickSelection?: boolean) => void;
18751877
select?: () => void;
18761878
selectEnd?: () => void;
1879+
tooltip?: import("ace-code").Ace.GutterTooltip;
18771880
}
18781881
export type Editor = import("ace-code/src/editor").Editor;
18791882
import { MouseEvent } from "ace-code/src/mouse/mouse_event";
18801883
namespace Ace {
18811884
type Range = import("ace-code").Ace.Range;
18821885
type MouseEvent = import("ace-code").Ace.MouseEvent;
18831886
type Point = import("ace-code").Ace.Point;
1887+
type GutterTooltip = import("ace-code").Ace.GutterTooltip;
18841888
}
18851889
export interface MouseHandler {
18861890
cancelDrag?: boolean;
18871891
mousedownEvent?: Ace.MouseEvent;
18881892
startSelect?: (pos?: Ace.Point, waitForClickSelection?: boolean) => void;
18891893
select?: () => void;
18901894
selectEnd?: () => void;
1895+
tooltip?: Ace.GutterTooltip;
18911896
}
18921897
}
18931898
declare module "ace-code/src/mouse/fold_handler" {

0 commit comments

Comments
 (0)