Skip to content

Commit

Permalink
Add an action property to the shortcut spec and add a shortcut for de…
Browse files Browse the repository at this point in the history
…leting items

Signed-off-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg committed Feb 18, 2024
1 parent aeea57e commit 4b436db
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 18 deletions.
1 change: 1 addition & 0 deletions api/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @typedef {{
* id: String,
* action: String,
* description: String,
* trigger: String[]
* }} ShortcutSpec
Expand Down
15 changes: 3 additions & 12 deletions app/utils/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ function normalize (key) {
return key
}

async function dispatchShortcutEvent (id) {
async function dispatchShortcutEvent (action) {
const bridge = await api.load()
bridge.events.emitLocally('shortcut', id)
bridge.events.emitLocally('shortcut', action)
}

/**
Expand Down Expand Up @@ -102,7 +102,7 @@ export async function registerKeyDown (e) {
}

for (const shortcut of matchedShortcuts) {
dispatchShortcutEvent(shortcut.id)
dispatchShortcutEvent(shortcut.action)
}

/*
Expand All @@ -122,12 +122,3 @@ export async function registerKeyDown (e) {
export function registerKeyUp (e) {
keys.clear()
}

;(async function () {
const bridge = await api.load()
const identity = await bridge.client.awaitIdentity()

bridge.events.on(`local.${identity}.shortcut`, shortcut => {
dispatchShortcutEvent(shortcut)
})
})()
10 changes: 7 additions & 3 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,14 @@ Keyboard shortcuts SHOULD be registered with the API to give the user an index o
Shortcut triggers can be overridden by the user in the settings panel.

### Listening to keyboard shortcuts
Listen to a registered shortcut by subscribing to the `shortcut` event, as such:
Listen to a registered shortcut by subscribing to the `shortcut` event.
When triggered the action will be provided as the listeners first argument as such:

```javascript
import bridge from 'bridge'

bridge.events.on('shortcut', id => {
console.log('Shortcut was triggered with id:', id)
bridge.events.on('shortcut', action => {
console.log('Shortcut was triggered for action:', action)
// React to action
})
```
Expand All @@ -374,11 +375,13 @@ The field should be set to an array of shortcut-specification objects. Such as:
"shortcuts": [
{
"id": "bridge.shortcuts.play",
"action": "play",
"description": "My custom shortcut",
"trigger": ["Shift", "A"]
},
{
"id": "bridge.shortcuts.stop",
"action": "stop",
"description": "My second custom shortcut",
"trigger": ["Shift", "B"]
}
Expand All @@ -396,6 +399,7 @@ import bridge from 'bridge'

bridge.shortcuts.registerShortcut({
id: 'myPlugin.shortcuts.myShortcut',
action: 'myPlugin.myAction',
description: 'Trigger my command',
trigger: ['Shift', 'CommandOrControl', 'A']
})
Expand Down
1 change: 1 addition & 0 deletions docs/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Contributions can be added either through `package.json` or using the matching a
"shortcuts": [
{
"id": "my-plugin.shortcuts.my-shortcut",
"action": "my-plugin.my-action",
"description": "Executes my cool action",
"trigger": ["Shift", "A"]
}
Expand Down
8 changes: 7 additions & 1 deletion lib/schemas/shortcuts.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"type": "string",
"description": "A globally unique identifier for the shortcut"
},
"action": {
"type": "string",
"description": "The identifier of the action to perform"
},
"description": {
"type": "string",
"description": "A human readable description of the shortcut, this will be shown in the settings panel"
Expand Down Expand Up @@ -75,7 +79,9 @@
"ArrowDown",
"ArrowLeft",
"ArrowRight",
"CommandOrControl"
"CommandOrControl",
"Backspace",
"Delete"
]
}
}
Expand Down
7 changes: 5 additions & 2 deletions plugins/rundown/app/components/RundownList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ export function RundownList ({
case 'bridge.rundown.previous':
select(-1)
break
case 'bridge.rundown.play':
case 'delete':
bridge.items.deleteItems(selection)
break
case 'play':
selection.forEach(itemId => bridge.items.playItem(itemId))
break
case 'bridge.rundown.stop':
case 'stop':
selection.forEach(itemId => bridge.items.stopItem(itemId))
break
case 'copy':
Expand Down
7 changes: 7 additions & 0 deletions plugins/rundown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,39 @@
"shortcuts": [
{
"id": "bridge.rundown.play",
"action": "play",
"description": "Play the selected item",
"trigger": ["F2"]
},
{
"id": "bridge.rundown.stop",
"action": "stop",
"description": "Stop the selected item",
"trigger": ["F1"]
},
{
"id": "bridge.rundown.next",
"action": "bridge.rundown.next",
"trigger": ["ArrowDown"]
},
{
"id": "bridge.rundown.previous",
"action": "bridge.rundown.previous",
"trigger": ["ArrowUp"]
},
{
"id": "bridge.rundown.collapse",
"action": "bridge.rundown.collapse",
"trigger": ["ArrowLeft"]
},
{
"id": "bridge.rundown.expand",
"action": "bridge.rundown.expand",
"trigger": ["ArrowRight"]
},
{
"id": "bridge.rundown.select-multiple",
"action": "bridge.rundown.select-multiple",
"trigger": ["CommandOrControl"]
}
]
Expand Down
15 changes: 15 additions & 0 deletions plugins/shortcuts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,33 @@
"shortcuts": [
{
"id": "copy",
"action": "copy",
"description": "Copy selected content into the clipboard",
"trigger": ["CommandOrControl", "C"]
},
{
"id": "paste",
"action": "paste",
"description": "Paste the contents of the clipboard",
"trigger": ["CommandOrControl", "V"]
},
{
"id": "selectAll",
"action": "selectAll",
"description": "Select all",
"trigger": ["CommandOrControl", "A"]
},
{
"id": "delete",
"action": "delete",
"description": "Delete",
"trigger": ["Delete"]
},
{
"id": "deleteWithBackspace",
"action": "delete",
"description": "Delete",
"trigger": ["CommandOrControl", "Backspace"]
}
]
},
Expand Down

0 comments on commit 4b436db

Please sign in to comment.