Skip to content

Commit 8cf9dc2

Browse files
Merge pull request #37 from atom-ide-community/fix/leftovers
fix: improve handling of unmounting data tips on screen
2 parents 99bfc30 + c4f4441 commit 8cf9dc2

1 file changed

Lines changed: 12 additions & 22 deletions

File tree

lib/datatip-manager.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,32 @@ module.exports = class DatatipManager {
4646
* @type {Boolean}
4747
*/
4848
this.showDataTipOnCursorMove = false;
49-
5049
/**
5150
* [showDataTipOnMouseMove description]
5251
* @type {Boolean}
5352
*/
5453
this.showDataTipOnMouseMove = false;
55-
5654
/**
5755
* [currentMarkerRange description]
5856
* @type {Range}
5957
*/
6058
this.currentMarkerRange = null;
61-
6259
/**
6360
* [onMouseMoveEvt description]
6461
*/
6562
this.onMouseMoveEvt = this.onMouseMoveEvt.bind(this);
66-
6763
/**
6864
* [onCursorMoveEvt description]
6965
*/
7066
this.onCursorMoveEvt = this.onCursorMoveEvt.bind(this);
71-
7267
/**
7368
* [mouseMoveTimer description]
7469
*/
7570
this.mouseMoveTimer = null;
76-
7771
/**
7872
* [cursorMoveTimer description]
7973
*/
8074
this.cursorMoveTimer = null;
81-
8275
/**
8376
* [renderer description]
8477
* @type {[type]}
@@ -96,10 +89,7 @@ module.exports = class DatatipManager {
9689
atom.workspace.observeTextEditors(editor => {
9790
const disposable = this.watchEditor(editor);
9891
editor.onDidDestroy(() => disposable.dispose());
99-
})
100-
);
101-
102-
this.subscriptions.add(
92+
}),
10393
atom.commands.add('atom-text-editor', {
10494
'datatip:toggle': (evt) => {
10595
const editor = evt.currentTarget.getModel();
@@ -168,7 +158,7 @@ module.exports = class DatatipManager {
168158
}
169159
let focusListener = () => this.updateCurrentEditor(editor);
170160
editorView.addEventListener('focus', focusListener);
171-
let blurListener = () => this.hideDataTip();
161+
let blurListener = () => this.unmountDataTip();
172162
editorView.addEventListener('blur', blurListener);
173163

174164
let disposable = new Disposable(() => {
@@ -203,7 +193,7 @@ module.exports = class DatatipManager {
203193
this.editorSubscriptions = null;
204194

205195
// Stop tracking editor + buffer; close any left-overs
206-
this.hideDataTip();
196+
this.unmountDataTip();
207197
this.editor = null;
208198
this.editorView = null;
209199

@@ -222,7 +212,7 @@ module.exports = class DatatipManager {
222212
this.editor.onDidChangeCursorPosition(this.onCursorMoveEvt),
223213
this.editor.getBuffer().onDidChangeText(evt => { // make sure to remove any datatip as long as we are typing
224214
if (evt.changes.length != 1) { return; }
225-
this.hideDataTip();
215+
this.unmountDataTip();
226216
}),
227217
new Disposable(() => { this.editorView.removeEventListener("mousemove", this.onMouseMoveEvt); })
228218
);
@@ -241,7 +231,7 @@ module.exports = class DatatipManager {
241231
(!this.currentMarkerRange.containsPoint(position))) {
242232
this.showDataTip(editor, position, evt);
243233
}
244-
}, 300, evt);
234+
}, 500, evt);
245235
}
246236
/**
247237
* [onMouseMoveEvt description]
@@ -272,15 +262,15 @@ module.exports = class DatatipManager {
272262
// show the datatip in such situations and hide any existing datatips (the mouse moved more to
273263
// the right, away from the actual text)
274264
if (distance >= this.editor.getDefaultCharWidth()) {
275-
return this.hideDataTip();
265+
return this.unmountDataTip();
276266
}
277267

278268
const point = this.editor.bufferPositionForScreenPosition(screenPosition);
279269
if ((this.currentMarkerRange === null) ||
280270
(!this.currentMarkerRange.containsPoint(point))) {
281271
this.showDataTip(this.editor, point, evt);
282272
}
283-
}, 300, evt);
273+
}, 500, evt);
284274
}
285275

286276
/**
@@ -294,7 +284,7 @@ module.exports = class DatatipManager {
294284
provider.datatip(editor, position, evt)
295285
.then((result) => {
296286
// clear last data tip
297-
this.hideDataTip();
287+
this.unmountDataTip();
298288

299289
if (result === null || result === undefined) { return; }
300290

@@ -317,13 +307,13 @@ module.exports = class DatatipManager {
317307
const snippet = m.value.replace(regExpLSPPrefix, '');
318308
return `<pre><code class="${editor.getGrammar().name.toLowerCase()}">${snippet}</code></pre>`;
319309
}).join('\r\n');
310+
320311
const requestToken = `${position.row}:${position.column}`;
321312
this.renderer.render(requestToken, s).then(({ token, html }) => {
322313
if (this.currentMarkerRange.containsPoint(position)) { // make sure we are still on the same position
314+
this.unmountDataTip();
323315
dataTipView = new DataTipView({ htmlView: html });
324316
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, result.range, position, dataTipView);
325-
} else {
326-
this.hideDataTip();
327317
}
328318
}).catch(({ token, error }) => {
329319
console.error(error);
@@ -387,9 +377,9 @@ module.exports = class DatatipManager {
387377
}
388378

389379
/**
390-
* [hideDataTip description]
380+
* [unmountDataTip description]
391381
*/
392-
hideDataTip () {
382+
unmountDataTip () {
393383
this.currentMarkerRange = null;
394384
if (this.dataTipMarkerDisposables) {
395385
this.dataTipMarkerDisposables.dispose();

0 commit comments

Comments
 (0)