Repository: lapce/lapce
File: lapce-ui/src/palette.rs (Rust)

Code before:
        self.input.event(ctx, event, data, env);
        self.content.event(ctx, event, data, env);
        self.preview.event(ctx, event, data, env);
    }

    fn lifecycle(
        &mut self,
        ctx: &mut LifeCycleCtx,
        event: &LifeCycle,
        data: &LapceTabData,
        env: &Env,
    ) {
        self.input.lifecycle(ctx, event, data, env);
        self.content.lifecycle(ctx, event, data, env);
        self.preview.lifecycle(ctx, event, data, env);
        if data.palette.has_nonzero_default_index {
            self.ensure_item_visible(data, env, ctx.size().width, |cmd| {
                ctx.submit_command(cmd)
            });
        }
    }

    fn update(
        &mut self,
        ctx: &mut UpdateCtx,
        old_data: &LapceTabData,
        data: &LapceTabData,
        env: &Env,
    ) {
        if old_data.palette.input != data.palette.input
            || old_data.palette.index != data.palette.index
        {
            self.ensure_item_visible(data, env, ctx.size().width, |cmd| {
                ctx.submit_command(cmd)
            });
        }
        self.input.update(ctx, data, env);
        self.content.update(ctx, data, env);
        self.preview.update(ctx, data, env);
    }

    fn layout(
        &mut self,
        ctx: &mut LayoutCtx,
        bc: &BoxConstraints,
        data: &LapceTabData,
        env: &Env,
    ) -> Size {
        let width = bc.max().width;
        let max_height = bc.max().height;


Review comment (bug):
I think if you do

```
old_data.palette.input != data.palette.input
            || old_data.palette.index != data.palette.index
            || old_data.palette.run_id != data.palette.run_id
```

Then you don't need the ensure_item_visible in lifecycle.

I might be wrong. Can you please test. 

Code after:
        self.input.event(ctx, event, data, env);
        self.content.event(ctx, event, data, env);
        self.preview.event(ctx, event, data, env);
    }

    fn lifecycle(
        &mut self,
        ctx: &mut LifeCycleCtx,
        event: &LifeCycle,
        data: &LapceTabData,
        env: &Env,
    ) {
        self.input.lifecycle(ctx, event, data, env);
        self.content.lifecycle(ctx, event, data, env);
        self.preview.lifecycle(ctx, event, data, env);
    }

    fn update(
        &mut self,
        ctx: &mut UpdateCtx,
        old_data: &LapceTabData,
        data: &LapceTabData,
        env: &Env,
    ) {
        if old_data.palette.input != data.palette.input
            || old_data.palette.index != data.palette.index
            || old_data.palette.run_id != data.palette.run_id
        {
            self.ensure_item_visible(ctx, data, env);
        }
        self.input.update(ctx, data, env);
        self.content.update(ctx, data, env);
        self.preview.update(ctx, data, env);
    }

    fn layout(
        &mut self,
        ctx: &mut LayoutCtx,
        bc: &BoxConstraints,
        data: &LapceTabData,
        env: &Env,
    ) -> Size {
        let width = bc.max().width;
        let max_height = bc.max().height;

        let bc = BoxConstraints::tight(Size::new(width, bc.max().height));

        let input_size = self.input.layout(ctx, &bc, data, env);
        self.input.set_origin(ctx, data, env, Point::ZERO);

        let height = MAX_PALETTE_ITEMS.min(data.palette.len());