Skip to content

Commit

Permalink
Merge pull request #131 from atom-community/fix-datatip-not-showing
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Mar 15, 2021
2 parents d18fbd1 + 9e94596 commit e56b3a5
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 72 deletions.
8 changes: 2 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"extends": "eslint-config-atomic/react",
"ignorePatterns": ["dist/", "node_modules/"],
"rules": {
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-non-null-assertion": "off"
}
"extends": "eslint-config-atomic/strict-react",
"ignorePatterns": ["dist/", "node_modules/"]
}
64 changes: 31 additions & 33 deletions lib/datatip-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ export class DataTipManager {

return new Disposable(() => {
disposable.dispose()
if (this.subscriptions != null) {
this.subscriptions.remove(disposable)
}
this.subscriptions.remove(disposable)
this.watchedEditors.delete(editor)
})
}
Expand All @@ -202,7 +200,7 @@ export class DataTipManager {
this.editor = null
this.editorView = null

if (editor == null || !atom.workspace.isTextEditor(editor)) {
if (editor === null || !atom.workspace.isTextEditor(editor)) {
return
}

Expand Down Expand Up @@ -234,7 +232,7 @@ export class DataTipManager {
* the central cursor movement event handler
* @param evt the cursor move event
*/
onCursorMoveEvt(evt: CursorPositionChangedEvent) {
onCursorMoveEvt(event: CursorPositionChangedEvent) {
if (this.cursorMoveTimer) {
clearTimeout(this.cursorMoveTimer)
}
Expand All @@ -251,21 +249,21 @@ export class DataTipManager {
}
},
this.hoverTime,
evt
event
)
}

/**
* the central mouse movement event handler
*/
onMouseMoveEvt(evt: MouseEvent) {
onMouseMoveEvt(event: MouseEvent) {
if (this.mouseMoveTimer) {
clearTimeout(this.mouseMoveTimer)
}

this.mouseMoveTimer = setTimeout(
(evt) => {
if (this.editorView == null || this.editor == null) {
if (this.editorView === null || this.editor === null) {
return
}

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

/**
* handles the mouse wheel event to enable scrolling over long text
* @param evt the mouse wheel event being triggered
*/
onMouseWheel(evt: WheelEvent) {
evt.stopPropagation()
}

/**
* the central command event handler
* @param evt command event
Expand Down Expand Up @@ -337,6 +328,8 @@ export class DataTipManager {
try {
let datatip: Datatip | null = null
for (const provider of this.providerRegistry.getAllProvidersForEditor(editor)) {
// we only need one and we want to process them synchronously
// eslint-disable-next-line no-await-in-loop
const providerTip = await provider.datatip(editor, position)
if (providerTip) {
datatip = providerTip
Expand All @@ -347,7 +340,7 @@ export class DataTipManager {
this.unmountDataTip()
} else {
// omit update of UI if the range is the same as the current one
if (this.currentMarkerRange != null && datatip.range.intersectsWith(this.currentMarkerRange)) {
if (this.currentMarkerRange !== null && datatip.range.intersectsWith(this.currentMarkerRange)) {
return
}
// make sure we are still on the same position
Expand Down Expand Up @@ -448,25 +441,22 @@ export class DataTipManager {
})

// OPTIMIZATION:
// if there is an overlay already on the same position, skip showing the datatip
// if there is an highligh overlay already on the same position, skip adding the highlight
const decorations = editor.getOverlayDecorations().filter((decoration) => {
const decorationMarker = decoration.getMarker()
if (decorationMarker.compare(highlightMarker) == 1) {
return decoration
}
return null
return decoration.isType("highligh") && decoration.getMarker().compare(highlightMarker) === 1
})
if (decorations.length > 0) {
highlightMarker.destroy()
return this.dataTipMarkerDisposables
// END OPTIMIZATION
} else {
// Actual Highlighting
disposables.add(new Disposable(() => highlightMarker.destroy()))

editor.decorateMarker(highlightMarker, {
type: "highlight",
class: "datatip-highlight-region",
})
}
// END OPTIMIZATION

disposables.add(new Disposable(() => highlightMarker.destroy()))
editor.decorateMarker(highlightMarker, {
type: "highlight",
class: "datatip-highlight-region",
})

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

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

return disposables
}
Expand All @@ -516,3 +506,11 @@ export class DataTipManager {
this.dataTipMarkerDisposables = null
}
}

/**
* handles the mouse wheel event to enable scrolling over long text
* @param evt the mouse wheel event being triggered
*/
function onMouseWheel(evt: WheelEvent) {
evt.stopPropagation()
}
7 changes: 4 additions & 3 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ let datatipManager: DataTipManager
/**
* called by Atom when activating an extension
*/
export async function activate() {
export function activate() {
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
subscriptions = new CompositeDisposable()
if (!datatipManager) datatipManager = new DataTipManager()
if (!datatipManager) {
datatipManager = new DataTipManager()
}
subscriptions.add(datatipManager)

install_deps().then(() => {
Expand All @@ -31,7 +33,6 @@ async function install_deps() {
// install package-deps if not loaded
if (!atom.packages.isPackageLoaded("busy-signal")) {
// Dynamic import https://mariusschulz.com/blog/dynamic-import-expressions-in-typescript
// @ts-ignore
await import("atom-package-deps").then((atom_package_deps) => {
atom_package_deps.install("atom-ide-datatip", true)
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
"busy-signal"
],
"dependencies": {
"atom-ide-base": "^2.3.4",
"atom-ide-base": "^2.4.0",
"atom-package-deps": "^7.2.2"
},
"devDependencies": {
"@types/atom": "^1.40.9",
"@types/jasmine": "^3.6.6",
"@types/node": "^14.14.34",
"atom-jasmine3-test-runner": "^5.1.9",
"atom-jasmine3-test-runner": "^5.2.1",
"build-commit": "^0.1.4",
"cross-env": "latest",
"eslint": "7.22.0",
Expand Down
26 changes: 12 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const RollupConfig = [
],
// loaded externally
external: ["atom"],
plugins: plugins,
plugins,
},
]
export default RollupConfig
2 changes: 1 addition & 1 deletion spec/main-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("atom-ide-datatip tests", () => {
await atom.packages.activatePackage("atom-ide-datatip")
})

it("Activation", async function () {
it("Activation", function () {
expect(atom.packages.isPackageLoaded("atom-ide-datatip")).toBeTruthy()
})
})
13 changes: 1 addition & 12 deletions spec/runner.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
"use babel"
// eslint-disable-next-line import/named
import { createRunner } from "atom-jasmine3-test-runner"

// https://github.com/UziTech/atom-jasmine3-test-runner#api
export default createRunner({
testPackages: ["atom-ide-markdown-service", "busy-signal"],
timeReporter: true,
specHelper: true,
attachToDOM: true,
// Extra Packages
customMatchers: true,
jasmineFocused: false,
jasmineJson: false,
jasminePass: false,
jasmineShouldFail: false,
jasmineTagged: false,
mockClock: true,
mockLocalStorage: false,
profile: true,
unspy: false,
})

0 comments on commit e56b3a5

Please sign in to comment.