fix: panel is not focus

This commit is contained in:
2025-02-06 09:11:44 +07:00
parent a941e844b9
commit 193aaa646e
6 changed files with 21 additions and 60 deletions

View File

@@ -33,13 +33,8 @@ smallvec = "1.13.2"
rust-embed = "8.5.0" rust-embed = "8.5.0"
[profile.release] [profile.release]
codegen-units = 1
lto = true
panic = "abort"
incremental = false
opt-level = "z"
strip = true strip = true
rpath = false opt-level = "z"
debug = false lto = true
debug-assertions = false codegen-units = 1
overflow-checks = false panic = "abort"

View File

@@ -20,7 +20,7 @@ use state::{get_client, initialize_client};
use std::{borrow::Cow, collections::HashSet, ops::Deref, str::FromStr, sync::Arc, time::Duration}; use std::{borrow::Cow, collections::HashSet, ops::Deref, str::FromStr, sync::Arc, time::Duration};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use ui::{theme::Theme, Root}; use ui::{theme::Theme, Root};
use views::{app::AppView, onboarding, startup::Startup}; use views::{app, onboarding, startup::Startup};
mod asset; mod asset;
mod views; mod views;
@@ -311,8 +311,7 @@ fn main() {
if let Some(root) = this.root() { if let Some(root) = this.root() {
cx.update_entity(&root, |this: &mut Root, cx| { cx.update_entity(&root, |this: &mut Root, cx| {
this.set_view( this.set_view(
cx.new(|cx| AppView::new(profile, window, cx)) app::init(profile, window, cx).into(),
.into(),
cx, cx,
); );
}); });

View File

@@ -2,7 +2,7 @@ use app_state::registry::AppRegistry;
use chat_state::registry::ChatRegistry; use chat_state::registry::ChatRegistry;
use common::profile::NostrProfile; use common::profile::NostrProfile;
use gpui::{ use gpui::{
actions, div, img, impl_internal_actions, px, AppContext, Axis, BorrowAppContext, Context, actions, div, img, impl_internal_actions, px, App, AppContext, Axis, BorrowAppContext, Context,
Entity, InteractiveElement, IntoElement, ObjectFit, ParentElement, Render, Styled, StyledImage, Entity, InteractiveElement, IntoElement, ObjectFit, ParentElement, Render, Styled, StyledImage,
Window, Window,
}; };
@@ -44,24 +44,18 @@ impl_internal_actions!(dock, [AddPanel]);
// Account actions // Account actions
actions!(account, [OpenProfile, OpenContacts, OpenSettings, Logout]); actions!(account, [OpenProfile, OpenContacts, OpenSettings, Logout]);
pub struct DockAreaTab { pub fn init(account: NostrProfile, window: &mut Window, cx: &mut App) -> Entity<AppView> {
id: &'static str, AppView::new(account, window, cx)
version: usize,
} }
pub const DOCK_AREA: DockAreaTab = DockAreaTab {
id: "dock",
version: 1,
};
pub struct AppView { pub struct AppView {
account: NostrProfile, account: NostrProfile,
dock: Entity<DockArea>, dock: Entity<DockArea>,
} }
impl AppView { impl AppView {
pub fn new(account: NostrProfile, window: &mut Window, cx: &mut Context<'_, Self>) -> AppView { pub fn new(account: NostrProfile, window: &mut Window, cx: &mut App) -> Entity<Self> {
let dock = cx.new(|cx| DockArea::new(DOCK_AREA.id, Some(DOCK_AREA.version), window, cx)); let dock = cx.new(|cx| DockArea::new(window, cx));
let weak_dock = dock.downgrade(); let weak_dock = dock.downgrade();
let left_panel = DockItem::panel(Arc::new(sidebar::init(window, cx))); let left_panel = DockItem::panel(Arc::new(sidebar::init(window, cx)));
let center_panel = DockItem::split_with_sizes( let center_panel = DockItem::split_with_sizes(
@@ -79,13 +73,13 @@ impl AppView {
cx, cx,
); );
// Set default dock layout
_ = weak_dock.update(cx, |view, cx| { _ = weak_dock.update(cx, |view, cx| {
view.set_version(DOCK_AREA.version, window, cx);
view.set_left_dock(left_panel, Some(px(240.)), true, window, cx); view.set_left_dock(left_panel, Some(px(240.)), true, window, cx);
view.set_center(center_panel, window, cx); view.set_center(center_panel, window, cx);
}); });
AppView { account, dock } cx.new(|_| Self { account, dock })
} }
fn render_account(&self) -> impl IntoElement { fn render_account(&self) -> impl IntoElement {

View File

@@ -16,7 +16,7 @@ use ui::{
ContextModal, Root, Size, StyledExt, ContextModal, Root, Size, StyledExt,
}; };
use super::app::AppView; use super::app;
const ALPHA_MESSAGE: &str = "Coop is in the alpha stage; it does not store any credentials. You will need to log in again when you reopen the app."; const ALPHA_MESSAGE: &str = "Coop is in the alpha stage; it does not store any credentials. You will need to log in again when you reopen the app.";
const JOIN_URL: &str = "https://start.njump.me/"; const JOIN_URL: &str = "https://start.njump.me/";
@@ -61,10 +61,12 @@ impl Onboarding {
}) })
} }
/*
fn use_connect(&mut self, _window: &mut Window, cx: &mut Context<Self>) { fn use_connect(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
self.use_connect = true; self.use_connect = true;
cx.notify(); cx.notify();
} }
*/
fn use_privkey(&mut self, _window: &mut Window, cx: &mut Context<Self>) { fn use_privkey(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
self.use_privkey = true; self.use_privkey = true;
@@ -127,10 +129,7 @@ impl Onboarding {
if let Some(root) = this.root() { if let Some(root) = this.root() {
cx.update_entity(&root, |this: &mut Root, cx| { cx.update_entity(&root, |this: &mut Root, cx| {
this.set_view( this.set_view(app::init(profile, window, cx).into(), cx);
cx.new(|cx| AppView::new(profile, window, cx)).into(),
cx,
);
}); });
} }
}); });

