add repository shortcuts and extract repository switcher
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run

This commit is contained in:
2026-11-17 14:56:09 +07:00
parent 0cd0e4672f
commit d5bf8c3e0f
14 changed files with 702 additions and 211 deletions
+11
View File
@@ -111,6 +111,13 @@ The style methods on elements are similar to those used by Tailwind CSS.
If some attributes or children of an element tree are conditional, `.when(condition, |this| ...)` can be used to run the closure only when `condition` is true. Similarly, `.when_some(option, |this, value| ...)` runs the closure when the `Option` has a value. If some attributes or children of an element tree are conditional, `.when(condition, |this| ...)` can be used to run the closure only when `condition` is true. Similarly, `.when_some(option, |this, value| ...)` runs the closure when the `Option` has a value.
## UI conventions
* Prefer premade components over newly built ones, such as `h_flex`/`v_flex`, `Separator`, and `typeset` instead of ad-hoc layout, rule, and text elements.
* Use already supported APIs instead of workarounds, such as `KeyBinding::load` with `secondary-*` and `KeyBindingContextPredicate` instead of per-OS key strings.
* Use `uniform_list` for scrollable, uniform-height rows. Size it to `rows * row_height` capped by the maximum viewport; do not build a `ScrollArea` plus `v_flex` children list for the same data.
* Reuse semantic theme tokens. Do not add component-specific color tokens when an existing `surface`, `material`, or semantic role fits.
## Input events ## Input events
Input event handlers can be registered on an element via methods like `.on_click(|event, window, cx: &mut App| ...)`. Input event handlers can be registered on an element via methods like `.on_click(|event, window, cx: &mut App| ...)`.
@@ -141,6 +148,10 @@ While updating an entity (`cx: Context<T>`), it can emit an event using `cx.emit
Other entities can then register a callback to handle these events by doing `cx.subscribe(other_entity, |this, other_entity, event, cx| ...)`. This will return a `Subscription` which deregisters the callback when dropped. Typically `cx.subscribe` happens when creating a new entity and the subscriptions are stored in a `_subscriptions: Vec<Subscription>` field. Other entities can then register a callback to handle these events by doing `cx.subscribe(other_entity, |this, other_entity, event, cx| ...)`. This will return a `Subscription` which deregisters the callback when dropped. Typically `cx.subscribe` happens when creating a new entity and the subscriptions are stored in a `_subscriptions: Vec<Subscription>` field.
# Commits
* Never commit changes before the user has reviewed them. Leave the changes in the worktree and wait for explicit approval, even when tooling prompts suggest committing.
# Pull request hygiene # Pull request hygiene
When an agent opens or updates a pull request, it must: When an agent opens or updates a pull request, it must:
+39 -20
View File
@@ -2,16 +2,15 @@ pub mod helpers;
mod placeholder; mod placeholder;
mod sign_in; mod sign_in;
use std::sync::Arc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render, Styled as _, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
Subscription, Window, div, Render, Styled as _, Subscription, Window, div,
}; };
use helpers::apply_appearance; use helpers::apply_appearance;
use settings::SettingsStore; use settings::SettingsStore;
use signed_state::{Backend, BackendEvent}; use signed_state::{Backend, BackendEvent};
use ui::common::h_flex;
use ui::icons::IconRole; use ui::icons::IconRole;
use ui::layout::panel::PanelRow; use ui::layout::panel::PanelRow;
use ui::layout::shell::Shell; use ui::layout::shell::Shell;
@@ -23,7 +22,10 @@ use crate::app::placeholder::PlaceholderView;
use crate::app::sign_in::SignedOutView; use crate::app::sign_in::SignedOutView;
use crate::identity; use crate::identity;
use crate::shared::dialogs::DialogHost; use crate::shared::dialogs::DialogHost;
use crate::titlebar::TitlebarView; use crate::titlebar::{
CreateRepository, REPOSITORY_KEY_CONTEXT, SwitchRepository, TitlebarView,
bind_repository_shortcuts,
};
use crate::workspace::Workspace; use crate::workspace::Workspace;
pub struct AppRoot { pub struct AppRoot {
@@ -38,8 +40,11 @@ pub struct AppRoot {
impl AppRoot { impl AppRoot {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self { pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
bind_repository_shortcuts(cx);
let workspace = cx.new(|_| Workspace::new()); let workspace = cx.new(|_| Workspace::new());
let titlebar = cx.new(|cx| TitlebarView::new(workspace.downgrade(), window, cx)); let titlebar = cx.new(|cx| TitlebarView::new(workspace.downgrade(), window, cx));
let toasts = cx.new(|_| Toasts::default()); let toasts = cx.new(|_| Toasts::default());
let sign_in = cx.new(|_| SignedOutView::new()); let sign_in = cx.new(|_| SignedOutView::new());
let empty = cx.new(|_| PlaceholderView::new("Select a repository")); let empty = cx.new(|_| PlaceholderView::new("Select a repository"));
@@ -98,43 +103,57 @@ impl Render for AppRoot {
let titlebar_view = self.titlebar.read(cx); let titlebar_view = self.titlebar.read(cx);
let workspace = self.workspace.read(cx); let workspace = self.workspace.read(cx);
let main = workspace.active_main();
let has_main = main.is_some();
let repo_tabs =
titlebar_view.render_repo_tabs(workspace.open_mains(), workspace.active_main_id());
let tab_bar = h_flex()
.gap_2()
.child(titlebar_view.repository_switcher())
.when_some(repo_tabs, |bar, tabs| bar.child(tabs));
div() div()
.relative() .relative()
.size_full() .size_full()
.font_family(".SystemUIFont") .font_family(".SystemUIFont")
.text_color(cx.theme().colors.foreground) .text_color(cx.theme().colors.foreground)
.key_context(REPOSITORY_KEY_CONTEXT)
.on_action(cx.listener(|this, action: &SwitchRepository, window, cx| {
this.titlebar.update(cx, |titlebar, cx| {
titlebar.activate_shortcut(action.index, window, cx);
});
}))
.on_action(cx.listener(|this, _: &CreateRepository, window, cx| {
this.titlebar.update(cx, |titlebar, cx| {
titlebar.create_repository(window, cx);
});
}))
.child( .child(
Shell::new("signed-shell") Shell::new("signed-shell")
.titlebar( .titlebar(
Titlebar::new("signed-titlebar") Titlebar::new("signed-titlebar")
.when_some(titlebar_view.render_actions(cx), |titlebar, actions| { .child(titlebar_view.render_actions())
titlebar.child(actions) .tab_bar(tab_bar)
})
.when_some(titlebar_view.render_tabs(cx), |titlebar, tabs| {
titlebar.tab_bar(tabs)
})
.when_some(titlebar_view.render_user_menu(cx), |titlebar, menu| { .when_some(titlebar_view.render_user_menu(cx), |titlebar, menu| {
titlebar.suffix(menu) titlebar.suffix(menu)
}), }),
) )
.panel( .panel(
PanelRow::new("signed-panel") PanelRow::new("signed-panel")
.when(signed_in, |row| { .when_some(main, |row, main| {
row.main( row.main(main).when(workspace.has_details(), |row| {
workspace
.active_main()
.unwrap_or_else(|| Arc::new(self.empty.clone())),
)
.when(workspace.has_details(), |row| {
row.split(self.workspace.clone()) row.split(self.workspace.clone())
}) })
}) })
.when(!signed_in, |row| row.main(self.sign_in.clone())), .when(!has_main && signed_in, |row| row.main(self.empty.clone()))
.when(!has_main && !signed_in, |row| {
row.main(self.sign_in.clone())
}),
) )
.toasts(self.toasts.clone()), .toasts(self.toasts.clone()),
) )
.child(self.dialogs.clone()) .child(self.dialogs.clone())
.when(signed_in, |root| root.child(titlebar_view.palette())) .child(titlebar_view.palette())
} }
} }
-25
View File
@@ -1,25 +0,0 @@
use gpui::{AnyElement, App, IntoElement};
use signed_state::ResolvedLocalRepo;
use ui::avatar::Avatar;
use ui::common::Sizable as _;
/// The bound owner's avatar, falling back to the path's pixel avatar when unowned.
pub(super) fn local_avatar(
entry: &ResolvedLocalRepo,
directory: &gpui::Entity<metadata::ProfileDirectory>,
cx: &App,
) -> AnyElement {
let Some(owner) = entry.nip34.as_ref().and_then(|binding| binding.owner) else {
return Avatar::new(entry.path.to_string_lossy())
.small()
.into_any_element();
};
let profile = directory.read(cx).profile(&owner, cx);
Avatar::new(owner)
.name(profile.name())
.picture(profile.picture())
.small()
.into_any_element()
}
+234 -89
View File
@@ -1,18 +1,22 @@
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use gpui::{ use gpui::{
AnyElement, App, AppContext as _, Context, IntoElement, ParentElement as _, SharedString, AnyElement, App, AppContext as _, Context, Entity, IntoElement, KeyBinding,
Styled as _, Subscription, WeakEntity, Window, px, KeyBindingContextPredicate, ParentElement as _, SharedString, Styled as _, Subscription,
WeakEntity, Window, px,
}; };
use helpers::local_avatar;
use metadata::{Profile, ProfileDirectory}; use metadata::{Profile, ProfileDirectory};
use nostr::prelude::PublicKey; use nostr::prelude::PublicKey;
use repository_switcher::RepositoryEntry;
pub(crate) use repository_switcher::RepositorySwitcher;
use signed_core::Announcement; use signed_core::Announcement;
use signed_state::{Backend, BackendEvent, LocalReposStore, RepoListStore, ResolvedLocalRepo}; use signed_state::{Backend, BackendEvent, LocalReposStore, RepoListStore, ResolvedLocalRepo};
use ui::avatar::Avatar; use ui::avatar::Avatar;
use ui::button::{Button, ButtonVariant}; use ui::button::{Button, ButtonVariant};
use ui::command_palette::{Command, CommandPalette, CommandPaletteState}; use ui::command_palette::{Command, CommandPalette, CommandPaletteState};
use ui::common::{Sizable as _, h_flex}; use ui::common::h_flex;
use ui::icons::{Icon, IconRole}; use ui::icons::{Icon, IconRole};
use ui::menu::{Menu, MenuItem}; use ui::menu::{Menu, MenuItem};
use ui::tabs::{Tab, Tabs, TabsVariant}; use ui::tabs::{Tab, Tabs, TabsVariant};
@@ -24,7 +28,77 @@ use crate::shared::{log_dropped, panels};
use crate::workspace::Workspace; use crate::workspace::Workspace;
use crate::{identity, settings}; use crate::{identity, settings};
mod helpers; mod repository_switcher;
/// The key context the repository shortcuts bind against.
pub(crate) const REPOSITORY_KEY_CONTEXT: &str = "Signed";
const CREATE_KEYSTROKE: &str = "secondary-n";
const REPOSITORY_KEYSTROKES: [&str; 9] = [
"secondary-1",
"secondary-2",
"secondary-3",
"secondary-4",
"secondary-5",
"secondary-6",
"secondary-7",
"secondary-8",
"secondary-9",
];
/// Opens the repository at this index in the combined announced/local list.
#[derive(Clone, PartialEq, gpui::Action)]
#[action(namespace = signed, no_json)]
pub(crate) struct SwitchRepository {
pub index: usize,
}
/// Opens the create-repository dialog.
#[derive(Clone, PartialEq, gpui::Action)]
#[action(namespace = signed, no_json)]
pub(crate) struct CreateRepository;
pub(crate) fn bind_repository_shortcuts(cx: &mut App) {
let context = match KeyBindingContextPredicate::parse(REPOSITORY_KEY_CONTEXT) {
Ok(context) => Some(Rc::new(context)),
Err(error) => {
log::error!("failed to parse repository key context: {error}");
return;
}
};
let bindings = REPOSITORY_KEYSTROKES
.into_iter()
.enumerate()
.map(|(index, keystroke)| {
KeyBinding::load(
keystroke,
Box::new(SwitchRepository { index }),
context.clone(),
false,
None,
cx,
)
})
.chain(std::iter::once(KeyBinding::load(
CREATE_KEYSTROKE,
Box::new(CreateRepository),
context.clone(),
false,
None,
cx,
)))
.collect::<Result<Vec<_>, _>>();
let bindings = match bindings {
Ok(bindings) => bindings,
Err(error) => {
log::error!("failed to parse repository shortcut keystrokes: {error}");
return;
}
};
cx.bind_keys(bindings);
}
pub struct TitlebarView { pub struct TitlebarView {
weak: WeakEntity<Self>, weak: WeakEntity<Self>,
@@ -33,10 +107,11 @@ pub struct TitlebarView {
announcements: Arc<Vec<Announcement>>, announcements: Arc<Vec<Announcement>>,
/// Local repositories found by the scan that are not announced yet. /// Local repositories found by the scan that are not announced yet.
local_repos: Arc<Vec<ResolvedLocalRepo>>, local_repos: Arc<Vec<ResolvedLocalRepo>>,
/// Profiles rendered by the titlebar tabs. /// Profiles rendered by the repository switcher.
directory: gpui::Entity<ProfileDirectory>, directory: Entity<ProfileDirectory>,
/// The command palette opened from the titlebar. /// The command palette opened from the titlebar.
palette: gpui::Entity<CommandPaletteState>, palette: Entity<CommandPaletteState>,
repository_switcher: Entity<RepositorySwitcher>,
user_menu_open: bool, user_menu_open: bool,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
} }
@@ -51,8 +126,42 @@ impl TitlebarView {
let repos = RepoListStore::global(cx); let repos = RepoListStore::global(cx);
let local = LocalReposStore::global(cx); let local = LocalReposStore::global(cx);
let palette = Self::new_palette(workspace.clone(), window, cx);
let directory = ProfileDirectory::new(cx);
let entity = cx.entity();
let weak = entity.downgrade();
let mut subscriptions = Vec::new(); let mut subscriptions = Vec::new();
let repository_switcher = cx.new(|cx| {
RepositorySwitcher::new(
directory.clone(),
{
let weak = weak.clone();
move |index, window, cx| {
log_dropped(weak.update(cx, |this, cx| {
this.activate(index, window, cx);
}));
}
},
{
let weak = weak.clone();
move |window, cx| {
log_dropped(weak.update(cx, |this, cx| {
this.create_repository(window, cx);
}));
}
},
|cx| {
let local_repos = LocalReposStore::global(cx);
local_repos.update(cx, |store, cx| {
store.rescan(cx);
});
},
cx,
)
});
subscriptions.push(cx.subscribe(&backend, |this, _backend, event, cx| { subscriptions.push(cx.subscribe(&backend, |this, _backend, event, cx| {
let signer_changed = matches!(event, BackendEvent::SignerChanged); let signer_changed = matches!(event, BackendEvent::SignerChanged);
let signer_required = matches!(event, BackendEvent::SignerRequired); let signer_required = matches!(event, BackendEvent::SignerRequired);
@@ -74,21 +183,6 @@ impl TitlebarView {
} }
})); }));
let palette = Self::new_palette(workspace.clone(), window, cx);
let entity = cx.entity();
let this = Self {
weak: entity.downgrade(),
workspace,
announcements: Arc::new(Vec::new()),
local_repos: Arc::new(Vec::new()),
directory: ProfileDirectory::new(cx),
palette,
user_menu_open: false,
_subscriptions: subscriptions,
};
cx.defer(move |cx| { cx.defer(move |cx| {
entity.update(cx, |this, cx| { entity.update(cx, |this, cx| {
if this.refresh(cx) { if this.refresh(cx) {
@@ -97,14 +191,24 @@ impl TitlebarView {
}); });
}); });
this Self {
weak: cx.entity().downgrade(),
workspace,
announcements: Arc::new(Vec::new()),
local_repos: Arc::new(Vec::new()),
directory,
palette,
repository_switcher,
user_menu_open: false,
_subscriptions: subscriptions,
}
} }
fn new_palette( fn new_palette(
workspace: WeakEntity<Workspace>, workspace: WeakEntity<Workspace>,
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> gpui::Entity<CommandPaletteState> { ) -> Entity<CommandPaletteState> {
cx.new(|cx| { cx.new(|cx| {
let matcher = |query: &str, commands: &[Command]| { let matcher = |query: &str, commands: &[Command]| {
let needle = query.to_lowercase(); let needle = query.to_lowercase();
@@ -116,7 +220,7 @@ impl TitlebarView {
}; };
CommandPaletteState::new( CommandPaletteState::new(
CommandPalette::new("signed-command-palette", Self::palette_commands(), matcher) CommandPalette::new("command-palette", Self::palette_commands(), matcher)
.on_execute(move |command, window, cx| match command.id.as_ref() { .on_execute(move |command, window, cx| match command.id.as_ref() {
"create-repo" => dialogs::create::open(workspace.clone(), window, cx), "create-repo" => dialogs::create::open(workspace.clone(), window, cx),
"rescan-repos" => { "rescan-repos" => {
@@ -143,7 +247,7 @@ impl TitlebarView {
] ]
} }
pub fn palette(&self) -> gpui::Entity<CommandPaletteState> { pub fn palette(&self) -> Entity<CommandPaletteState> {
self.palette.clone() self.palette.clone()
} }
@@ -173,8 +277,8 @@ impl TitlebarView {
self.local_repos = Arc::new(local_repos); self.local_repos = Arc::new(local_repos);
let mut profiles: Vec<PublicKey> = user.into_iter().collect(); let mut profiles: Vec<PublicKey> = user.into_iter().collect();
let owners: Vec<PublicKey> = self profiles.extend(
.local_repos self.local_repos
.iter() .iter()
.filter_map(|entry| { .filter_map(|entry| {
entry entry
@@ -183,47 +287,84 @@ impl TitlebarView {
.and_then(|binding| binding.owner) .and_then(|binding| binding.owner)
.filter(|owner| !profiles.contains(owner)) .filter(|owner| !profiles.contains(owner))
}) })
.collect(); .collect::<Vec<PublicKey>>(),
);
profiles.extend(owners);
self.directory.update(cx, |directory, cx| { self.directory.update(cx, |directory, cx| {
directory.track(profiles, cx); directory.track(profiles, cx);
}); });
if announcements_changed || local_changed {
let entries = self.repository_entries();
self.repository_switcher.update(cx, |switcher, cx| {
switcher.set_entries(entries, cx);
});
}
announcements_changed || local_changed announcements_changed || local_changed
} }
pub fn render_tabs(&self, cx: &App) -> Option<Tabs> { fn repository_entries(&self) -> Vec<RepositoryEntry> {
let backend = Backend::global(cx); let mut entries = Vec::with_capacity(self.announcements.len() + self.local_repos.len());
backend.read(cx).current_user()?;
let announcements = self.announcements.clone(); for (index, announcement) in self.announcements.iter().enumerate() {
let local_repos = self.local_repos.clone(); let label = announcement
.name
.as_deref()
.map(SharedString::from)
.unwrap_or_else(|| SharedString::from(announcement.id.clone()));
if announcements.is_empty() && local_repos.is_empty() { entries.push(RepositoryEntry {
index,
key: announcement_key(announcement),
label,
owner: Some(announcement.owner),
});
}
for (local_index, entry) in self.local_repos.iter().enumerate() {
let owner = entry.nip34.as_ref().and_then(|binding| binding.owner);
entries.push(RepositoryEntry {
index: self.announcements.len() + local_index,
key: local_key(entry),
label: entry.name(),
owner,
});
}
entries
}
pub(crate) fn repository_switcher(&self) -> Entity<RepositorySwitcher> {
self.repository_switcher.clone()
}
/// Tabs for the repositories opened in the main panel.
pub fn render_repo_tabs(
&self,
open: &[SharedString],
active: Option<&SharedString>,
) -> Option<Tabs> {
if open.is_empty() {
return None; return None;
} }
let keys: Vec<SharedString> = announcements let lookup: HashMap<SharedString, RepositoryEntry> = self
.iter() .repository_entries()
.map(announcement_key) .into_iter()
.chain(local_repos.iter().map(local_key)) .map(|entry| (entry.key.clone(), entry))
.collect(); .collect();
let active = self let open_tabs = open.to_vec();
.workspace let lookup_for_tabs = lookup;
.read_with(cx, |workspace, _| workspace.active_main_id().cloned()) let lookup_directory = self.directory.clone();
.ok()
.flatten();
let selected = active let selected = active
.as_ref() .and_then(|id| open.iter().position(|open_id| open_id == id))
.and_then(|id| keys.iter().position(|key| key == id))
.unwrap_or(usize::MAX); .unwrap_or(usize::MAX);
let weak = self.weak.clone(); let workspace = self.workspace.clone();
let directory = self.directory.clone(); let open_for_change = open.to_vec();
Some( Some(
Tabs::new("signed-repo-tabs") Tabs::new("signed-repo-tabs")
@@ -231,41 +372,50 @@ impl TitlebarView {
.overflow_scroll(true) .overflow_scroll(true)
.selected(selected) .selected(selected)
.tabs(move |_, cx| { .tabs(move |_, cx| {
let mut tabs = Vec::with_capacity(announcements.len() + local_repos.len()); open_tabs
.iter()
.map(|id| {
let entry = lookup_for_tabs.get(id);
let label = entry
.map(|entry| entry.label.clone())
.unwrap_or_else(|| id.clone());
for announcement in announcements.iter() { let mut tab = Tab::new(id.clone(), label);
let profile = directory.read(cx).profile(&announcement.owner, cx); if let Some(entry) = entry {
let label = announcement tab = tab.lead(entry.avatar(&lookup_directory, cx));
.name
.as_deref()
.map(SharedString::from)
.unwrap_or_else(|| SharedString::from(announcement.id.clone()));
tabs.push(
Tab::new(announcement_key(announcement), label).lead(
Avatar::new(format!("{}:{}", announcement.owner, announcement.id))
.name(profile.name())
.picture(profile.picture())
.small(),
),
);
} }
tab
for entry in local_repos.iter() {
tabs.push(
Tab::new(local_key(entry), entry.name())
.kind("Local Repositories")
.lead(local_avatar(entry, &directory, cx)),
);
}
tabs
}) })
.on_change(move |index, window, cx| { .collect()
log_dropped(weak.update(cx, |this, cx| this.activate(index, window, cx))); })
.on_change(move |index, _, cx| {
let Some(id) = open_for_change.get(index).cloned() else {
return;
};
log_dropped(workspace.update(cx, |workspace, cx| {
workspace.activate_main(&id, cx);
}));
}), }),
) )
} }
pub(crate) fn activate_shortcut(
&mut self,
index: usize,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.repository_switcher
.update(cx, |switcher, cx| switcher.close(cx));
self.activate(index, window, cx);
}
pub(crate) fn create_repository(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.repository_switcher
.update(cx, |switcher, cx| switcher.close(cx));
dialogs::create::open(self.workspace.clone(), window, cx);
}
fn activate(&mut self, index: usize, window: &mut Window, cx: &mut Context<Self>) { fn activate(&mut self, index: usize, window: &mut Window, cx: &mut Context<Self>) {
if let Some(announcement) = self.announcements.get(index) { if let Some(announcement) = self.announcements.get(index) {
let addr = announcement.addr(); let addr = announcement.addr();
@@ -401,18 +551,14 @@ impl TitlebarView {
}) })
} }
pub fn render_actions(&self, cx: &App) -> Option<AnyElement> { pub fn render_actions(&self) -> AnyElement {
let backend = Backend::global(cx);
backend.read(cx).current_user()?;
let workspace = self.workspace.clone(); let workspace = self.workspace.clone();
Some(
h_flex() h_flex()
.gap_1() .gap_1()
.child( .child(
Button::new("open-command-palette") Button::new("open-command-palette")
.icon(Icon::named(IconRole::Search)) .icon(IconRole::Search)
.variant(ButtonVariant::Ghost) .variant(ButtonVariant::Ghost)
.tooltip(Tooltip::text("Command palette")) .tooltip(Tooltip::text("Command palette"))
.on_click({ .on_click({
@@ -424,15 +570,14 @@ impl TitlebarView {
) )
.child( .child(
Button::new("add-repo") Button::new("add-repo")
.icon(Icon::named(IconRole::Plus)) .icon(IconRole::Plus)
.variant(ButtonVariant::Ghost) .variant(ButtonVariant::Ghost)
.tooltip(Tooltip::text("Create repository")) .tooltip(Tooltip::text("Create repository"))
.on_click(move |_, window, cx| { .on_click(move |_, window, cx| {
dialogs::create::open(workspace.clone(), window, cx); dialogs::create::open(workspace.clone(), window, cx);
}), }),
) )
.into_any_element(), .into_any_element()
)
} }
} }
@@ -0,0 +1,309 @@
use std::rc::Rc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
App, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _, Render, Role,
SharedString, StatefulInteractiveElement as _, Styled as _, UniformListScrollHandle, Window,
div, px, uniform_list,
};
use metadata::ProfileDirectory;
use nostr::prelude::PublicKey;
use ui::avatar::Avatar;
use ui::button::{Button, ButtonSide, ButtonVariant};
use ui::common::{Sizable as _, h_flex, v_flex};
use ui::icons::{Icon, IconRole};
use ui::input::{Input, InputState};
use ui::popover::Popover;
use ui::separator::Separator;
use ui::theme::{ActiveTheme as _, TextRole, Typeset};
use ui::tooltip::Tooltip;
use crate::shared::log_dropped;
type OpenHandler = Rc<dyn Fn(usize, &mut Window, &mut App)>;
type CreateHandler = Rc<dyn Fn(&mut Window, &mut App)>;
type RescanHandler = Rc<dyn Fn(&mut App)>;
/// One row of the repository switcher.
#[derive(Clone)]
pub(super) struct RepositoryEntry {
pub(super) index: usize,
pub(super) key: SharedString,
pub(super) label: SharedString,
pub(super) owner: Option<PublicKey>,
}
impl RepositoryEntry {
pub(super) fn avatar(&self, directory: &Entity<ProfileDirectory>, cx: &App) -> Avatar {
let mut avatar = Avatar::new(self.key.clone());
if let Some(owner) = self.owner {
let profile = directory.read(cx).profile(&owner, cx);
avatar = avatar.name(profile.name()).picture(profile.picture());
}
avatar.small()
}
}
/// The titlebar repository launcher: a static trigger and a searchable list.
pub(crate) struct RepositorySwitcher {
search: Entity<InputState>,
directory: Entity<ProfileDirectory>,
entries: Vec<RepositoryEntry>,
open: bool,
on_open: OpenHandler,
on_create: CreateHandler,
on_rescan: RescanHandler,
scroll_handle: UniformListScrollHandle,
}
impl RepositorySwitcher {
pub(super) fn new(
directory: Entity<ProfileDirectory>,
on_open: impl Fn(usize, &mut Window, &mut App) + 'static,
on_create: impl Fn(&mut Window, &mut App) + 'static,
on_rescan: impl Fn(&mut App) + 'static,
cx: &mut Context<Self>,
) -> Self {
let search = InputState::new(cx);
Self {
search,
directory,
entries: Vec::new(),
open: false,
on_open: Rc::new(on_open),
on_create: Rc::new(on_create),
on_rescan: Rc::new(on_rescan),
scroll_handle: UniformListScrollHandle::new(),
}
}
pub(super) fn set_entries(&mut self, entries: Vec<RepositoryEntry>, cx: &mut Context<Self>) {
self.entries = entries;
cx.notify();
}
pub(super) fn close(&mut self, cx: &mut Context<Self>) {
if self.open {
self.open = false;
cx.notify();
}
}
}
impl Render for RepositorySwitcher {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let theme = *cx.theme();
let weak = cx.entity().downgrade();
let entries = self.entries.clone();
let search = self.search.clone();
let directory = self.directory.clone();
let on_open = self.on_open.clone();
let on_create = self.on_create.clone();
let on_rescan = self.on_rescan.clone();
let row_weak = weak.clone();
let create_weak = weak.clone();
let rescan_weak = weak.clone();
let content_search = search.clone();
let scroll_handle = self.scroll_handle.clone();
let change_search = search.clone();
let change_weak = weak.clone();
Popover::new("repo-switcher-popover")
.open(self.open)
.on_change(move |open, window, cx| {
let search = change_search.clone();
log_dropped(change_weak.update(cx, |this, cx| {
this.open = open;
if open {
search.update(cx, |state, cx| {
state.set_value_silent("", window, cx);
});
}
cx.notify();
}));
})
.trigger(move |_window: &mut Window, _cx: &mut App| {
Button::new("repo-switcher")
.icon(Icon::named(IconRole::Folder))
.variant(ButtonVariant::Ghost)
.tooltip(Tooltip::text("Repositories"))
.accessibility_label("Repositories")
.into_any_element()
})
.content(move |window: &mut Window, cx: &mut App| {
let focus = content_search.read(cx).focus_handle();
let query = content_search.read(cx).value().to_lowercase();
window.defer(cx, move |window, cx| {
if !focus.is_focused(window) {
window.focus(&focus, cx);
}
});
let visible: Vec<RepositoryEntry> = entries
.iter()
.filter(|entry| query.is_empty() || entry.label.to_lowercase().contains(&query))
.cloned()
.collect();
let row_height = theme.sizes.medium.menu_item_height + theme.spacing.unit * 0.5;
let list_height = (row_height * visible.len() as f32).min(px(280.));
let list_entries = visible.clone();
let list_directory = directory.clone();
let list_weak = row_weak.clone();
let list_on_open = on_open.clone();
let list_scroll_handle = scroll_handle.clone();
v_flex()
.w(px(380.))
.p(theme.spacing.unit * 2.0)
.gap(theme.spacing.unit * 2.0)
.child(
Input::new("repo-switcher-search", content_search.clone())
.placeholder("Filter repositories...")
.fully_rounded(true)
.prefix(
Icon::named(IconRole::Search)
.small()
.color(theme.colors.muted_foreground),
)
.bg(theme.colors.muted)
.border_color(theme.colors.muted),
)
.map(|this| {
if visible.is_empty() {
this.child(
div()
.p_3()
.text_color(theme.colors.muted_foreground)
.text_center()
.typeset(TextRole::Callout, cx)
.child("No repositories found"),
)
} else {
this.child(
uniform_list(
"repo-switcher-list",
visible.len(),
move |range, _, cx| {
range
.filter_map(|row| {
let entry = list_entries.get(row)?;
let shortcut = repository_shortcut(entry.index);
let index = entry.index;
let weak = list_weak.clone();
let on_open = list_on_open.clone();
Some(
h_flex()
.id(("repo-switcher-entry", index))
.role(Role::MenuItem)
.w_full()
.h(row_height)
.px(theme.spacing.unit * 3.0)
.gap(theme.spacing.unit * 2.0)
.rounded(theme.radius.control)
.text_size(theme.sizes.medium.text_size)
.hover(|row| row.bg(theme.colors.muted))
.child(entry.avatar(&list_directory, cx))
.child(
div()
.flex_1()
.min_w_0()
.child(entry.label.clone()),
)
.when_some(shortcut, |row, shortcut| {
row.child(
div()
.text_color(
theme
.colors
.muted_foreground,
)
.child(shortcut),
)
})
.cursor_pointer()
.on_click(move |_, window, cx| {
log_dropped(weak.update(
cx,
|this, cx| {
this.close(cx);
},
));
on_open(index, window, cx);
}),
)
})
.collect()
},
)
.track_scroll(&list_scroll_handle)
.h(list_height)
.w_full(),
)
}
})
.child(Separator::horizontal())
.child(
Button::new("repo-switcher-create")
.variant(ButtonVariant::Ghost)
.side(ButtonSide::Left)
.full_width(true)
.icon(Icon::named(IconRole::CirclePlus))
.child(div().flex_1().child("Create Repository"))
.child(
div()
.text_color(theme.colors.muted_foreground)
.child(create_shortcut()),
)
.on_click(move |_, window, cx| {
log_dropped(create_weak.update(cx, |this, cx| {
this.close(cx);
}));
on_create(window, cx);
}),
)
.child(Separator::horizontal())
.child(
Button::new("repo-switcher-rescan")
.variant(ButtonVariant::Ghost)
.side(ButtonSide::Left)
.full_width(true)
.icon(Icon::named(IconRole::Refresh))
.label("Rescan Repositories")
.on_click(move |_, _, cx| {
log_dropped(rescan_weak.update(cx, |this, cx| {
this.close(cx);
}));
on_rescan(cx);
}),
)
.into_any_element()
})
}
}
/// The shortcut hint for a repository row, matching its key binding.
fn repository_shortcut(index: usize) -> Option<SharedString> {
(index < 9).then(|| {
let label = if cfg!(target_os = "macos") {
format!("⌘{}", index + 1)
} else {
format!("Ctrl+{}", index + 1)
};
SharedString::from(label)
})
}
fn create_shortcut() -> SharedString {
if cfg!(target_os = "macos") {
SharedString::from("⌘N")
} else {
SharedString::from("Ctrl+N")
}
}
+9
View File
@@ -14,6 +14,7 @@ use crate::shared::log_dropped;
#[derive(Default)] #[derive(Default)]
pub struct Workspace { pub struct Workspace {
main: Option<SharedString>, main: Option<SharedString>,
main_order: Vec<SharedString>,
main_views: HashMap<SharedString, Arc<dyn PanelView>>, main_views: HashMap<SharedString, Arc<dyn PanelView>>,
details: Vec<(SharedString, SharedString)>, details: Vec<(SharedString, SharedString)>,
detail_views: HashMap<SharedString, Arc<dyn PanelView>>, detail_views: HashMap<SharedString, Arc<dyn PanelView>>,
@@ -36,6 +37,10 @@ impl Workspace {
self.main.as_ref() self.main.as_ref()
} }
pub fn open_mains(&self) -> &[SharedString] {
&self.main_order
}
pub fn active_detail(&self) -> Option<Arc<dyn PanelView>> { pub fn active_detail(&self) -> Option<Arc<dyn PanelView>> {
self.active_detail self.active_detail
.as_ref() .as_ref()
@@ -64,6 +69,9 @@ impl Workspace {
if self.main.as_ref() != Some(&id) { if self.main.as_ref() != Some(&id) {
self.clear_details(); self.clear_details();
} }
if !self.main_views.contains_key(&id) {
self.main_order.push(id.clone());
}
self.main_views.insert(id.clone(), view); self.main_views.insert(id.clone(), view);
self.main = Some(id); self.main = Some(id);
cx.notify(); cx.notify();
@@ -109,6 +117,7 @@ impl Workspace {
pub fn clear(&mut self, cx: &mut Context<Self>) { pub fn clear(&mut self, cx: &mut Context<Self>) {
self.main = None; self.main = None;
self.main_order.clear();
self.main_views.clear(); self.main_views.clear();
self.clear_details(); self.clear_details();
cx.notify(); cx.notify();
+10
View File
@@ -74,6 +74,7 @@ pub struct Button {
loading: bool, loading: bool,
padded: bool, padded: bool,
fully_rounded: bool, fully_rounded: bool,
full_width: bool,
side: ButtonSide, side: ButtonSide,
tab_stop: bool, tab_stop: bool,
debug_selector: Option<Rc<dyn Fn() -> String>>, debug_selector: Option<Rc<dyn Fn() -> String>>,
@@ -101,6 +102,7 @@ impl Button {
loading: false, loading: false,
padded: true, padded: true,
fully_rounded: false, fully_rounded: false,
full_width: false,
side: ButtonSide::default(), side: ButtonSide::default(),
tab_stop: true, tab_stop: true,
debug_selector: None, debug_selector: None,
@@ -190,6 +192,12 @@ impl Button {
self self
} }
/// Stretches the button and its content across the available width.
pub fn full_width(mut self, full_width: bool) -> Self {
self.full_width = full_width;
self
}
/// Sets the edge the content aligns to, `Right` renders the icon after the label. /// Sets the edge the content aligns to, `Right` renders the icon after the label.
pub fn side(mut self, side: ButtonSide) -> Self { pub fn side(mut self, side: ButtonSide) -> Self {
self.side = side; self.side = side;
@@ -313,6 +321,7 @@ impl RenderOnce for Button {
}) })
.h(metrics.control_height) .h(metrics.control_height)
.when(is_icon_only, |button| button.w(metrics.control_height)) .when(is_icon_only, |button| button.w(metrics.control_height))
.when(self.full_width, |button| button.w_full())
.when(!is_icon_only && self.padded, |button| { .when(!is_icon_only && self.padded, |button| {
button.px(metrics.padding_x) button.px(metrics.padding_x)
}) })
@@ -328,6 +337,7 @@ impl RenderOnce for Button {
.child( .child(
h_flex() h_flex()
.gap_2() .gap_2()
.when(self.full_width, |content| content.flex_1())
.when(self.loading, |content| content.invisible()) .when(self.loading, |content| content.invisible())
.map(|content| { .map(|content| {
if icon_trailing { if icon_trailing {
+21 -10
View File
@@ -23,13 +23,15 @@
//! } //! }
//! ``` //! ```
use std::rc::Rc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
App, Bounds, ClipboardItem, Context, ElementId, HighlightStyle, Hsla, InteractiveElement as _, App, Bounds, ClipboardItem, Context, ElementId, HighlightStyle, Hsla, InteractiveElement as _,
IntoElement, KeyBinding, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, IntoElement, KeyBinding, KeyBindingContextPredicate, MouseButton, MouseDownEvent,
ParentElement as _, Pixels, Point, Render, ScrollStrategy, SharedString, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, Point, Render, ScrollStrategy,
StatefulInteractiveElement as _, Styled as _, TextStyle, UniformListScrollHandle, Window, SharedString, StatefulInteractiveElement as _, Styled as _, TextStyle, UniformListScrollHandle,
actions, canvas, div, uniform_list, Window, actions, canvas, div, uniform_list,
}; };
use crate::components::highlight::{HighlightedCode, Language, Role, highlight}; use crate::components::highlight::{HighlightedCode, Language, Role, highlight};
@@ -49,12 +51,21 @@ pub const CODE_VIEW_CONTEXT: &str = "CodeView";
/// ///
/// Call once at startup. Without it, selection copy has no key. /// Call once at startup. Without it, selection copy has no key.
pub fn bind_code_view_keys(cx: &mut App) { pub fn bind_code_view_keys(cx: &mut App) {
let context = Some(CODE_VIEW_CONTEXT); let context = match KeyBindingContextPredicate::parse(CODE_VIEW_CONTEXT) {
#[cfg(target_os = "macos")] Ok(context) => Some(Rc::new(context)),
let copy = "cmd-c"; Err(error) => {
#[cfg(not(target_os = "macos"))] log::error!("failed to parse code view key context: {error}");
let copy = "ctrl-c"; return;
cx.bind_keys([KeyBinding::new(copy, Copy, context)]); }
};
let binding = match KeyBinding::load("secondary-c", Box::new(Copy), context, false, None, cx) {
Ok(binding) => binding,
Err(error) => {
log::error!("failed to parse code view copy keystroke: {error}");
return;
}
};
cx.bind_keys([binding]);
} }
/// A point in the source, in lines and characters (not bytes). /// A point in the source, in lines and characters (not bytes).
+14 -3
View File
@@ -1907,6 +1907,7 @@ pub struct Input {
disabled: bool, disabled: bool,
/// The placeholder stays visible while focused. /// The placeholder stays visible while focused.
placeholder_when_focused: bool, placeholder_when_focused: bool,
fully_rounded: bool,
a11y_label: Option<SharedString>, a11y_label: Option<SharedString>,
/// Multiline field height in row, ignored when the state is single-line. /// Multiline field height in row, ignored when the state is single-line.
rows: usize, rows: usize,
@@ -1928,6 +1929,7 @@ impl Input {
size: Size::default(), size: Size::default(),
disabled: false, disabled: false,
placeholder_when_focused: false, placeholder_when_focused: false,
fully_rounded: false,
a11y_label: None, a11y_label: None,
rows: DEFAULT_ROWS, rows: DEFAULT_ROWS,
prefix: None, prefix: None,
@@ -1957,8 +1959,13 @@ impl Input {
self self
} }
/// Renders the field inert, unfocusable, and dimmed, regardless of the /// Renders the field as a pill instead of the control radius.
/// state's read-only setting. pub fn fully_rounded(mut self, fully_rounded: bool) -> Self {
self.fully_rounded = fully_rounded;
self
}
/// Renders the field inert, unfocusable, and dimmed.
pub fn disabled(mut self, disabled: bool) -> Self { pub fn disabled(mut self, disabled: bool) -> Self {
self.disabled = disabled; self.disabled = disabled;
self self
@@ -2179,7 +2186,11 @@ impl RenderOnce for Input {
metrics.dense_padding_x metrics.dense_padding_x
}) })
.gap_2() .gap_2()
.rounded(radius.control) .rounded(if self.fully_rounded {
radius.full
} else {
radius.control
})
.bg(colors.input) .bg(colors.input)
.text_size(metrics.text_size) .text_size(metrics.text_size)
.text_color(colors.foreground) .text_color(colors.foreground)
+21 -11
View File
@@ -28,17 +28,18 @@ use std::borrow::Borrow as _;
use std::collections::HashMap; use std::collections::HashMap;
use std::hash::{DefaultHasher, Hash, Hasher}; use std::hash::{DefaultHasher, Hash, Hasher};
use std::ops::Range; use std::ops::Range;
use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AnyElement, App, Bounds, ClipboardItem, Context, Div, Element, ElementId, Entity, FontStyle, AnyElement, App, Bounds, ClipboardItem, Context, Div, Element, ElementId, Entity, FontStyle,
GlobalElementId, HighlightStyle, InspectorElementId, InteractiveElement as _, InteractiveText, GlobalElementId, HighlightStyle, InspectorElementId, InteractiveElement as _, InteractiveText,
IntoElement, KeyBinding, LayoutId, ListAlignment, ListOffset, ListState, MouseButton, IntoElement, KeyBinding, KeyBindingContextPredicate, LayoutId, ListAlignment, ListOffset,
MouseDownEvent, MouseMoveEvent, ObjectFit, ParentElement as _, Pixels, Refineable as _, Render, ListState, MouseButton, MouseDownEvent, MouseMoveEvent, ObjectFit, ParentElement as _, Pixels,
SharedString, StatefulInteractiveElement as _, StrikethroughStyle, StyleRefinement, Styled, Refineable as _, Render, SharedString, StatefulInteractiveElement as _, StrikethroughStyle,
StyledImage as _, StyledText, TextLayout, UnderlineStyle, Window, actions, div, img, list, px, StyleRefinement, Styled, StyledImage as _, StyledText, TextLayout, UnderlineStyle, Window,
relative, actions, div, img, list, px, relative,
}; };
use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, TagEnd}; use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, TagEnd};
@@ -848,12 +849,21 @@ impl InlineBuilder {
/// ///
/// Call once at startup. Without it, selection copy has no key. /// Call once at startup. Without it, selection copy has no key.
pub fn bind_text_view_keys(cx: &mut App) { pub fn bind_text_view_keys(cx: &mut App) {
let context = Some(TEXT_VIEW_CONTEXT); let context = match KeyBindingContextPredicate::parse(TEXT_VIEW_CONTEXT) {
#[cfg(target_os = "macos")] Ok(context) => Some(Rc::new(context)),
let copy = "cmd-c"; Err(error) => {
#[cfg(not(target_os = "macos"))] log::error!("failed to parse text view key context: {error}");
let copy = "ctrl-c"; return;
cx.bind_keys([KeyBinding::new(copy, Copy, context)]); }
};
let binding = match KeyBinding::load("secondary-c", Box::new(Copy), context, false, None, cx) {
Ok(binding) => binding,
Err(error) => {
log::error!("failed to parse text view copy keystroke: {error}");
return;
}
};
cx.bind_keys([binding]);
} }
/// The view's base container: selection wiring, focus, and copy. /// The view's base container: selection wiring, focus, and copy.
+4 -13
View File
@@ -24,6 +24,7 @@ use gpui::{
StyleRefinement, Styled as _, Window, div, StyleRefinement, Styled as _, Window, div,
}; };
use crate::common::v_flex;
use crate::components::common::{ use crate::components::common::{
StyledExt as _, nav_key, paint_selectable_row, selectable_label_color, StyledExt as _, nav_key, paint_selectable_row, selectable_label_color,
}; };
@@ -202,8 +203,7 @@ impl Sidebar {
self.transparent self.transparent
} }
/// Textures the material with a film-grain overlay; it renders only while /// Textures the sidebar with a film-grain overlay.
/// the sidebar paints one.
pub fn grain(mut self, grain: bool) -> Self { pub fn grain(mut self, grain: bool) -> Self {
self.grain = grain; self.grain = grain;
self self
@@ -390,22 +390,13 @@ impl RenderOnce for Sidebar {
let theme = cx.theme(); let theme = cx.theme();
div() v_flex()
.id(id.clone()) .id(id.clone())
.refine_style(&style)
.debug_selector(move || format!("sidebar-{debug_id}")) .debug_selector(move || format!("sidebar-{debug_id}"))
.h_full() .h_full()
.w(width) .w(width)
.flex()
.flex_col()
.map(|sidebar| {
if material {
sidebar.bg(theme.material.background)
} else {
sidebar.bg(theme.colors.sidebar)
}
})
.text_size(theme.sizes.medium.text_size) .text_size(theme.sizes.medium.text_size)
.refine_style(&style)
.when(border_right, |sidebar| { .when(border_right, |sidebar| {
sidebar sidebar
.border_r(BORDER_WIDTH) .border_r(BORDER_WIDTH)
-4
View File
@@ -23,8 +23,6 @@ pub struct ColorTokens {
pub foreground: Hsla, pub foreground: Hsla,
pub surface: Hsla, pub surface: Hsla,
pub surface_foreground: Hsla, pub surface_foreground: Hsla,
/// The docked sidebar's backdrop.
pub sidebar: Hsla,
pub primary: Hsla, pub primary: Hsla,
pub primary_foreground: Hsla, pub primary_foreground: Hsla,
pub secondary: Hsla, pub secondary: Hsla,
@@ -60,7 +58,6 @@ impl ColorTokens {
foreground: hex(0x18181b), foreground: hex(0x18181b),
surface: hex(0xfafafa), surface: hex(0xfafafa),
surface_foreground: hex(0x18181b), surface_foreground: hex(0x18181b),
sidebar: hex(0xf4f4f5),
primary: hex(0x2563eb), primary: hex(0x2563eb),
primary_foreground: hex(0xffffff), primary_foreground: hex(0xffffff),
secondary: hex(0xf4f4f5), secondary: hex(0xf4f4f5),
@@ -95,7 +92,6 @@ impl ColorTokens {
foreground: hex(0xfafafa), foreground: hex(0xfafafa),
surface: hex(0x18181b), surface: hex(0x18181b),
surface_foreground: hex(0xfafafa), surface_foreground: hex(0xfafafa),
sidebar: hex(0x18181b),
primary: hex(0x3b82f6), primary: hex(0x3b82f6),
primary_foreground: hex(0xffffff), primary_foreground: hex(0xffffff),
secondary: hex(0x27272a), secondary: hex(0x27272a),
-5
View File
@@ -19,7 +19,6 @@ pub struct ThemeDefinition {
foreground: Option<String>, foreground: Option<String>,
surface: Option<String>, surface: Option<String>,
surface_foreground: Option<String>, surface_foreground: Option<String>,
sidebar: Option<String>,
primary: Option<String>, primary: Option<String>,
primary_foreground: Option<String>, primary_foreground: Option<String>,
secondary: Option<String>, secondary: Option<String>,
@@ -88,10 +87,6 @@ impl ThemeDefinition {
self.color(&self.surface_foreground, "surface_foreground") self.color(&self.surface_foreground, "surface_foreground")
} }
pub fn sidebar(&self) -> Option<Hsla> {
self.color(&self.sidebar, "sidebar")
}
pub fn primary(&self) -> Option<Hsla> { pub fn primary(&self) -> Option<Hsla> {
self.color(&self.primary, "primary") self.color(&self.primary, "primary")
} }
-1
View File
@@ -82,7 +82,6 @@ pub(crate) fn resolve(
surface: def_color(|d| d.surface()).unwrap_or(base.surface), surface: def_color(|d| d.surface()).unwrap_or(base.surface),
surface_foreground: def_color(|d| d.surface_foreground()) surface_foreground: def_color(|d| d.surface_foreground())
.unwrap_or(base.surface_foreground), .unwrap_or(base.surface_foreground),
sidebar: def_color(|d| d.sidebar()).unwrap_or(base.sidebar),
primary, primary,
primary_foreground: def_color(|d| d.primary_foreground()) primary_foreground: def_color(|d| d.primary_foreground())
.unwrap_or_else(|| contrast_foreground(primary)), .unwrap_or_else(|| contrast_foreground(primary)),