@lvce-editor/main-area-worker 9.28.2 → 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.
@@ -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 (!editorState?.modified && tab.uri) {
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 focusedState = focusEditorGroup(currentState, existingTab.groupId);
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, {
@@ -4370,9 +4389,19 @@ const handleContextMenu = async (state, rawGroupId, x, y) => {
4370
4389
  return state;
4371
4390
  };
4372
4391
 
4373
- const handleDoubleClick = async state => {
4374
- // TODO: implement handleDoubleClick
4375
- return state;
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
+ });
4376
4405
  };
4377
4406
 
4378
4407
  const EditorGroupHeader = 'EditorGroupHeader';
@@ -4593,7 +4622,8 @@ const handleModifiedStatusChange = (state, uri, newStatus) => {
4593
4622
  if (tab.uri === uri) {
4594
4623
  return {
4595
4624
  ...tab,
4596
- isDirty: newStatus
4625
+ isDirty: newStatus,
4626
+ isPreview: newStatus ? false : tab.isPreview
4597
4627
  };
4598
4628
  }
4599
4629
  return tab;
@@ -5954,6 +5984,7 @@ const HandleHeaderDoubleClick = 15;
5954
5984
  const HandleSashPointerDown = 16;
5955
5985
  const HandleSashPointerMove = 17;
5956
5986
  const HandleSashPointerUp = 18;
5987
+ const HandleDoubleClick = 19;
5957
5988
 
5958
5989
  const renderContent = content => {
5959
5990
  return [{
@@ -6120,6 +6151,7 @@ const renderTab = (tab, isActive, tabIndex, groupIndex) => {
6120
6151
  'data-groupIndex': groupIndex,
6121
6152
  'data-index': tabIndex,
6122
6153
  onContextMenu: HandleTabContextMenu,
6154
+ onDblClick: HandleDoubleClick,
6123
6155
  onMouseDown: HandleClickTab,
6124
6156
  role: 'tab',
6125
6157
  title: tab.uriTitle || tab.uri || tab.title,
@@ -6481,6 +6513,9 @@ const renderEventListeners = () => {
6481
6513
  }, {
6482
6514
  name: HandleClickTab,
6483
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']
6484
6519
  }, {
6485
6520
  name: HandleContextMenu,
6486
6521
  params: ['handleContextMenu', 'event.target.dataset.groupId', ClientX, ClientY],
@@ -6604,6 +6639,14 @@ const reopenEditorWith = async context => {
6604
6639
  }
6605
6640
  };
6606
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
+ };
6607
6650
  const getLatestStoredState = (uid, fallbackState, referenceTabId, referenceTabUri, allowMissingReference = false) => {
6608
6651
  const stateFromStore = get(uid);
6609
6652
  if (!stateFromStore) {
@@ -6639,10 +6682,10 @@ const save = async state => {
6639
6682
  return currentState;
6640
6683
  }
6641
6684
  if (!tab.isDirty) {
6642
- await saveEditor(tab.editorUid);
6685
+ await saveEditorAndHandleSettingsChange(tab);
6643
6686
  return getLatestStoredState(state.uid, currentState, tab.id, tab.uri);
6644
6687
  }
6645
- const editorState = await saveEditor(tab.editorUid);
6688
+ const editorState = await saveEditorAndHandleSettingsChange(tab);
6646
6689
  const latestState = getLatestStoredState(state.uid, currentState, tab.id, tab.uri);
6647
6690
  if (editorState?.modified) {
6648
6691
  return latestState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/main-area-worker",
3
- "version": "9.28.2",
3
+ "version": "9.29.0",
4
4
  "description": "Main Area Worker",
5
5
  "repository": {
6
6
  "type": "git",