Skip to content

Commit e56b3a5

Browse files
authored
Merge pull request #131 from atom-community/fix-datatip-not-showing
2 parents d18fbd1 + 9e94596 commit e56b3a5

File tree

8 files changed

+54
-72
lines changed

8 files changed

+54
-72
lines changed

.eslintrc.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
2-
"extends": "eslint-config-atomic/react",
3-
"ignorePatterns": ["dist/", "node_modules/"],
4-
"rules": {
5-
"@typescript-eslint/no-inferrable-types": "off",
6-
"@typescript-eslint/no-non-null-assertion": "off"
7-
}
2+
"extends": "eslint-config-atomic/strict-react",
3+
"ignorePatterns": ["dist/", "node_modules/"]
84
}

lib/datatip-manager.ts

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ export class DataTipManager {
176176

177177
return new Disposable(() => {
178178
disposable.dispose()
179-
if (this.subscriptions != null) {
180-
this.subscriptions.remove(disposable)
181-
}
179+
this.subscriptions.remove(disposable)
182180
this.watchedEditors.delete(editor)
183181
})
184182
}
@@ -202,7 +200,7 @@ export class DataTipManager {
202200
this.editor = null
203201
this.editorView = null
204202

205-
if (editor == null || !atom.workspace.isTextEditor(editor)) {
203+
if (editor === null || !atom.workspace.isTextEditor(editor)) {
206204
return
207205
}
208206

@@ -234,7 +232,7 @@ export class DataTipManager {
234232
* the central cursor movement event handler
235233
* @param evt the cursor move event
236234
*/
237-
onCursorMoveEvt(evt: CursorPositionChangedEvent) {
235+
onCursorMoveEvt(event: CursorPositionChangedEvent) {
238236
if (this.cursorMoveTimer) {
239237
clearTimeout(this.cursorMoveTimer)
240238
}
@@ -251,21 +249,21 @@ export class DataTipManager {
251249
}
252250
},
253251
this.hoverTime,
254-
evt
252+
event
255253
)
256254
}
257255

258256
/**
259257
* the central mouse movement event handler
260258
*/
261-
onMouseMoveEvt(evt: MouseEvent) {
259+
onMouseMoveEvt(event: MouseEvent) {
262260
if (this.mouseMoveTimer) {
263261
clearTimeout(this.mouseMoveTimer)
264262
}
265263

266264
this.mouseMoveTimer = setTimeout(
267265
(evt) => {
268-
if (this.editorView == null || this.editor == null) {
266+
if (this.editorView === null || this.editor === null) {
269267
return
270268
}
271269

@@ -284,6 +282,7 @@ export class DataTipManager {
284282
// means the mouse event occured quite far away from where the text ends on that row. Do not
285283
// show the datatip in such situations and hide any existing datatips (the mouse moved more to
286284
// the right, away from the actual text)
285+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
287286
// @ts-ignore: internal API
288287
if (distance >= this.editor.getDefaultCharWidth()) {
289288
return this.unmountDataTip()
@@ -295,18 +294,10 @@ export class DataTipManager {
295294
}
296295
},
297296
this.hoverTime,
298-
evt
297+
event
299298
)
300299
}
301300

302-
/**
303-
* handles the mouse wheel event to enable scrolling over long text
304-
* @param evt the mouse wheel event being triggered
305-
*/
306-
onMouseWheel(evt: WheelEvent) {
307-
evt.stopPropagation()
308-
}
309-
310301
/**
311302
* the central command event handler
312303
* @param evt command event
@@ -337,6 +328,8 @@ export class DataTipManager {
337328
try {
338329
let datatip: Datatip | null = null
339330
for (const provider of this.providerRegistry.getAllProvidersForEditor(editor)) {
331+
// we only need one and we want to process them synchronously
332+
// eslint-disable-next-line no-await-in-loop
340333
const providerTip = await provider.datatip(editor, position)
341334
if (providerTip) {
342335
datatip = providerTip
@@ -347,7 +340,7 @@ export class DataTipManager {
347340
this.unmountDataTip()
348341
} else {
349342
// omit update of UI if the range is the same as the current one
350-
if (this.currentMarkerRange != null && datatip.range.intersectsWith(this.currentMarkerRange)) {
343+
if (this.currentMarkerRange !== null && datatip.range.intersectsWith(this.currentMarkerRange)) {
351344
return
352345
}
353346
// make sure we are still on the same position
@@ -448,25 +441,22 @@ export class DataTipManager {
448441
})
449442

450443
// OPTIMIZATION:
451-
// if there is an overlay already on the same position, skip showing the datatip
444+
// if there is an highligh overlay already on the same position, skip adding the highlight
452445
const decorations = editor.getOverlayDecorations().filter((decoration) => {
453-
const decorationMarker = decoration.getMarker()
454-
if (decorationMarker.compare(highlightMarker) == 1) {
455-
return decoration
456-
}
457-
return null
446+
return decoration.isType("highligh") && decoration.getMarker().compare(highlightMarker) === 1
458447
})
459448
if (decorations.length > 0) {
460449
highlightMarker.destroy()
461-
return this.dataTipMarkerDisposables
450+
// END OPTIMIZATION
451+
} else {
452+
// Actual Highlighting
453+
disposables.add(new Disposable(() => highlightMarker.destroy()))
454+
455+
editor.decorateMarker(highlightMarker, {
456+
type: "highlight",
457+
class: "datatip-highlight-region",
458+
})
462459
}
463-
// END OPTIMIZATION
464-
465-
disposables.add(new Disposable(() => highlightMarker.destroy()))
466-
editor.decorateMarker(highlightMarker, {
467-
type: "highlight",
468-
class: "datatip-highlight-region",
469-
})
470460

471461
// The actual datatip should appear at the trigger position.
472462
const overlayMarker = editor.markBufferRange(new Range(position, position), {
@@ -502,7 +492,7 @@ export class DataTipManager {
502492
}
503493

504494
// TODO move this code to atom-ide-base
505-
element.addEventListener("wheel", this.onMouseWheel, { passive: true })
495+
element.addEventListener("wheel", onMouseWheel, { passive: true })
506496

507497
return disposables
508498
}
@@ -516,3 +506,11 @@ export class DataTipManager {
516506
this.dataTipMarkerDisposables = null
517507
}
518508
}
509+
510+
/**
511+
* handles the mouse wheel event to enable scrolling over long text
512+
* @param evt the mouse wheel event being triggered
513+
*/
514+
function onMouseWheel(evt: WheelEvent) {
515+
evt.stopPropagation()
516+
}

lib/main.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ let datatipManager: DataTipManager
1616
/**
1717
* called by Atom when activating an extension
1818
*/
19-
export async function activate() {
19+
export function activate() {
2020
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
2121
subscriptions = new CompositeDisposable()
22-
if (!datatipManager) datatipManager = new DataTipManager()
22+
if (!datatipManager) {
23+
datatipManager = new DataTipManager()
24+
}
2325
subscriptions.add(datatipManager)
2426

2527
install_deps().then(() => {
@@ -31,7 +33,6 @@ async function install_deps() {
3133
// install package-deps if not loaded
3234
if (!atom.packages.isPackageLoaded("busy-signal")) {
3335
// Dynamic import https://mariusschulz.com/blog/dynamic-import-expressions-in-typescript
34-
// @ts-ignore
3536
await import("atom-package-deps").then((atom_package_deps) => {
3637
atom_package_deps.install("atom-ide-datatip", true)
3738
})

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
"busy-signal"
3535
],
3636
"dependencies": {
37-
"atom-ide-base": "^2.3.4",
37+
"atom-ide-base": "^2.4.0",
3838
"atom-package-deps": "^7.2.2"
3939
},
4040
"devDependencies": {
4141
"@types/atom": "^1.40.9",
4242
"@types/jasmine": "^3.6.6",
4343
"@types/node": "^14.14.34",
44-
"atom-jasmine3-test-runner": "^5.1.9",
44+
"atom-jasmine3-test-runner": "^5.2.1",
4545
"build-commit": "^0.1.4",
4646
"cross-env": "latest",
4747
"eslint": "7.22.0",

pnpm-lock.yaml

Lines changed: 12 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const RollupConfig = [
1414
],
1515
// loaded externally
1616
external: ["atom"],
17-
plugins: plugins,
17+
plugins,
1818
},
1919
]
2020
export default RollupConfig

spec/main-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("atom-ide-datatip tests", () => {
1414
await atom.packages.activatePackage("atom-ide-datatip")
1515
})
1616

17-
it("Activation", async function () {
17+
it("Activation", function () {
1818
expect(atom.packages.isPackageLoaded("atom-ide-datatip")).toBeTruthy()
1919
})
2020
})

spec/runner.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
"use babel"
2+
// eslint-disable-next-line import/named
23
import { createRunner } from "atom-jasmine3-test-runner"
34

45
// https://github.com/UziTech/atom-jasmine3-test-runner#api
56
export default createRunner({
67
testPackages: ["atom-ide-markdown-service", "busy-signal"],
78
timeReporter: true,
89
specHelper: true,
9-
attachToDOM: true,
10-
// Extra Packages
11-
customMatchers: true,
12-
jasmineFocused: false,
13-
jasmineJson: false,
14-
jasminePass: false,
15-
jasmineShouldFail: false,
16-
jasmineTagged: false,
17-
mockClock: true,
18-
mockLocalStorage: false,
19-
profile: true,
20-
unspy: false,
2110
})

0 commit comments

Comments
 (0)