I’m using allowMultipleSelections
to display cursors from remote clients. Each client needs to send its own selection. I saw EditorSelection.main
but that seems to be the last applied selection, not the one created by the user interaction.
My current solution is to read the main selection in a transaction with a keyboardselection
or pointerselection
userEvent
annotation. It seems like selection.main
should be the user’s local selection.
Is this the correct way to go about it?
Here’s the logic I have:
const updateListener = EditorView.updateListener.of(
(update) => {
const updatedLocalSelection = update.transactions.reduce(
(selection: SelectionRange | null, t) => {
const event = t.annotation(Transaction.userEvent)
if (
(event === 'keyboardselection' || event === 'pointerselection')
&& t.selection
) {
return t.selection.main
}
return selection
}, null)
if (updatedLocalSelection) {
// send updatedLocalSelection
}
})