Skip to content

Commit 80eb5b5

Browse files
committed
fix: refactor overlayFocusFix
1 parent ef0da88 commit 80eb5b5

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lib/datatip-manager.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ export class DataTipManager {
478478

479479
// makes the text selectable with the help of user-select: text
480480
element.setAttribute("tabindex", "-1")
481+
overlayFocusFix(editor, element)
481482

482483
editor.decorateMarker(overlayMarker, {
483484
type: "overlay",
@@ -487,7 +488,6 @@ export class DataTipManager {
487488
})
488489
disposables.add(new Disposable(() => overlayMarker.destroy()))
489490

490-
const editorComponent = atom.views.getView(editor).getComponent()
491491

492492
element.addEventListener("mouseenter", () => {
493493
this.editorView?.removeEventListener("mousemove", this.onMouseMoveEvt)
@@ -499,17 +499,6 @@ export class DataTipManager {
499499
element.removeEventListener("keydown", copyListener)
500500
})
501501

502-
/**
503-
- focus on the datatip once the text is selected (cursor gets disabled temporarily)
504-
- remove focus once mouse leaves
505-
*/
506-
element.addEventListener("mousedown", () => {
507-
blurEditor(editorComponent)
508-
element.addEventListener("mouseleave", () => {
509-
focusEditor(editorComponent)
510-
})
511-
})
512-
513502
// TODO move this code to atom-ide-base
514503
element.addEventListener("wheel", this.onMouseWheel, { passive: true })
515504

@@ -533,6 +522,21 @@ export class DataTipManager {
533522
}
534523
}
535524

525+
function overlayFocusFix(editor: TextEditor, element: HTMLElement) {
526+
const editorComponent = atom.views.getView(editor).getComponent()
527+
/**
528+
- focus on the datatip once the text is selected (cursor gets disabled temporarily)
529+
- remove focus once mouse leaves
530+
*/
531+
element.addEventListener("mousedown", () => {
532+
blurEditor(editorComponent)
533+
element.addEventListener("mouseleave", () => {
534+
focusEditor(editorComponent)
535+
})
536+
})
537+
538+
}
539+
536540
// TODO we should not need this
537541
/** A manual copy listener */
538542
async function copyListener(event: KeyboardEvent) {

0 commit comments

Comments
 (0)