# add \`PickerDelegate::selected_index_changed\` \(\#12059\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/097032327d6c8b88b5f81f204101e8587e81827a)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 097032327d6c8b88b5f81f204101e8587e81827a

Requested commit: 097032327d6c8b88b5f81f204101e8587e81827a

Commit: 097032327d6c8b88b5f81f204101e8587e81827a

Tree: 5840deaea8b8be02c5cef846985c406cbd86fca9

Author: Nate Butler

Committer: GitHub

## Message

````
add `PickerDelegate::selected_index_changed` (#12059)

Adds the ability to have some effect run when a selection changes in a
picker.

If the `PickerDelegate` implements something other than `None` for
`selected_index_changed` then each time the selection changes it will
run that effect.

For example:

```rs
impl PickerDelegate for PromptManagerDelegate {
    //...

    fn selected_index_changed(
        &self,
        ix: usize,
        cx: &mut ViewContext<Picker<Self>>,
    ) -> Option<Box<dyn Fn(&mut WindowContext) + 'static>> {
        Some(self.prompt_manager.set_active_prompt(ix, cx))
    }

    //...
}
```

This isn't currently used in any picker, but I'm adding this to allow
the functionality we intended for the prompt library, we're changing
selections, activates a preview in the right column.

This will be useful for building any sort of UI where there's a picker
on the left and a preview on the right, such as a UI like them
telescope.

Release Notes:

- N/A
````

## Parents

- [7db85b0d2ebf890d8faa69d53442cbfdc1a90d3f](https://git.cafe/gitcafe/zed/commit/7db85b0d2ebf890d8faa69d53442cbfdc1a90d3f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/097032327d6c8b88b5f81f204101e8587e81827a?format=markdown)
