Skip to content

Commit d1a93fc

Browse files
mkslancnightwing
andauthored
Gutter Hover tooltip (#5872)
* WIP: gutter hover tooltip based on hover tooltip * Refactor gutter tooltip to reuse hover tooltip functionality and align position logic. * Adjust gutter tooltip offsets and ensure absolute positioning. * refactor gutter tooltip handling: unify hide method, remove unused code, and improve positioning logic. * remove tooltipFollowsMouse option in default gutter handler (for now) * remove `tooltipFollowsMouse` option and refactor gutter tooltip logic to improve handling and positioning. * fix tests * refactor gutter tooltip constructor and positioning logic for improved alignment and consistency. * fix tooltip positioning logic * refactor gutter tooltip positioning logic to enhance alignment, reuse anchor metrics, and improve code clarity. * fix more tests * refactor gutter tooltip: improve type definitions, remove unused constants, replace `const` with `var` for consistency, and adjust destroy logic. * refactor tooltip logic: improve $setPosition method, update handling of markers, and enhance code readability. * refactor tooltip references: rename `tooltip` to `$tooltip`, update type definitions, and adjust related logic for consistency and clarity. * cleanup * Use position fixed to prevent tooltip being cropped to parent node reverts #5853 --------- Co-authored-by: nightwing <[email protected]>
1 parent 0e72f76 commit d1a93fc

File tree

16 files changed

+390
-352
lines changed

16 files changed

+390
-352
lines changed

ace-internal.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ export namespace Ace {
380380
dragDelay: number;
381381
dragEnabled: boolean;
382382
focusTimeout: number;
383-
tooltipFollowsMouse: boolean;
384383
}
385384

386385
interface EditorOptions extends EditSessionOptions,
@@ -1629,7 +1628,6 @@ declare module "./src/mouse/mouse_event" {
16291628
declare module "./src/mouse/mouse_handler" {
16301629

16311630
export interface MouseHandler {
1632-
$tooltipFollowsMouse?: boolean,
16331631
cancelDrag?: boolean
16341632
//from DefaultHandlers
16351633
$clickSelection?: Ace.Range,
@@ -1638,6 +1636,7 @@ declare module "./src/mouse/mouse_handler" {
16381636
select?: () => void
16391637
$lastScroll?: { t: number, vx: number, vy: number, allowed: number }
16401638
selectEnd?: () => void
1639+
$tooltip?: Ace.GutterTooltip
16411640
}
16421641
}
16431642

ace.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ declare module "ace-code" {
281281
dragDelay: number;
282282
dragEnabled: boolean;
283283
focusTimeout: number;
284-
tooltipFollowsMouse: boolean;
285284
}
286285
interface EditorOptions extends EditSessionOptions, MouseHandlerOptions, VirtualRendererOptions {
287286
selectionStyle: "fullLine" | "screenLine" | "text" | "line";

src/autocomplete/popup.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,27 +370,24 @@ class AcePopup {
370370
renderer.$maxPixelHeight = null;
371371
}
372372

373-
el.style.display = "";
374-
var rootRect = el.offsetParent && el.offsetParent.getBoundingClientRect();
375-
376373

377374
if (anchor === "top") {
378375
el.style.top = "";
379-
el.style.bottom = (screenHeight + scrollBarSize - dims.bottom)
380-
- (rootRect ? screenHeight + scrollBarSize - rootRect.bottom : 0)+ "px";
376+
el.style.bottom = (screenHeight + scrollBarSize - dims.bottom) + "px";
381377
popup.isTopdown = false;
382378
} else {
383-
el.style.top = (dims.top - (rootRect ? rootRect.top : 0)) + "px";
379+
el.style.top = dims.top + "px";
384380
el.style.bottom = "";
385381
popup.isTopdown = true;
386382
}
387383

384+
el.style.display = "";
388385

389386
var left = pos.left;
390387
if (left + el.offsetWidth > screenWidth)
391388
left = screenWidth - el.offsetWidth;
392389

393-
el.style.left = (left - (rootRect ? rootRect.left : 0)) + "px";
390+
el.style.left = left + "px";
394391
el.style.right = "";
395392

396393
if (!popup.isOpen) {
@@ -401,6 +398,8 @@ class AcePopup {
401398

402399
popup.anchorPos = pos;
403400
popup.anchor = anchor;
401+
402+
dom.$fixPositionBug(el);
404403

405404
return true;
406405
};
@@ -472,7 +471,7 @@ dom.importCssString(`
472471
width: 300px;
473472
z-index: 200000;
474473
border: 1px lightgray solid;
475-
position: absolute;
474+
position: fixed;
476475
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
477476
line-height: 1.4;
478477
background: #fefefe;

src/css/editor-css.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ module.exports = `
460460
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
461461
color: black;
462462
padding: 3px 4px;
463-
position: absolute;
463+
position: fixed;
464464
z-index: 999999;
465465
box-sizing: border-box;
466466
cursor: default;

src/editor.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3121,7 +3121,6 @@ config.defineOptions(Editor.prototype, "editor", {
31213121
dragDelay: "$mouseHandler",
31223122
dragEnabled: "$mouseHandler",
31233123
focusTimeout: "$mouseHandler",
3124-
tooltipFollowsMouse: "$mouseHandler",
31253124

31263125
firstLineNumber: "session",
31273126
overwrite: "session",

src/ext/options.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,6 @@ var optionGroups = {
231231
},
232232
"Keyboard Accessibility Mode": {
233233
path: "enableKeyboardAccessibility"
234-
},
235-
"Gutter tooltip follows mouse": {
236-
path: "tooltipFollowsMouse",
237-
defaultValue: true
238234
}
239235
}
240236
};

src/keyboard/gutter_handler.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

33
var keys = require('../lib/keys');
4-
var GutterTooltip = require("../mouse/default_gutter_handler").GutterTooltip;
54

65
class GutterKeyboardHandler {
76
constructor(editor) {
@@ -13,7 +12,7 @@ class GutterKeyboardHandler {
1312
this.activeRowIndex = null;
1413
this.activeLane = null;
1514

16-
this.annotationTooltip = new GutterTooltip(this.editor);
15+
this.annotationTooltip = this.editor.$mouseHandler.$tooltip;
1716
}
1817

1918
addListener() {
@@ -34,7 +33,7 @@ class GutterKeyboardHandler {
3433
e.preventDefault();
3534

3635
if (e.keyCode === keys["escape"])
37-
this.annotationTooltip.hideTooltip();
36+
this.annotationTooltip.hide();
3837

3938
return;
4039
}
@@ -186,12 +185,8 @@ class GutterKeyboardHandler {
186185
return;
187186

188187
case "annotation":
189-
var gutterElement = this.lines.cells[this.activeRowIndex].element.childNodes[2];
190-
var rect = gutterElement.getBoundingClientRect();
191-
var style = this.annotationTooltip.getElement().style;
192-
style.left = rect.right + "px";
193-
style.top = rect.bottom + "px";
194-
this.annotationTooltip.showTooltip(this.$rowIndexToRow(this.activeRowIndex));
188+
this.annotationTooltip.showTooltip(this.$rowIndexToRow(this.activeRowIndex));
189+
this.annotationTooltip.$fromKeyboard = true;
195190
break;
196191
}
197192
return;
@@ -213,7 +208,7 @@ class GutterKeyboardHandler {
213208
}
214209

215210
if (this.annotationTooltip.isOpen)
216-
this.annotationTooltip.hideTooltip();
211+
this.annotationTooltip.hide();
217212

218213
return;
219214
}

0 commit comments

Comments
 (0)