Skip to content

Commit 312f618

Browse files
Merge pull request #39 from tonn/feature/hover-blink-fix
fix: remove blinking of tooltip window when mouse hover it
2 parents 04a3519 + 0da78d7 commit 312f618

1 file changed

Lines changed: 48 additions & 35 deletions

File tree

lib/datatip-manager.js

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -278,50 +278,63 @@ module.exports = class DatatipManager {
278278
* @param {TextEditor} editor [description]
279279
* @param {Point} position [description]
280280
*/
281-
showDataTip (editor, position, evt) {
282-
const provider = this.providerRegistry.getProviderForEditor(editor);
283-
if (provider) {
284-
provider.datatip(editor, position, evt)
285-
.then((result) => {
286-
// clear last data tip
287-
this.unmountDataTip();
288-
289-
if (result === null || result === undefined) { return; }
281+
async showDataTip (editor, position, evt) {
282+
try {
283+
const provider = this.providerRegistry.getProviderForEditor(editor);
284+
if (provider) {
285+
const datatip = await provider.datatip(editor, position, evt);
290286

287+
if (datatip) {
291288
// omit update of UI if the range is the same as the current one
292-
if (this.currentMarkerRange != null && result.range.compare(this.currentMarkerRange)) { return; }
289+
if (this.currentMarkerRange != null && datatip.range.intersectsWith(this.currentMarkerRange)) { return; }
290+
// make sure we are still on the same position
291+
if (!datatip.range.containsPoint(position)) { return; }
293292

294-
// store marker range
295-
this.currentMarkerRange = result.range;
293+
// clear last data tip
294+
this.unmountDataTip();
296295

297-
let dataTipView = null;
296+
// store marker range
297+
this.currentMarkerRange = datatip.range;
298298

299-
if (result.component){
300-
dataTipView = new DataTipView({ reactView: result.component });
301-
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, result.range, position, dataTipView);
299+
if (datatip.component){
300+
const dataTipView = new DataTipView({ reactView: datatip.component });
301+
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView);
302302
}
303-
else if (result.markedStrings.length > 0) {
304-
let s = result.markedStrings.map((m) => {
305-
if (m.type === "markdown") return m.value;
306-
const regExpLSPPrefix = /^\((method|property|parameter|alias)\)\W/;
307-
const snippet = m.value.replace(regExpLSPPrefix, '');
308-
return `<pre><code class="${editor.getGrammar().name.toLowerCase()}">${snippet}</code></pre>`;
309-
}).join('\r\n');
310-
311-
this.renderer.render(s).then((html) => {
312-
if (this.currentMarkerRange.containsPoint(position)) { // make sure we are still on the same position
313-
this.unmountDataTip();
314-
dataTipView = new DataTipView({ htmlView: html });
315-
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, result.range, position, dataTipView);
316-
}
317-
}).catch((err) => {
318-
console.error(err);
319-
});
303+
else if (datatip.markedStrings.length > 0) {
304+
let htmlString = this.makeHtmlFromMarkedStrings(datatip.markedStrings, editor.getGrammar().name.toLowerCase());
305+
306+
const html = await this.renderer.render(htmlString);
307+
const dataTipView = new DataTipView({ htmlView: html });
308+
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView);
320309
}
321-
});
310+
}
311+
}
312+
} catch (err) {
313+
console.error(err);
322314
}
323315
}
324316

317+
/**
318+
* [makeHtmlFromMarkedStrings description]
319+
* @param {[type]} markedStrings [description]
320+
* @param {String} grammarName [description]
321+
* @return {String} [description]
322+
*/
323+
makeHtmlFromMarkedStrings(markedStrings, grammarName) {
324+
const regExpLSPPrefix = /^\((method|property|parameter|alias)\)\W/;
325+
326+
return markedStrings
327+
.map(string => {
328+
if (string.type === 'markdown') {
329+
return string.value;
330+
} else if (string.type === 'snippet') {
331+
const snippet = string.value.replace(regExpLSPPrefix, '');
332+
return `<pre><code class="${grammarName}">${snippet}</code></pre>`;
333+
}
334+
})
335+
.join('<br>');
336+
}
337+
325338
/**
326339
* [mountDataTipWithMarker description]
327340
* @param {TextEditor} editor [description]
@@ -378,7 +391,7 @@ module.exports = class DatatipManager {
378391
new Disposable(() => overlayMarker.destroy()),
379392
new Disposable(() => {
380393
this.editorView.addEventListener("mousemove", this.onMouseMoveEvt);
381-
view.destroy()
394+
view.destroy();
382395
}),
383396
new Disposable(() => marker.destroy())
384397
);

0 commit comments

Comments
 (0)