Scoop API

scoop:scoop.surface:0.1.0

src/shared/shortcuts/matching.scoop

Selected production source · src/shared/shortcuts/matching.scoop

1package scoop.surface
3import scoop.window.*
5internal fun checkedBindings(bindings: Array<ShortcutBinding>): Array<ShortcutBinding> {
6 for (index in 0L ..< bindings.size) {
7 val current = bindings[index]
8 if (!current.enabled)
9 continue
10 for (previous in 0L ..< index) {
11 val other = bindings[previous]
12 requireInput(
13 !other.enabled || !current.chord.equivalentTo(other.chord),
14 "duplicate enabled shortcut combination"
15 )
16 }
17 }
18 return bindings
21/** Protect text shortcuts using the backend's actual AltGr information. */
22internal fun shortcutAllowed(context: RoutedEventContext, event: KeyEvent): Boolean {
23 if (context.currentTarget === context.target)
24 return true
25 val editing = context.target.area?.textInput ?: false
26 if (!editing)
27 return true
28 when (event.logicalKey) {
29 case Dead(_) -> return false
30 else -> {}
31 }
32 val modifiers = event.modifiers
33 val textModifier =
34 modifiers.altGraph ?: (modifiers.control && modifiers.alt && !modifiers.superKey)
35 if (!textModifier && (modifiers.superKey || modifiers.control))
36 return true
37 return when (event.logicalKey) {
38 case Named(val value) -> value != NamedKey.Space
39 else -> false
40 }