@@ -11,6 +11,7 @@ use crate::tauri_bridge::{
1111} ;
1212use crate :: workbench:: chat_markdown:: render_markdown_to_html;
1313use crate :: workbench:: { RightPanelTab , WorkbenchService } ;
14+ use gloo_timers:: future:: TimeoutFuture ;
1415use js_sys:: Date ;
1516use leptos:: prelude:: * ;
1617use leptos:: task:: spawn_local;
@@ -232,6 +233,30 @@ fn grouped_plans(plans: &[PlanMeta]) -> Vec<PlanGroup> {
232233 . collect ( )
233234}
234235
236+ fn open_plan_composer (
237+ composer_open : RwSignal < bool > ,
238+ draft_error : RwSignal < Option < String > > ,
239+ ) {
240+ composer_open. set ( true ) ;
241+ draft_error. set ( None ) ;
242+ spawn_local ( async move {
243+ TimeoutFuture :: new ( 0 ) . await ;
244+ scroll_plans_body_to_top ( ) ;
245+ } ) ;
246+ }
247+
248+ fn scroll_plans_body_to_top ( ) {
249+ let Some ( document) = web_sys:: window ( ) . and_then ( |window| window. document ( ) ) else {
250+ return ;
251+ } ;
252+ let Ok ( Some ( node) ) = document. query_selector ( ".blx-plans-pane .blx-sr-pane__body" ) else {
253+ return ;
254+ } ;
255+ if let Ok ( el) = node. dyn_into :: < web_sys:: HtmlElement > ( ) {
256+ el. set_scroll_top ( 0 ) ;
257+ }
258+ }
259+
235260#[ component]
236261pub fn PlansPanel ( ) -> impl IntoView {
237262 let wb = expect_context :: < WorkbenchService > ( ) ;
@@ -336,8 +361,7 @@ pub fn PlansPanel() -> impl IntoView {
336361 aria-label=move || i18n. tr( I18nKey :: PlansNewPlan ) ( )
337362 title=move || i18n. tr( I18nKey :: PlansNewPlan ) ( )
338363 on: click=move |_| {
339- composer_open. set( true ) ;
340- draft_error. set( None ) ;
364+ open_plan_composer( composer_open, draft_error) ;
341365 }
342366 >
343367 <LxIcon icon=icondata:: LuPlus width="13px" height="13px" />
@@ -471,7 +495,7 @@ pub fn PlansPanel() -> impl IntoView {
471495 <button
472496 type ="button"
473497 class="blx-sr-btn blx-sr-btn--primary"
474- on: click=move |_| composer_open . set ( true )
498+ on: click=move |_| open_plan_composer ( composer_open , draft_error )
475499 >
476500 <LxIcon icon=icondata:: LuPlus width="13px" height="13px" />
477501 <span>{ i18n. tr( I18nKey :: PlansNewPlan ) } </span>
0 commit comments