From baadd44b29c9d8e867de5020eb724d6285554d89 Mon Sep 17 00:00:00 2001 From: Axel Boberg Date: Wed, 12 Nov 2025 00:14:28 +0100 Subject: [PATCH] Fix an issue where 'select next sibling' stopped working Signed-off-by: Axel Boberg --- api/browser/selection.js | 27 +++++++++++++++++++++++++++ api/state.js | 2 +- plugins/rundown/lib/handlers.js | 7 ++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/api/browser/selection.js b/api/browser/selection.js index 6f68125f..44610bbf 100644 --- a/api/browser/selection.js +++ b/api/browser/selection.js @@ -43,12 +43,39 @@ class Selection { return } this.#client = newValue + this.#setup() } constructor (props) { this.#props = props } + async #setup () { + /* + Only listen to changes to + the _serverSelection key + and set the selection in this + thread when it changes + + Typically the API shouldn't + attach event listeners itself + as it may force data to be pushed + even though it's not used by the client + + - but make an exception here as + this code is only run in the renderer + thread and listeners on state.change + are required anyway + */ + this.#props.Events.on('state.change', (state, set) => { + if (!set?._connections?.[this.#client.getIdentity()]?._serverSelection) { + return + } + const newSelection = state?._connections?.[this.#client.getIdentity()]?._serverSelection + this.setSelection(newSelection) + }) + } + /** * Select an item, * will replace the diff --git a/api/state.js b/api/state.js index 8b87225c..bdc153ad 100644 --- a/api/state.js +++ b/api/state.js @@ -64,7 +64,7 @@ class State { this.applyLocally(set) } - return this.#state + return [this.#state, set] }) } diff --git a/plugins/rundown/lib/handlers.js b/plugins/rundown/lib/handlers.js index 158c45af..4d5b211e 100644 --- a/plugins/rundown/lib/handlers.js +++ b/plugins/rundown/lib/handlers.js @@ -99,7 +99,12 @@ async function selectItem (id) { bridge.state.apply({ _connections: { [mainClientId]: { - selection: { $replace: [id] } + /* + Use a key that the + client can listen to + and act on + */ + _serverSelection: { $replace: [id] } } } })