vzcode 0.64.0 → 0.66.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.
@@ -94,17 +94,25 @@ const convertToCodeMirrorDiagnostic = (
94
94
  }));
95
95
  };
96
96
 
97
+ // This is a promise that resolves when the file system is initialized.
98
+ let fileSystemInitializationPromise = null;
99
+ async function ensureFileSystemInitialized() {
100
+ if (!fileSystemInitializationPromise) {
101
+ fileSystemInitializationPromise =
102
+ initializeFileSystem();
103
+ }
104
+ await fileSystemInitializationPromise;
105
+ }
106
+
97
107
  onmessage = async ({ data }) => {
98
108
  if (debug) {
99
109
  console.log('message received');
100
110
  }
101
- // Initialize the file system.
102
- if (!isFileSystemInitialized) {
103
- isFileSystemInitialized = true;
104
- await initializeFileSystem();
105
- }
106
111
 
107
- // Sanity check.
112
+ // Ensure the file system is initialized.
113
+ await ensureFileSystemInitialized();
114
+
115
+ // Sanity check - should never happen.
108
116
  if (env === null) {
109
117
  throw new Error('File system not initialized');
110
118
  }
@@ -3,6 +3,10 @@ import { ThemeLabel } from '../themes';
3
3
  import { closeTabsReducer } from './closeTabsReducer';
4
4
  import { openTabReducer } from './openTabReducer';
5
5
  import { setActiveFileIdReducer } from './setActiveFileIdReducer';
6
+ import {
7
+ setActiveFileLeftReducer,
8
+ setActiveFileRightReducer,
9
+ } from './setActiveFileLeftRightReducer';
6
10
  import { setIsSettingsOpenReducer } from './setIsSettingsOpenReducer';
7
11
  import { setThemeReducer } from './setThemeReducer';
8
12
  import { editorNoLongerWantsFocusReducer } from './editorNoLongerWantsFocusReducer';
@@ -38,6 +42,12 @@ export type VZAction =
38
42
  // * Sets the active file ID.
39
43
  | { type: 'set_active_file_id'; activeFileId: FileId }
40
44
 
45
+ // `set_active_file_left' 'set_active_file_right`
46
+ // * Sets the active file ID to be the tab directly to the left or right
47
+ // * of the currently active tab.
48
+ | { type: 'set_active_file_left' }
49
+ | { type: 'set_active_file_right' }
50
+
41
51
  // `open_tab`
42
52
  // * Opens a tab.
43
53
  // * Also serves to change an already open transient tab to persistent.
@@ -88,6 +98,8 @@ export type TabState = {
88
98
 
89
99
  const reducers = [
90
100
  setActiveFileIdReducer,
101
+ setActiveFileLeftReducer,
102
+ setActiveFileRightReducer,
91
103
  openTabReducer,
92
104
  closeTabsReducer,
93
105
  setThemeReducer,
@@ -0,0 +1,47 @@
1
+ import { VZAction, VZState } from '.';
2
+
3
+ export const setActiveFileLeftReducer = (
4
+ state: VZState,
5
+ action: VZAction,
6
+ ): VZState => {
7
+ if (action.type !== 'set_active_file_left') {
8
+ return state;
9
+ }
10
+
11
+ let index = state.tabList.findIndex(
12
+ (tab) => tab.fileId === state.activeFileId,
13
+ );
14
+
15
+ index -= 1;
16
+ if (index < 0) {
17
+ index = state.tabList.length - 1;
18
+ }
19
+
20
+ return {
21
+ ...state,
22
+ activeFileId: state.tabList[index].fileId,
23
+ };
24
+ };
25
+
26
+ export const setActiveFileRightReducer = (
27
+ state: VZState,
28
+ action: VZAction,
29
+ ): VZState => {
30
+ if (action.type !== 'set_active_file_right') {
31
+ return state;
32
+ }
33
+
34
+ let index = state.tabList.findIndex(
35
+ (tab) => tab.fileId === state.activeFileId,
36
+ );
37
+
38
+ index += 1;
39
+ if (index > state.tabList.length - 1) {
40
+ index = 0;
41
+ }
42
+
43
+ return {
44
+ ...state,
45
+ activeFileId: state.tabList[index].fileId,
46
+ };
47
+ };