Skip to content

Commit

Permalink
Add .unobstructed modifier for @Hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
somebee committed Apr 12, 2024
1 parent 2bf5c5a commit 916de33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/imba/src/imba/dom/core.web.imba
Expand Up @@ -307,6 +307,23 @@ extend class Element
return false
return parentElement..hidden? ?? true

###
Is the element visible inside viewport and clickable?
###
get unobstructed?
let box = getBoundingClientRect!
let vp = window.visualViewport
let x = box.left + box.width * 0.5
let y = box.top + box.height * 0.5

if vp.width > x > 0 and vp.height > y > 0
let hit = document.elementFromPoint(x,y)
return no unless hit and (hit.contains(self) or self.contains(hit))
return yes

return no


get focus?
document.activeElement == self

Expand Down
3 changes: 3 additions & 0 deletions packages/imba/src/imba/events/hotkey.imba
Expand Up @@ -152,6 +152,9 @@ class HotKeyManager
if handler.params.local and !handler.#target.contains(source)
continue

if handler.params.unobstructed
continue unless receiver.unobstructed?

if !e.#inEditable or (handler.capture? or handler.params.force)
let el = handler.#target
if group.contains(el) or el.contains(group) or (handler.global?)
Expand Down

0 comments on commit 916de33

Please sign in to comment.