# Updating multiple selections individually with a transaction

**URL:** https://discuss.codemirror.net/t/updating-multiple-selections-individually-with-a-transaction/5077
**Category:** v6
**Created:** [October 2, 2022, 9:15am UTC](https://discuss.codemirror.net/t/updating-multiple-selections-individually-with-a-transaction/5077 "2022-10-02T09:15:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![BurningTreeC](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/burningtreec/32/2531_2.png) [@BurningTreeC](https://discuss.codemirror.net/u/BurningTreeC)
#### Post date: [October 2, 2022, 9:15am UTC](https://discuss.codemirror.net/t/updating-multiple-selections-individually-with-a-transaction/5077/1 "2022-10-02T09:15:33Z")

</div>

Hi there,

I’m pretty new to Codemirror6  
I’m trying to apply a transaction to my document which has multiple selections  
For each selection, I’d like to detect if the range’s from === the range’s to  
In that case I’d need to change the cursor position in the final document but always with this transaction

What I’m doing is

```auto
changes.push({from: ..., to: ..., insert: replacementText});

```

Then I have an Array of changes and I dispatch it by

```auto
.dispatch({changes: changes});

```

Which works fine  
But for some edge cases I need to update the selection in one go with the transaction  
My edge case is, that when there’s just the cursor (selection-start === selection-end) then I’d need the selection to “jump” further to the right in the final document for a given value

Does anybody have an example or an idea how that can be done?

I appreciate your answers  
Best wishes,  
Simon

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [October 2, 2022, 9:55am UTC](https://discuss.codemirror.net/t/updating-multiple-selections-individually-with-a-transaction/5077/2 "2022-10-02T09:55:57Z")

</div>

Have you seen [`state.changeByRange`](https://codemirror.net/docs/ref/#state.EditorState.changeByRange)? That is written for pretty much this kind of use case.

---

<div class="post-metadata">

### Author: ![BurningTreeC](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/burningtreec/32/2531_2.png) [@BurningTreeC](https://discuss.codemirror.net/u/BurningTreeC)
#### Post date: [October 3, 2022, 3:49am UTC](https://discuss.codemirror.net/t/updating-multiple-selections-individually-with-a-transaction/5077/3 "2022-10-03T03:49:21Z")

</div>

Thank you @marijn , I managed to achieve what I wanted using `state.changeByRange` !

Thanks again,  
Simon
