@@ -3292,19 +3292,21 @@ impl Screen<'_> {
32923292 }
32933293
32943294 let current_grid = self . context_manager . current_grid ( ) ;
3295- let ( context, margin) = current_grid. current_context_with_computed_dimension ( ) ;
3296- let layout = context. dimension ;
3297- let terminal = context. terminal . lock ( ) ;
3295+ let scaled_margin = current_grid. get_scaled_margin ( ) ;
3296+
3297+ let Some ( current_item) = current_grid. current_item ( ) else {
3298+ return ;
3299+ } ;
3300+
3301+ let layout = current_item. val . dimension ;
3302+ let terminal = current_item. val . terminal . lock ( ) ;
32983303 let cursor_pos = terminal. grid . cursor . pos ;
32993304 drop ( terminal) ;
33003305
33013306 // Calculate pixel position of cursor
33023307 let cell_width = layout. dimension . width ;
33033308 let line_height = self . sugarloaf . style ( ) . line_height ;
33043309 let cell_height = layout. dimension . height * line_height;
3305- // Margin from current_context_with_computed_dimension is already pre-scaled
3306- let margin_x = margin. left ;
3307- let margin_y = margin. top ;
33083310
33093311 // Validate dimensions before calculation
33103312 if cell_width <= 0.0 || cell_height <= 0.0 {
@@ -3316,10 +3318,16 @@ impl Screen<'_> {
33163318 return ;
33173319 }
33183320
3319- // Convert grid position to pixel position, centering horizontally in the cell
3321+ // Panel origin: layout_rect is relative to root container,
3322+ // add scaled_margin to get absolute screen position
3323+ let panel_rect = current_item. layout_rect ( ) ;
3324+ let origin_x = panel_rect[ 0 ] + scaled_margin. left ;
3325+ let origin_y = panel_rect[ 1 ] + scaled_margin. top ;
3326+
3327+ // Convert grid position to pixel position
33203328 let pixel_x =
3321- margin_x + ( cursor_pos. col . 0 as f32 * cell_width) + ( cell_width * 0.5 ) ;
3322- let pixel_y = margin_y + ( cursor_pos. row . 0 as f32 * cell_height) ;
3329+ origin_x + ( cursor_pos. col . 0 as f32 * cell_width) + ( cell_width * 0.5 ) ;
3330+ let pixel_y = origin_y + ( cursor_pos. row . 0 as f32 * cell_height) ;
33233331
33243332 // Validate final coordinates
33253333 if pixel_x. is_nan ( ) || pixel_y. is_nan ( ) || pixel_x < 0.0 || pixel_y < 0.0 {
0 commit comments