@@ -3,19 +3,19 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();
3
3
4
4
import * as arena from 'arena' ;
5
5
import * as Ecs from 'ecs' ;
6
+ import * as Fork from 'fork' ;
7
+ import * as geom from 'geom' ;
6
8
import * as Lib from 'lib' ;
7
9
import * as log from 'log' ;
8
10
import * as movement from 'movement' ;
9
- import * as Rect from 'rectangle' ;
10
11
import * as Node from 'node' ;
11
- import * as Fork from 'fork' ;
12
- import * as geom from 'geom' ;
12
+ import * as Rect from 'rectangle' ;
13
13
14
14
import type { Entity } from 'ecs' ;
15
- import type { Rectangle } from './rectangle' ;
16
- import type { ShellWindow } from './window' ;
17
15
import type { Ext } from './extension' ;
16
+ import type { Rectangle } from './rectangle' ;
18
17
import { Stack } from './stack' ;
18
+ import type { ShellWindow } from './window' ;
19
19
20
20
const { Arena } = arena ;
21
21
const { Meta } = imports . gi ;
@@ -350,7 +350,7 @@ export class Forest extends Ecs.World {
350
350
}
351
351
352
352
/** Detaches an entity from the a fork, re-arranging the fork's tree as necessary */
353
- detach ( ext : Ext , fork_entity : Entity , window : Entity ) : [ Entity , Fork . Fork ] | null {
353
+ detach ( ext : Ext , fork_entity : Entity , window : Entity , destroy_stack : boolean = false ) : [ Entity , Fork . Fork ] | null {
354
354
const fork = this . forks . get ( fork_entity ) ;
355
355
if ( ! fork ) return null ;
356
356
@@ -387,8 +387,11 @@ export class Forest extends Ecs.World {
387
387
ext ,
388
388
fork . left . inner as Node . NodeStack ,
389
389
window ,
390
- ( ) => {
391
- if ( fork . right ) {
390
+ destroy_stack ,
391
+ ( window : undefined | Entity ) => {
392
+ if ( window )
393
+ fork . left = Node . Node . window ( window ) ;
394
+ else if ( fork . right ) {
392
395
fork . left = fork . right
393
396
fork . right = null
394
397
if ( parent ) {
@@ -428,9 +431,14 @@ export class Forest extends Ecs.World {
428
431
ext ,
429
432
fork . right . inner as Node . NodeStack ,
430
433
window ,
431
- ( ) => {
432
- fork . right = null
434
+ destroy_stack ,
435
+ ( window ) => {
436
+ if ( window )
437
+ fork . right = Node . Node . window ( window ) ;
438
+ else {
439
+ fork . right = null ;
433
440
this . reassign_to_parent ( fork , fork . left )
441
+ }
434
442
} ,
435
443
) ;
436
444
}
@@ -714,7 +722,7 @@ export class Forest extends Ecs.World {
714
722
}
715
723
716
724
/** Removes window from stack, destroying the stack if it was the last window. */
717
- private remove_from_stack ( ext : Ext , stack : Node . NodeStack , window : Entity , on_last : ( ) => void ) {
725
+ private remove_from_stack ( ext : Ext , stack : Node . NodeStack , window : Entity , destroy_stack : boolean , on_last : ( win ?: Entity ) => void ) {
718
726
if ( stack . entities . length === 1 ) {
719
727
this . stacks . remove ( stack . idx ) ?. destroy ( ) ;
720
728
on_last ( ) ;
@@ -723,6 +731,10 @@ export class Forest extends Ecs.World {
723
731
if ( s ) {
724
732
Node . stack_remove ( this , stack , window )
725
733
}
734
+ if ( destroy_stack && stack . entities . length === 1 ) {
735
+ on_last ( stack . entities [ 0 ] )
736
+ this . stacks . remove ( stack . idx ) ?. destroy ( )
737
+ }
726
738
}
727
739
728
740
const win = ext . windows . get ( window ) ;
0 commit comments