@lvce-editor/main-area-worker 9.28.1 → 9.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mainAreaWorkerMain.js +98 -13
- package/package.json +1 -1
|
@@ -2261,7 +2261,10 @@ const closeTabAndSave = async (state, groupId, tabId) => {
|
|
|
2261
2261
|
}
|
|
2262
2262
|
if (tab.editorUid !== -1 && tab.isDirty) {
|
|
2263
2263
|
const editorState = await saveEditor(tab.editorUid);
|
|
2264
|
-
if (
|
|
2264
|
+
if (editorState?.modified !== false) {
|
|
2265
|
+
return state;
|
|
2266
|
+
}
|
|
2267
|
+
if (tab.uri) {
|
|
2265
2268
|
await handleModifiedStatusChange$1(tab.uri, false);
|
|
2266
2269
|
}
|
|
2267
2270
|
}
|
|
@@ -3673,6 +3676,7 @@ const ensureActiveGroup = (state, uri, preview = false, title = getLabel(uri), e
|
|
|
3673
3676
|
...tab,
|
|
3674
3677
|
editorInput,
|
|
3675
3678
|
editorType,
|
|
3679
|
+
editorUid: create$2(),
|
|
3676
3680
|
errorMessage: '',
|
|
3677
3681
|
icon: '',
|
|
3678
3682
|
isDirty: false,
|
|
@@ -3922,6 +3926,18 @@ const updateTabIcon = async (context, readyState, tabId) => {
|
|
|
3922
3926
|
}
|
|
3923
3927
|
};
|
|
3924
3928
|
|
|
3929
|
+
const getExistingTabState = (state, existingTab, preview) => {
|
|
3930
|
+
const focusedState = focusEditorGroup(state, existingTab.groupId);
|
|
3931
|
+
const pinnedState = !preview && existingTab.tab.isPreview ? updateTab(focusedState, existingTab.tab.id, {
|
|
3932
|
+
isPreview: false
|
|
3933
|
+
}) : focusedState;
|
|
3934
|
+
return switchTab(pinnedState, existingTab.groupId, existingTab.tab.id);
|
|
3935
|
+
};
|
|
3936
|
+
const getActivePreviewEditorUid = state => {
|
|
3937
|
+
const activeGroup = state.layout.activeGroupId === undefined ? state.layout.groups.find(group => group.focused) : state.layout.groups.find(group => group.id === state.layout.activeGroupId);
|
|
3938
|
+
const activeTab = activeGroup?.tabs.find(tab => tab.id === activeGroup.activeTabId);
|
|
3939
|
+
return activeTab?.isPreview ? activeTab.editorUid : -1;
|
|
3940
|
+
};
|
|
3925
3941
|
const openInputWithContext = async (context, options) => {
|
|
3926
3942
|
const state = context.getState();
|
|
3927
3943
|
object(state);
|
|
@@ -3937,17 +3953,20 @@ const openInputWithContext = async (context, options) => {
|
|
|
3937
3953
|
const existingTab = findTabByUri(currentState, uri);
|
|
3938
3954
|
const shouldRetryExistingTab = !!existingTab && existingTab.tab.loadingState === 'error';
|
|
3939
3955
|
if (existingTab && !shouldRetryExistingTab) {
|
|
3940
|
-
const
|
|
3941
|
-
const switchedState = switchTab(focusedState, existingTab.groupId, existingTab.tab.id);
|
|
3956
|
+
const switchedState = getExistingTabState(currentState, existingTab, preview);
|
|
3942
3957
|
await context.updateState(() => switchedState);
|
|
3943
3958
|
return;
|
|
3944
3959
|
}
|
|
3960
|
+
const replacedEditorUid = getActivePreviewEditorUid(currentState);
|
|
3945
3961
|
const previousTabId = getActiveTabId(currentState);
|
|
3946
3962
|
const {
|
|
3947
3963
|
stateWithTab,
|
|
3948
3964
|
tabId
|
|
3949
3965
|
} = getStateWithTab(currentState, editorInput, existingTab, shouldRetryExistingTab, uri, preview, title, editorType);
|
|
3950
3966
|
await context.updateState(() => stateWithTab);
|
|
3967
|
+
if (replacedEditorUid !== -1) {
|
|
3968
|
+
await disposeEditors([replacedEditorUid]);
|
|
3969
|
+
}
|
|
3951
3970
|
if (await isDirectoryEditorInput(editorInput)) {
|
|
3952
3971
|
const latestState = context.getState();
|
|
3953
3972
|
const errorState = updateTab(latestState, tabId, {
|
|
@@ -4083,8 +4102,11 @@ const getGroupSegments = (groups, parentDirection) => {
|
|
|
4083
4102
|
if (group.direction !== undefined && group.direction !== parentDirection) {
|
|
4084
4103
|
const startIndex = index;
|
|
4085
4104
|
const nestedGroups = [group];
|
|
4105
|
+
const {
|
|
4106
|
+
segmentId
|
|
4107
|
+
} = group;
|
|
4086
4108
|
index++;
|
|
4087
|
-
while (index < groups.length && groups[index].direction === group.direction) {
|
|
4109
|
+
while (index < groups.length && groups[index].direction === group.direction && groups[index].segmentId === segmentId) {
|
|
4088
4110
|
nestedGroups.push(groups[index]);
|
|
4089
4111
|
index++;
|
|
4090
4112
|
}
|
|
@@ -4176,6 +4198,7 @@ const splitWithinMatchingNestedDirection = (state, groups, sourceGroup, groupId,
|
|
|
4176
4198
|
const newGroup = {
|
|
4177
4199
|
...baseNewGroup,
|
|
4178
4200
|
direction: splitLayoutDirection,
|
|
4201
|
+
segmentId: sourceGroup.segmentId,
|
|
4179
4202
|
size: Number((sourceGroup.size / 2).toFixed(6))
|
|
4180
4203
|
};
|
|
4181
4204
|
const insertIndex = isTrailingSplit(direction) ? sourceIndex + 1 : sourceIndex;
|
|
@@ -4185,15 +4208,18 @@ const splitWithinMatchingNestedDirection = (state, groups, sourceGroup, groupId,
|
|
|
4185
4208
|
const splitStandaloneSourceIntoNestedDirection = (state, groups, sourceGroup, groupId, newGroupId, direction, splitLayoutDirection, baseNewGroup) => {
|
|
4186
4209
|
const sourceIndex = groups.findIndex(group => group.id === groupId);
|
|
4187
4210
|
const halfSize = Number((sourceGroup.size / 2).toFixed(6));
|
|
4211
|
+
const segmentId = sourceGroup.segmentId ?? sourceGroup.id;
|
|
4188
4212
|
const updatedSourceGroup = {
|
|
4189
4213
|
...sourceGroup,
|
|
4190
4214
|
direction: splitLayoutDirection,
|
|
4191
4215
|
focused: false,
|
|
4216
|
+
segmentId,
|
|
4192
4217
|
size: halfSize
|
|
4193
4218
|
};
|
|
4194
4219
|
const newGroup = {
|
|
4195
4220
|
...baseNewGroup,
|
|
4196
4221
|
direction: splitLayoutDirection,
|
|
4222
|
+
segmentId,
|
|
4197
4223
|
size: Number((sourceGroup.size - halfSize).toFixed(6))
|
|
4198
4224
|
};
|
|
4199
4225
|
const replacementGroups = isTrailingSplit(direction) ? [updatedSourceGroup, newGroup] : [newGroup, updatedSourceGroup];
|
|
@@ -4329,7 +4355,10 @@ const handleClickCloseTab = async (state, rawGroupIndex, rawIndex) => {
|
|
|
4329
4355
|
return closeTabAndSave(state, groupId, tabId);
|
|
4330
4356
|
};
|
|
4331
4357
|
|
|
4332
|
-
const handleClickTab = async (state, groupIndexRaw, indexRaw) => {
|
|
4358
|
+
const handleClickTab = async (state, groupIndexRaw, indexRaw, button = 0) => {
|
|
4359
|
+
if (button !== 0) {
|
|
4360
|
+
return state;
|
|
4361
|
+
}
|
|
4333
4362
|
if (!groupIndexRaw || !indexRaw) {
|
|
4334
4363
|
return state;
|
|
4335
4364
|
}
|
|
@@ -4360,9 +4389,19 @@ const handleContextMenu = async (state, rawGroupId, x, y) => {
|
|
|
4360
4389
|
return state;
|
|
4361
4390
|
};
|
|
4362
4391
|
|
|
4363
|
-
const handleDoubleClick =
|
|
4364
|
-
|
|
4365
|
-
|
|
4392
|
+
const handleDoubleClick = (state, groupIndexRaw, indexRaw) => {
|
|
4393
|
+
if (!groupIndexRaw || !indexRaw) {
|
|
4394
|
+
return state;
|
|
4395
|
+
}
|
|
4396
|
+
const groupIndex = Number.parseInt(groupIndexRaw);
|
|
4397
|
+
const tabIndex = Number.parseInt(indexRaw);
|
|
4398
|
+
const tab = state.layout.groups[groupIndex]?.tabs[tabIndex];
|
|
4399
|
+
if (!tab?.isPreview) {
|
|
4400
|
+
return state;
|
|
4401
|
+
}
|
|
4402
|
+
return updateTab(state, tab.id, {
|
|
4403
|
+
isPreview: false
|
|
4404
|
+
});
|
|
4366
4405
|
};
|
|
4367
4406
|
|
|
4368
4407
|
const EditorGroupHeader = 'EditorGroupHeader';
|
|
@@ -4583,7 +4622,8 @@ const handleModifiedStatusChange = (state, uri, newStatus) => {
|
|
|
4583
4622
|
if (tab.uri === uri) {
|
|
4584
4623
|
return {
|
|
4585
4624
|
...tab,
|
|
4586
|
-
isDirty: newStatus
|
|
4625
|
+
isDirty: newStatus,
|
|
4626
|
+
isPreview: newStatus ? false : tab.isPreview
|
|
4587
4627
|
};
|
|
4588
4628
|
}
|
|
4589
4629
|
return tab;
|
|
@@ -4859,7 +4899,7 @@ const isValidTab = tab => {
|
|
|
4859
4899
|
};
|
|
4860
4900
|
|
|
4861
4901
|
const isValidEditorGroup = group => {
|
|
4862
|
-
return group && typeof group.id === 'number' && Array.isArray(group.tabs) && group.tabs.every(isValidTab) && (group.activeTabId === undefined || typeof group.activeTabId === 'number') && (group.direction === undefined || isLayoutDirection(group.direction)) && typeof group.focused === 'boolean' && typeof group.size === 'number' && group.size > 0 && typeof group.isEmpty === 'boolean';
|
|
4902
|
+
return group && typeof group.id === 'number' && Array.isArray(group.tabs) && group.tabs.every(isValidTab) && (group.activeTabId === undefined || typeof group.activeTabId === 'number') && (group.direction === undefined || isLayoutDirection(group.direction)) && typeof group.focused === 'boolean' && (group.segmentId === undefined || typeof group.segmentId === 'number') && typeof group.size === 'number' && group.size > 0 && typeof group.isEmpty === 'boolean';
|
|
4863
4903
|
};
|
|
4864
4904
|
|
|
4865
4905
|
const isValidMainAreaLayout = layout => {
|
|
@@ -5095,6 +5135,24 @@ const handleWorkspaceChange = async (state, _workspacePath, savedState) => {
|
|
|
5095
5135
|
return loadContent(state, savedState);
|
|
5096
5136
|
};
|
|
5097
5137
|
|
|
5138
|
+
const handleWorkspaceRefresh = async (state, deletedUris = []) => {
|
|
5139
|
+
const deleted = new Set(deletedUris);
|
|
5140
|
+
let newState = state;
|
|
5141
|
+
for (const group of state.layout.groups) {
|
|
5142
|
+
for (const tab of group.tabs) {
|
|
5143
|
+
if (tab.editorInput?.type === 'editor' && deleted.has(tab.editorInput.uri)) {
|
|
5144
|
+
newState = await closeTabWithViewlet(newState, group.id, tab.id);
|
|
5145
|
+
}
|
|
5146
|
+
}
|
|
5147
|
+
}
|
|
5148
|
+
return newState;
|
|
5149
|
+
};
|
|
5150
|
+
const handleWorkspaceRefreshWithContext = async (context, deletedUris = []) => {
|
|
5151
|
+
const state = context.getState();
|
|
5152
|
+
const newState = await handleWorkspaceRefresh(state, deletedUris);
|
|
5153
|
+
await context.updateState(() => newState);
|
|
5154
|
+
};
|
|
5155
|
+
|
|
5098
5156
|
const hasActiveTextEditor = state => {
|
|
5099
5157
|
const activeTab = getActiveTab(state);
|
|
5100
5158
|
return activeTab?.tab.editorInput?.type === 'editor';
|
|
@@ -5926,6 +5984,7 @@ const HandleHeaderDoubleClick = 15;
|
|
|
5926
5984
|
const HandleSashPointerDown = 16;
|
|
5927
5985
|
const HandleSashPointerMove = 17;
|
|
5928
5986
|
const HandleSashPointerUp = 18;
|
|
5987
|
+
const HandleDoubleClick = 19;
|
|
5929
5988
|
|
|
5930
5989
|
const renderContent = content => {
|
|
5931
5990
|
return [{
|
|
@@ -6092,6 +6151,7 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
|
|
|
6092
6151
|
'data-groupIndex': groupIndex,
|
|
6093
6152
|
'data-index': tabIndex,
|
|
6094
6153
|
onContextMenu: HandleTabContextMenu,
|
|
6154
|
+
onDblClick: HandleDoubleClick,
|
|
6095
6155
|
onMouseDown: HandleClickTab,
|
|
6096
6156
|
role: 'tab',
|
|
6097
6157
|
title: tab.uriTitle || tab.uri || tab.title,
|
|
@@ -6452,7 +6512,10 @@ const renderEventListeners = () => {
|
|
|
6452
6512
|
params: ['handleClickCloseTab', 'event.target.dataset.groupIndex', 'event.target.dataset.index']
|
|
6453
6513
|
}, {
|
|
6454
6514
|
name: HandleClickTab,
|
|
6455
|
-
params: ['handleClickTab', 'event.target.dataset.groupIndex', 'event.target.dataset.index']
|
|
6515
|
+
params: ['handleClickTab', 'event.target.dataset.groupIndex', 'event.target.dataset.index', Button$1]
|
|
6516
|
+
}, {
|
|
6517
|
+
name: HandleDoubleClick,
|
|
6518
|
+
params: ['handleDoubleClick', 'event.target.dataset.groupIndex', 'event.target.dataset.index']
|
|
6456
6519
|
}, {
|
|
6457
6520
|
name: HandleContextMenu,
|
|
6458
6521
|
params: ['handleContextMenu', 'event.target.dataset.groupId', ClientX, ClientY],
|
|
@@ -6576,6 +6639,14 @@ const reopenEditorWith = async context => {
|
|
|
6576
6639
|
}
|
|
6577
6640
|
};
|
|
6578
6641
|
|
|
6642
|
+
const settingsUri = 'app://settings.json';
|
|
6643
|
+
const saveEditorAndHandleSettingsChange = async tab => {
|
|
6644
|
+
const editorState = await saveEditor(tab.editorUid);
|
|
6645
|
+
if (!editorState?.modified && tab.uri === settingsUri) {
|
|
6646
|
+
await invoke('Layout.handleSettingsChanged');
|
|
6647
|
+
}
|
|
6648
|
+
return editorState;
|
|
6649
|
+
};
|
|
6579
6650
|
const getLatestStoredState = (uid, fallbackState, referenceTabId, referenceTabUri, allowMissingReference = false) => {
|
|
6580
6651
|
const stateFromStore = get(uid);
|
|
6581
6652
|
if (!stateFromStore) {
|
|
@@ -6611,10 +6682,10 @@ const save = async state => {
|
|
|
6611
6682
|
return currentState;
|
|
6612
6683
|
}
|
|
6613
6684
|
if (!tab.isDirty) {
|
|
6614
|
-
await
|
|
6685
|
+
await saveEditorAndHandleSettingsChange(tab);
|
|
6615
6686
|
return getLatestStoredState(state.uid, currentState, tab.id, tab.uri);
|
|
6616
6687
|
}
|
|
6617
|
-
const editorState = await
|
|
6688
|
+
const editorState = await saveEditorAndHandleSettingsChange(tab);
|
|
6618
6689
|
const latestState = getLatestStoredState(state.uid, currentState, tab.id, tab.uri);
|
|
6619
6690
|
if (editorState?.modified) {
|
|
6620
6691
|
return latestState;
|
|
@@ -6745,6 +6816,7 @@ const setEditorLayout = (state, direction, slots) => {
|
|
|
6745
6816
|
...group,
|
|
6746
6817
|
direction: slot.direction,
|
|
6747
6818
|
focused,
|
|
6819
|
+
segmentId: slot.segmentId,
|
|
6748
6820
|
size: slot.size
|
|
6749
6821
|
};
|
|
6750
6822
|
});
|
|
@@ -6808,39 +6880,51 @@ const setEditorLayoutThreeRows = state => {
|
|
|
6808
6880
|
}]);
|
|
6809
6881
|
};
|
|
6810
6882
|
const setEditorLayoutGrid = state => {
|
|
6883
|
+
const leftSegmentId = create$2();
|
|
6884
|
+
const rightSegmentId = create$2();
|
|
6811
6885
|
return setEditorLayout(state, Horizontal, [{
|
|
6812
6886
|
direction: Vertical,
|
|
6887
|
+
segmentId: leftSegmentId,
|
|
6813
6888
|
size: 25
|
|
6814
6889
|
}, {
|
|
6815
6890
|
direction: Vertical,
|
|
6891
|
+
segmentId: leftSegmentId,
|
|
6816
6892
|
size: 25
|
|
6817
6893
|
}, {
|
|
6818
6894
|
direction: Vertical,
|
|
6895
|
+
segmentId: rightSegmentId,
|
|
6819
6896
|
size: 25
|
|
6820
6897
|
}, {
|
|
6821
6898
|
direction: Vertical,
|
|
6899
|
+
segmentId: rightSegmentId,
|
|
6822
6900
|
size: 25
|
|
6823
6901
|
}]);
|
|
6824
6902
|
};
|
|
6825
6903
|
const setEditorLayoutTwoRowsRight = state => {
|
|
6904
|
+
const segmentId = create$2();
|
|
6826
6905
|
return setEditorLayout(state, Horizontal, [{
|
|
6827
6906
|
size: 50
|
|
6828
6907
|
}, {
|
|
6829
6908
|
direction: Vertical,
|
|
6909
|
+
segmentId,
|
|
6830
6910
|
size: 25
|
|
6831
6911
|
}, {
|
|
6832
6912
|
direction: Vertical,
|
|
6913
|
+
segmentId,
|
|
6833
6914
|
size: 25
|
|
6834
6915
|
}]);
|
|
6835
6916
|
};
|
|
6836
6917
|
const setEditorLayoutTwoColumnsBottom = state => {
|
|
6918
|
+
const segmentId = create$2();
|
|
6837
6919
|
return setEditorLayout(state, Vertical, [{
|
|
6838
6920
|
size: 50
|
|
6839
6921
|
}, {
|
|
6840
6922
|
direction: Horizontal,
|
|
6923
|
+
segmentId,
|
|
6841
6924
|
size: 25
|
|
6842
6925
|
}, {
|
|
6843
6926
|
direction: Horizontal,
|
|
6927
|
+
segmentId,
|
|
6844
6928
|
size: 25
|
|
6845
6929
|
}]);
|
|
6846
6930
|
};
|
|
@@ -7046,6 +7130,7 @@ const commandMap = {
|
|
|
7046
7130
|
'MainArea.handleTabContextMenu': wrapSerialCommand(handleTabContextMenu),
|
|
7047
7131
|
'MainArea.handleUriChange': wrapSerialCommand(handleUriChange),
|
|
7048
7132
|
'MainArea.handleWorkspaceChange': wrapSerialCommand(handleWorkspaceChange),
|
|
7133
|
+
'MainArea.handleWorkspaceRefresh': wrapAsyncCommand(handleWorkspaceRefreshWithContext),
|
|
7049
7134
|
'MainArea.hasActiveTextEditor': wrapGetter(hasActiveTextEditor),
|
|
7050
7135
|
'MainArea.initialize': initialize,
|
|
7051
7136
|
'MainArea.loadContent': wrapSerialCommand(loadContent),
|