Skip to content

Commit

Permalink
fix: remove focus once mouse leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Feb 2, 2021
1 parent 9e04409 commit 6dffe99
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/datatip-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TextEditorElement,
CommandEvent,
CursorPositionChangedEvent,
TextEditorComponent,
} from "atom"
import type { Datatip, DatatipProvider } from "atom-ide-base"
import { ViewContainer } from "atom-ide-base/commons-ui/float-pane/ViewContainer"
Expand Down Expand Up @@ -486,6 +487,8 @@ export class DataTipManager {
})
disposables.add(new Disposable(() => overlayMarker.destroy()))

const editorComponent = atom.views.getView(editor).getComponent()

element.addEventListener("mouseenter", () => {
this.editorView?.removeEventListener("mousemove", this.onMouseMoveEvt)
element.addEventListener("keydown", copyListener)
Expand All @@ -496,6 +499,17 @@ export class DataTipManager {
element.removeEventListener("keydown", copyListener)
})

/**
- focus on the datatip once the text is selected (cursor gets disabled temporarily)
- remove focus once mouse leaves
*/
element.addEventListener("mousedown", () => {
blurEditor(editorComponent)
element.addEventListener("mouseleave", () => {
focusEditor(editorComponent)
})
})

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

Expand Down Expand Up @@ -529,3 +543,14 @@ function copyListener(event: KeyboardEvent) {
}
}

function focusEditor(editorComponent: TextEditorComponent) {
// @ts-ignore
editorComponent?.didFocus()
}

function blurEditor(editorComponent: TextEditorComponent) {
// @ts-ignore
editorComponent?.didBlurHiddenInput({
relatedTarget: null,
})
}

0 comments on commit 6dffe99

Please sign in to comment.