scoop:scoop.surface:0.1.0
src/shared/shortcuts/dispatch.scoop
Selected production source · src/shared/shortcuts/dispatch.scoop
1
package scoop.surface3
import scoop.window.*5
internal fun runShortcutBindings(6
context: RoutedEventContext,7
event: InputEvent,8
bindings: Array<ShortcutBinding>,9
isActive: () -> Boolean10
) {11
if (!isActive())12
return13
val key =14
when (event) {15
case Keyboard(val value) -> value16
else -> return17
}18
if (key.state != ElementState.Pressed || key.synthetic || !shortcutAllowed(context, key))19
return20
var chosen: ShortcutBinding? = None21
for (binding in bindings) {22
if (!isActive())23
return24
if (25
binding.enabled &&26
(!key.isRepeat || binding.allowRepeat) &&27
binding.chord.matches(key) &&28
binding.canExecute()29
) {30
if (!isActive())31
return32
when (chosen) {33
case Some(_) -> throw IllegalArgumentException(34
Some("multiple shortcut bindings match this key event")35
)36
case None -> chosen = Some(binding)37
}38
}39
}40
when (chosen) {41
case Some(val binding) -> if (isActive()) {42
context.consume()43
binding.action()44
}45
case None -> {}46
}47
}