fix(electron): allow close pinned tab (#7732)
This commit is contained in:
@@ -10,7 +10,6 @@ import {
|
|||||||
|
|
||||||
export const showTabContextMenu = async (tabId: string, viewIndex: number) => {
|
export const showTabContextMenu = async (tabId: string, viewIndex: number) => {
|
||||||
const workbenches = WebContentViewsManager.instance.tabViewsMeta.workbenches;
|
const workbenches = WebContentViewsManager.instance.tabViewsMeta.workbenches;
|
||||||
const unpinned = workbenches.filter(w => !w.pinned);
|
|
||||||
const tabMeta = workbenches.find(w => w.id === tabId);
|
const tabMeta = workbenches.find(w => w.id === tabId);
|
||||||
if (!tabMeta) {
|
if (!tabMeta) {
|
||||||
return;
|
return;
|
||||||
@@ -63,7 +62,7 @@ export const showTabContextMenu = async (tabId: string, viewIndex: number) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
...(unpinned.length > 0
|
...(workbenches.length > 0
|
||||||
? ([
|
? ([
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ export type AddTabOption = {
|
|||||||
* Whether to show the tab after adding.
|
* Whether to show the tab after adding.
|
||||||
*/
|
*/
|
||||||
show?: boolean;
|
show?: boolean;
|
||||||
|
pinned?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class WebContentViewsManager {
|
export class WebContentViewsManager {
|
||||||
@@ -328,11 +329,6 @@ export class WebContentViewsManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const targetWorkbench = this.tabViewsMeta.workbenches[index];
|
const targetWorkbench = this.tabViewsMeta.workbenches[index];
|
||||||
|
|
||||||
if (targetWorkbench.pinned) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const workbenches = this.tabViewsMeta.workbenches.toSpliced(index, 1);
|
const workbenches = this.tabViewsMeta.workbenches.toSpliced(index, 1);
|
||||||
// if the active view is closed, switch to the next view (index unchanged)
|
// if the active view is closed, switch to the next view (index unchanged)
|
||||||
// if the new index is out of bound, switch to the last view
|
// if the new index is out of bound, switch to the last view
|
||||||
@@ -398,6 +394,7 @@ export class WebContentViewsManager {
|
|||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
};
|
};
|
||||||
|
option.pinned ??= false;
|
||||||
|
|
||||||
const workbenches = this.tabViewsMeta.workbenches;
|
const workbenches = this.tabViewsMeta.workbenches;
|
||||||
const newKey = this.generateViewId('app');
|
const newKey = this.generateViewId('app');
|
||||||
@@ -422,7 +419,7 @@ export class WebContentViewsManager {
|
|||||||
activeViewIndex: 0,
|
activeViewIndex: 0,
|
||||||
views: views,
|
views: views,
|
||||||
id: newKey,
|
id: newKey,
|
||||||
pinned: targetItem?.pinned ?? false,
|
pinned: option.pinned,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.patchTabViewsMeta({
|
this.patchTabViewsMeta({
|
||||||
|
|||||||
Reference in New Issue
Block a user