Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion app/src/ai/blocklist/agent_view/agent_input_footer/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use warpui::keymap::FixedBinding;
use warpui::{AppContext, Element, Entity, SingletonEntity, TypedActionView, View, ViewContext};

use super::toolbar_item::AgentToolbarItemKind;
use crate::appearance::AppearanceEvent;
use crate::chip_configurator::{
render_chip_editor_modal, render_chip_editor_sections, ChipConfigurator,
ChipConfiguratorAction, ChipConfiguratorLayout, ChipEditorModalConfig, ChipEditorMouseHandles,
Expand Down Expand Up @@ -180,6 +181,19 @@ impl AgentToolbarInlineEditor {
}
});

// Chip colors are derived from the theme, so rebuild the chips from
// settings when the theme changes to keep an open editor readable after a
// theme switch (this inline editor persists its arrangement on every
// edit, so reloading preserves the user's layout).
ctx.subscribe_to_model(&Appearance::handle(ctx), |me, _, event, ctx| {
if matches!(event, AppearanceEvent::ThemeChanged)
&& me.chip_configurator.current_dragging_state.is_none()
{
me.reset_from_settings(ctx);
ctx.notify();
}
});

editor
}

Expand Down Expand Up @@ -294,7 +308,21 @@ fn save_toolbar_selection<V: View>(
}

impl AgentToolbarEditorModal {
pub fn new(_ctx: &mut ViewContext<Self>) -> Self {
pub fn new(ctx: &mut ViewContext<Self>) -> Self {
// Chip colors are derived from the theme, so rebuild the chips when the
// theme changes to keep an open editor readable after a theme switch.
// Only rebuild while the modal is actually open (has chips) and not
// mid-drag.
ctx.subscribe_to_model(&Appearance::handle(ctx), |me, _, event, ctx| {
if matches!(event, AppearanceEvent::ThemeChanged)
&& me.chip_configurator.current_dragging_state.is_none()
&& me.chip_configurator.has_items()
{
let mode = me.mode;
open_toolbar_items_from_settings(&mut me.chip_configurator, mode, ctx);
ctx.notify();
}
});
Self {
mouse_handles: Default::default(),
chip_configurator: ChipConfigurator::new(ChipConfiguratorLayout::LeftRightZones),
Expand Down
9 changes: 9 additions & 0 deletions app/src/chip_configurator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ impl ChipConfigurator {
self.current_dragging_state = None;
}

/// Whether any zone currently holds chips (i.e. the configurator is open /
/// populated).
pub fn has_items(&self) -> bool {
!self.used_chips.is_empty()
|| !self.left_chips.is_empty()
|| !self.right_chips.is_empty()
|| !self.unused_chips.is_empty()
}

pub fn left_item_kinds(&self) -> Vec<AgentToolbarItemKind> {
self.left_chips
.iter()
Expand Down
20 changes: 20 additions & 0 deletions app/src/prompt/editor_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use warpui::{
AppContext, Element, Entity, SingletonEntity, TypedActionView, View, ViewContext, ViewHandle,
};

use crate::appearance::AppearanceEvent;
use crate::chip_configurator::{ChipConfigurator, ChipConfiguratorAction, ChipConfiguratorLayout};
use crate::context_chips::prompt::{Prompt, PromptConfiguration, PromptSelection};
use crate::context_chips::renderer::Renderer as ContextChipRenderer;
Expand Down Expand Up @@ -217,6 +218,25 @@ impl EditorModal {
dropdown
});

// Context-chip colors are theme-derived, so rebuild the chips when the
// theme changes to keep an open editor in sync (preserving the current
// used-chip selection).
ctx.subscribe_to_model(&Appearance::handle(ctx), |me, _, event, ctx| {
if matches!(event, AppearanceEvent::ThemeChanged)
&& me.chip_configurator.current_dragging_state.is_none()
&& me.chip_configurator.has_items()
{
let used_chips = me
.chip_configurator
.used_chips
.iter()
.filter_map(|r| r.chip_kind().cloned())
.collect();
me.update_used_chips(used_chips, ctx);
ctx.notify();
}
});

Self {
mouse_state_handles: Default::default(),
ps1_grid_info: None,
Expand Down
5 changes: 5 additions & 0 deletions app/src/settings_view/appearance_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,11 @@ impl AppearanceSettingsPageView {
editor.set_buffer_text(&format!("{line_height_ratio}"), ctx);
});
}
AppearanceEvent::ThemeChanged => {
// Context-chip colors are theme-derived, so rebuild the Input
// preview chips when the theme changes to keep them in sync.
self.context_chips = Self::get_context_chip_renderers(ctx);
}
_ => {}
}

Expand Down
Loading