Skip to content

Commit 58fc173

Browse files
author
Andreas Gerlach
committed
feat: don't show overlay if another is already visible at the same range
1 parent cadbca9 commit 58fc173

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

lib/datatip-manager.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,14 @@ module.exports = class DatatipManager {
308308
return `<pre><code class="${editor.getGrammar().name.toLowerCase()}">${snippet}</code></pre>`;
309309
}).join('\r\n');
310310

311-
const requestToken = `${position.row}:${position.column}`;
312-
this.renderer.render(requestToken, s).then(({ token, html }) => {
311+
this.renderer.render(s).then((html) => {
313312
if (this.currentMarkerRange.containsPoint(position)) { // make sure we are still on the same position
314313
this.unmountDataTip();
315314
dataTipView = new DataTipView({ htmlView: html });
316315
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, result.range, position, dataTipView);
317316
}
318-
}).catch(({ token, error }) => {
319-
console.error(error);
317+
}).catch((err) => {
318+
console.error(err);
320319
});
321320
}
322321
});
@@ -349,6 +348,19 @@ module.exports = class DatatipManager {
349348
invalidate: 'never',
350349
});
351350

351+
// if there is an overlay already on the same position, skip showing the data tip
352+
const decorations = editor.getOverlayDecorations({
353+
type: 'overlay'
354+
}).filter((decoration) => {
355+
const decorationMarker = decoration.getMarker();
356+
if (decorationMarker.compare(highlightMarker) == 1) {
357+
return decoration;
358+
}
359+
return null;
360+
});
361+
362+
if (decorations.length > 0) return this.dataTipMarkerDisposables;
363+
352364
const marker = editor.decorateMarker(overlayMarker, {
353365
type: 'overlay',
354366
class: 'datatip-overlay',

lib/provider-registry.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// @ts-check
2-
/// <reference path="../typings/atom-ide.d.ts"/>
3-
/// <reference path="../typings/atom.d.ts" />
41
'use babel';
52

63
const { CompositeDisposable, Disposable } = require('atom');

styles/atom-ide-datatips-marked.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
color: @syntax-text-color;
1010
font-family: var(--editor-font-family);
1111
font-size: var(--editor-font-size);
12-
max-width: 800px;
13-
max-height: 400px;
12+
max-height: 24em;
13+
max-width: 64em;
1414
overflow: auto;
1515
white-space: normal;
1616

styles/atom-ide-datatips.less

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
position: relative;
1111
white-space: normal;
1212
pointer-events: all;
13-
max-width: 800px;
14-
max-height: 400px;
13+
max-height: 24em;
14+
max-width: 64em;
1515
overflow: none;
1616

1717
p {
@@ -23,7 +23,7 @@
2323
}
2424

2525
.datatip-overlay {
26-
z-index: 12 !important; // HACK: exceed the z-index of
26+
z-index: 4 !important; // HACK: exceed the z-index of
2727
// .atom-dock-resize-handle-resizable, so that
2828
// mouseleaves aren't triggered when the cursor enters
2929
// the resizable
@@ -33,8 +33,8 @@
3333
background-color: @syntax-background-color;
3434
display: flex;
3535
position: relative;
36-
max-width: 800px;
37-
max-height: 400px;
36+
max-height: 24em;
37+
max-width: 64em;
3838
transition: background-color 0.15s ease;
3939
padding: 8px;
4040
white-space: pre-wrap;

0 commit comments

Comments
 (0)