View File

@@ -7,7 +7,7 @@ use crate::dock_area::{
use gpui::{ use gpui::{
actions, canvas, div, prelude::FluentBuilder, px, AnyElement, AnyView, App, AppContext, Axis, actions, canvas, div, prelude::FluentBuilder, px, AnyElement, AnyView, App, AppContext, Axis,
Bounds, Context, Edges, Entity, EntityId, EventEmitter, InteractiveElement as _, IntoElement, Bounds, Context, Edges, Entity, EntityId, EventEmitter, InteractiveElement as _, IntoElement,
ParentElement as _, Pixels, Render, SharedString, Styled, Subscription, WeakEntity, Window, ParentElement as _, Pixels, Render, Styled, Subscription, WeakEntity, Window,
}; };
use std::sync::Arc; use std::sync::Arc;
@@ -28,17 +28,11 @@ pub enum DockEvent {
/// The main area of the dock. /// The main area of the dock.
pub struct DockArea { pub struct DockArea {
id: SharedString,
/// The version is used to special the default layout, this is like the `panel_version` in [`Panel`](Panel).
version: Option<usize>,
pub(crate) bounds: Bounds<Pixels>, pub(crate) bounds: Bounds<Pixels>,
/// The center view of the dockarea. /// The center view of the dockarea.
items: DockItem, items: DockItem,
/// The entity_id of the [`TabPanel`](TabPanel) where each toggle button should be displayed, /// The entity_id of the [`TabPanel`](TabPanel) where each toggle button should be displayed,
toggle_button_panels: Edges<Option<EntityId>>, toggle_button_panels: Edges<Option<EntityId>>,
/// The left dock of the dock_area. /// The left dock of the dock_area.
left_dock: Option<Entity<Dock>>, left_dock: Option<Entity<Dock>>,
/// The bottom dock of the dock_area. /// The bottom dock of the dock_area.
@@ -47,13 +41,10 @@ pub struct DockArea {
right_dock: Option<Entity<Dock>>, right_dock: Option<Entity<Dock>>,
/// The top zoom view of the dock_area, if any. /// The top zoom view of the dock_area, if any.
zoom_view: Option<AnyView>, zoom_view: Option<AnyView>,
/// Lock panels layout, but allow to resize. /// Lock panels layout, but allow to resize.
is_locked: bool, is_locked: bool,
/// The panel style, default is [`PanelStyle::Default`](PanelStyle::Default). /// The panel style, default is [`PanelStyle::Default`](PanelStyle::Default).
pub(crate) panel_style: PanelStyle, pub(crate) panel_style: PanelStyle,
subscriptions: Vec<Subscription>, subscriptions: Vec<Subscription>,
} }
@@ -289,12 +280,7 @@ impl DockItem {
} }
impl DockArea { impl DockArea {
pub fn new( pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
id: impl Into<SharedString>,
version: Option<usize>,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let stack_panel = cx.new(|cx| StackPanel::new(Axis::Horizontal, window, cx)); let stack_panel = cx.new(|cx| StackPanel::new(Axis::Horizontal, window, cx));
let dock_item = DockItem::Split { let dock_item = DockItem::Split {
@@ -305,8 +291,6 @@ impl DockArea {
}; };
let mut this = Self { let mut this = Self {
id: id.into(),
version,
bounds: Bounds::default(), bounds: Bounds::default(),
items: dock_item, items: dock_item,
zoom_view: None, zoom_view: None,
@@ -330,12 +314,6 @@ impl DockArea {
self self
} }
/// Set version of the dock area.
pub fn set_version(&mut self, version: usize, _window: &mut Window, cx: &mut Context<Self>) {
self.version = Some(version);
cx.notify();
}
/// The DockItem as the center of the dock area. /// The DockItem as the center of the dock area.
/// ///
/// This is used to render at the Center of the DockArea. /// This is used to render at the Center of the DockArea.
@@ -661,11 +639,6 @@ impl DockArea {
self.subscriptions.push(subscription); self.subscriptions.push(subscription);
} }
/// Returns the ID of the dock area.
pub fn id(&self) -> SharedString {
self.id.clone()
}
pub fn set_zoomed_in<P: Panel>( pub fn set_zoomed_in<P: Panel>(
&mut self, &mut self,
panel: Entity<P>, panel: Entity<P>,

View File

@@ -171,6 +171,7 @@ impl TabPanel {
fn set_active_ix(&mut self, ix: usize, window: &mut Window, cx: &mut Context<Self>) { fn set_active_ix(&mut self, ix: usize, window: &mut Window, cx: &mut Context<Self>) {
if ix == self.active_ix { if ix == self.active_ix {
self.focus_active_panel(window, cx);
return; return;
} }
@@ -1021,7 +1022,7 @@ impl TabPanel {
fn focus_active_panel(&self, window: &mut Window, cx: &mut Context<Self>) { fn focus_active_panel(&self, window: &mut Window, cx: &mut Context<Self>) {
if let Some(active_panel) = self.active_panel(cx) { if let Some(active_panel) = self.active_panel(cx) {
active_panel.focus_handle(cx).focus(window); window.focus(&active_panel.focus_handle(cx));
} }
} }