@@ -1028,9 +1028,13 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
1028
1028
}
1029
1029
1030
1030
changeWorkspaceIcon ( ) {
1031
- const anchor = this . activeWorkspaceIndicator ?. querySelector (
1031
+ let anchor = this . activeWorkspaceIndicator ?. querySelector (
1032
1032
'.zen-current-workspace-indicator-icon'
1033
1033
) ;
1034
+ if ( this . #contextMenuData?. workspaceId ) {
1035
+ anchor = this . #contextMenuData. originalTarget ;
1036
+ }
1037
+ const workspaceId = this . #contextMenuData?. workspaceId || this . activeWorkspace ;
1034
1038
if ( ! anchor ) {
1035
1039
return ;
1036
1040
}
@@ -1042,7 +1046,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
1042
1046
gZenEmojiPicker
1043
1047
. open ( anchor )
1044
1048
. then ( async ( emoji ) => {
1045
- const workspace = this . getActiveWorkspaceFromCache ( ) ;
1049
+ const workspace = this . getWorkspaceFromId ( workspaceId ) ;
1046
1050
if ( ! workspace ) {
1047
1051
console . warn ( 'No active workspace found to change icon' ) ;
1048
1052
return ;
@@ -1129,6 +1133,11 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
1129
1133
addPopupListeners ( ) {
1130
1134
const workspaceActions = document . getElementById ( 'zenWorkspaceMoreActions' ) ;
1131
1135
workspaceActions . addEventListener ( 'popupshowing' , this . updateWorkspaceActionsMenu . bind ( this ) ) ;
1136
+ workspaceActions . addEventListener ( 'popuphidden' , ( ) => {
1137
+ setTimeout ( ( ) => {
1138
+ this . #contextMenuData = null ;
1139
+ } , 0 ) ; // Delay to ensure the context menu data is cleared after the popup is hidden
1140
+ } ) ;
1132
1141
1133
1142
const contextChangeContainerTabMenu = document . getElementById (
1134
1143
'context_zenWorkspacesOpenInContainerTab'
@@ -1143,6 +1152,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
1143
1152
) ;
1144
1153
}
1145
1154
1155
+ #contextMenuData = null ;
1146
1156
updateWorkspaceActionsMenu ( event ) {
1147
1157
if ( event . target . id !== 'zenWorkspaceMoreActions' ) {
1148
1158
return ;
@@ -1155,10 +1165,35 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
1155
1165
} else {
1156
1166
openInContainerMenuItem . setAttribute ( 'hidden' , 'true' ) ;
1157
1167
}
1168
+ const target = event . explicitOriginalTarget ?. closest ( 'toolbarbutton' ) ;
1169
+ this . #contextMenuData = {
1170
+ workspaceId : target ?. getAttribute ( 'zen-workspace-id' ) ,
1171
+ originalTarget : target ,
1172
+ } ;
1173
+ const workspaceName = document . getElementById ( 'context_zenEditWorkspace' ) ;
1174
+ const themePicker = document . getElementById ( 'context_zenChangeWorkspaceTheme' ) ;
1175
+ workspaceName . hidden =
1176
+ this . #contextMenuData. workspaceId &&
1177
+ this . #contextMenuData. workspaceId !== this . activeWorkspace ;
1178
+ themePicker . hidden =
1179
+ this . #contextMenuData. workspaceId &&
1180
+ this . #contextMenuData. workspaceId !== this . activeWorkspace ;
1181
+ event . target . addEventListener (
1182
+ 'popuphidden' ,
1183
+ ( ) => {
1184
+ this . #contextMenuData = null ;
1185
+ } ,
1186
+ { once : true }
1187
+ ) ;
1158
1188
}
1159
1189
1160
1190
updateWorkspaceActionsMenuContainer ( event ) {
1161
- const workspace = this . getActiveWorkspaceFromCache ( ) ;
1191
+ let workspace ;
1192
+ if ( this . #contextMenuData?. workspaceId ) {
1193
+ workspace = this . getWorkspaceFromId ( this . #contextMenuData. workspaceId ) ;
1194
+ } else {
1195
+ workspace = this . getActiveWorkspaceFromCache ( ) ;
1196
+ }
1162
1197
let containerTabId = workspace . containerTabId ;
1163
1198
return window . createUserContextMenu ( event , {
1164
1199
isContextMenu : true ,
@@ -2349,12 +2384,12 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
2349
2384
this . _organizingWorkspaceStrip = true ;
2350
2385
let workspaces = await this . _workspaces ( ) ;
2351
2386
let workspace = workspaces . workspaces . find (
2352
- ( workspace ) => workspace . uuid === this . activeWorkspace
2387
+ ( workspace ) => workspace . uuid === ( this . #contextMenuData ?. workspaceId || this . activeWorkspace )
2353
2388
) ;
2354
2389
let userContextId = parseInt ( event . target . getAttribute ( 'data-usercontextid' ) ) ;
2355
2390
workspace . containerTabId = userContextId + 0 ; // +0 to convert to number
2356
2391
await this . saveWorkspace ( workspace ) ;
2357
- await this . _organizeWorkspaceStripLocations ( workspace , true ) ;
2392
+ await this . _organizeWorkspaceStripLocations ( this . getActiveWorkspaceFromCache ( ) , true ) ;
2358
2393
await gZenWorkspaces . updateTabsContainers ( ) ;
2359
2394
this . tabContainer . _invalidateCachedTabs ( ) ;
2360
2395
}
@@ -2365,7 +2400,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
2365
2400
{ id : 'zen-workspaces-delete-workspace-body' } ,
2366
2401
] ) ;
2367
2402
if ( Services . prompt . confirm ( null , title , body ) ) {
2368
- await this . removeWorkspace ( this . activeWorkspace ) ;
2403
+ await this . removeWorkspace ( this . #contextMenuData ?. workspaceId || this . activeWorkspace ) ;
2369
2404
}
2370
2405
}
2371
2406
0 commit comments