Skip to content

Commit

Permalink
Merge pull request #115 from atom-community/refactor-selectable-overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Feb 2, 2021
2 parents ef0da88 + eba2a13 commit ff10ef7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7,331 deletions.
41 changes: 3 additions & 38 deletions lib/datatip-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ 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"
import { ProviderRegistry } from "atom-ide-base/commons-atom/ProviderRegistry"
import { makeOverlaySelectable, copyListener } from "atom-ide-base/commons-ui/float-pane/selectable-overlay"

export class DataTipManager {
/**
Expand Down Expand Up @@ -476,8 +476,8 @@ export class DataTipManager {
invalidate: "never",
})

// makes the text selectable with the help of user-select: text
element.setAttribute("tabindex", "-1")
// makes overlay selectable
makeOverlaySelectable(editor, element)

editor.decorateMarker(overlayMarker, {
type: "overlay",
Expand All @@ -487,8 +487,6 @@ 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 @@ -499,17 +497,6 @@ 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 All @@ -532,25 +519,3 @@ export class DataTipManager {
this.dataTipMarkerDisposables = null
}
}

// TODO we should not need this
/** A manual copy listener */
async function copyListener(event: KeyboardEvent) {
event.preventDefault()
if (event.ctrlKey && event.key === "c") {
const text = document.getSelection()?.toString() ?? ""
await navigator.clipboard.writeText(text)
}
}

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

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

0 comments on commit ff10ef7

Please sign in to comment.