vzcode 1.14.0 → 1.15.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/assets/{index-DGNI0PAo.js → index-DbFdL1A1.js} +55 -53
- package/dist/assets/{index-Wxh-Jaj6.css → index-Yz-ZHc0O.css} +1 -1
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/client/CodeEditor/index.tsx +1 -1
- package/src/client/VZCodeContext.tsx +14 -0
- package/src/client/VZSidebar/FileListing.tsx +20 -56
- package/src/client/VZSidebar/FileTypeIcon.tsx +49 -0
- package/src/client/VZSidebar/Item.tsx +5 -9
- package/src/client/VZSidebar/Search.tsx +412 -108
- package/src/client/VZSidebar/index.tsx +1 -1
- package/src/client/VZSidebar/styles.scss +36 -21
- package/src/client/useActions.ts +31 -0
- package/src/client/useKeyboardShortcuts.ts +13 -3
- package/src/client/vzReducer/createInitialState.ts +7 -1
- package/src/client/vzReducer/index.ts +21 -0
- package/src/client/vzReducer/openTabReducer.ts +4 -3
- package/src/client/vzReducer/searchReducer.ts +46 -1
- package/src/types.ts +2 -0
package/src/client/useActions.ts
CHANGED
|
@@ -115,6 +115,35 @@ export const useActions = (
|
|
|
115
115
|
[dispatch],
|
|
116
116
|
);
|
|
117
117
|
|
|
118
|
+
// Update search results file matching line visibility to be
|
|
119
|
+
const setSearchLineVisibility = useCallback(
|
|
120
|
+
(
|
|
121
|
+
files: ShareDBDoc<VZCodeContent>,
|
|
122
|
+
id: string,
|
|
123
|
+
line: number,
|
|
124
|
+
) => {
|
|
125
|
+
dispatch({
|
|
126
|
+
type: 'hide_search_results_line',
|
|
127
|
+
files: files,
|
|
128
|
+
id: id,
|
|
129
|
+
line: line,
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
[dispatch],
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Update search results active element
|
|
136
|
+
const setSearchFocusedIndex = useCallback(
|
|
137
|
+
(focusedIndex: number, childIndex: number) => {
|
|
138
|
+
dispatch({
|
|
139
|
+
type: 'set_active_search_index',
|
|
140
|
+
focusedIndex: focusedIndex,
|
|
141
|
+
childIndex: childIndex,
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
[dispatch],
|
|
145
|
+
);
|
|
146
|
+
|
|
118
147
|
// Toggle the focused variable, which should focus the search input
|
|
119
148
|
const toggleSearchFocused = useCallback(() => {
|
|
120
149
|
dispatch({
|
|
@@ -200,6 +229,8 @@ export const useActions = (
|
|
|
200
229
|
setSearch,
|
|
201
230
|
setSearchResults,
|
|
202
231
|
setSearchFileVisibility,
|
|
232
|
+
setSearchLineVisibility,
|
|
233
|
+
setSearchFocusedIndex,
|
|
203
234
|
toggleSearchFocused,
|
|
204
235
|
setIsSettingsOpen,
|
|
205
236
|
setIsDocOpen,
|
|
@@ -4,7 +4,8 @@ import { syntaxTree } from '@codemirror/language';
|
|
|
4
4
|
import { SyntaxNode, SyntaxNodeRef } from '@lezer/common';
|
|
5
5
|
import { EditorView } from '@codemirror/view';
|
|
6
6
|
import { EditorState } from '@codemirror/state';
|
|
7
|
-
import { FileId } from '../types';
|
|
7
|
+
import { FileId, PaneId } from '../types';
|
|
8
|
+
import { editorCacheKey } from './useEditorCache';
|
|
8
9
|
|
|
9
10
|
/*
|
|
10
11
|
The following is a helpful resource for the following Code Mirror Syntax Tree methods below
|
|
@@ -175,6 +176,7 @@ const sideBarKeyBoardMap = {
|
|
|
175
176
|
export const useKeyboardShortcuts = ({
|
|
176
177
|
closeTabs,
|
|
177
178
|
activeFileId,
|
|
179
|
+
activePaneId,
|
|
178
180
|
handleOpenCreateFileModal,
|
|
179
181
|
setActiveFileLeft,
|
|
180
182
|
setActiveFileRight,
|
|
@@ -187,6 +189,7 @@ export const useKeyboardShortcuts = ({
|
|
|
187
189
|
}: {
|
|
188
190
|
closeTabs: (fileIds: FileId[]) => void;
|
|
189
191
|
activeFileId: FileId | null;
|
|
192
|
+
activePaneId: PaneId;
|
|
190
193
|
handleOpenCreateFileModal: () => void;
|
|
191
194
|
setActiveFileLeft: () => void;
|
|
192
195
|
setActiveFileRight: () => void;
|
|
@@ -198,6 +201,12 @@ export const useKeyboardShortcuts = ({
|
|
|
198
201
|
codeEditorRef: React.RefObject<HTMLDivElement>;
|
|
199
202
|
}) => {
|
|
200
203
|
useEffect(() => {
|
|
204
|
+
// This key is needed to look up the current editor in the editor cache.
|
|
205
|
+
const cacheKey = editorCacheKey(
|
|
206
|
+
activeFileId,
|
|
207
|
+
activePaneId,
|
|
208
|
+
);
|
|
209
|
+
|
|
201
210
|
const handleKeyPress = (event: KeyboardEvent) => {
|
|
202
211
|
if (shouldTriggerRun(event)) {
|
|
203
212
|
event.preventDefault();
|
|
@@ -321,8 +330,9 @@ export const useKeyboardShortcuts = ({
|
|
|
321
330
|
}
|
|
322
331
|
|
|
323
332
|
// Move current cursor and center view in the editor to destination node
|
|
333
|
+
|
|
324
334
|
const editor: EditorView =
|
|
325
|
-
editorCache.get(
|
|
335
|
+
editorCache.get(cacheKey).editor;
|
|
326
336
|
const closestDefinition: SyntaxNode = definingNode;
|
|
327
337
|
|
|
328
338
|
editor.dispatch({
|
|
@@ -355,7 +365,7 @@ export const useKeyboardShortcuts = ({
|
|
|
355
365
|
}
|
|
356
366
|
|
|
357
367
|
const editor: EditorView =
|
|
358
|
-
editorCache.get(
|
|
368
|
+
editorCache.get(cacheKey).editor;
|
|
359
369
|
const tree = syntaxTree(editor.state);
|
|
360
370
|
const element = event.target as HTMLSpanElement;
|
|
361
371
|
|
|
@@ -17,7 +17,13 @@ export const createInitialState = ({
|
|
|
17
17
|
},
|
|
18
18
|
activePaneId: 'root',
|
|
19
19
|
theme: defaultTheme,
|
|
20
|
-
search: {
|
|
20
|
+
search: {
|
|
21
|
+
pattern: '',
|
|
22
|
+
results: {},
|
|
23
|
+
focused: false,
|
|
24
|
+
focusedIndex: null,
|
|
25
|
+
focusedChildIndex: null,
|
|
26
|
+
},
|
|
21
27
|
isSearchOpen: false,
|
|
22
28
|
isSettingsOpen: false,
|
|
23
29
|
isDocOpen: false,
|
|
@@ -27,6 +27,8 @@ import {
|
|
|
27
27
|
setSearchReducer,
|
|
28
28
|
setSearchResultsReducer,
|
|
29
29
|
setSearchFileVisibilityReducer,
|
|
30
|
+
setSearchLineVisibilityReducer,
|
|
31
|
+
setSearchFocusedIndexReducer,
|
|
30
32
|
toggleSearchFocusedReducer,
|
|
31
33
|
} from './searchReducer';
|
|
32
34
|
import { toggleAutoFollowReducer } from './toggleAutoFollowReducer';
|
|
@@ -134,6 +136,23 @@ export type VZAction =
|
|
|
134
136
|
visibility: SearchFileVisibility;
|
|
135
137
|
}
|
|
136
138
|
|
|
139
|
+
// `hide_search_results_line`
|
|
140
|
+
// * Hides a current search pattern file's specific matching line
|
|
141
|
+
| {
|
|
142
|
+
type: 'hide_search_results_line';
|
|
143
|
+
files: ShareDBDoc<VZCodeContent>;
|
|
144
|
+
id: string;
|
|
145
|
+
line: number;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// `set_active_search_index`
|
|
149
|
+
// * Sets focused (file) index and child focused (line) index for search results
|
|
150
|
+
| {
|
|
151
|
+
type: 'set_active_search_index';
|
|
152
|
+
focusedIndex: number;
|
|
153
|
+
childIndex: number;
|
|
154
|
+
}
|
|
155
|
+
|
|
137
156
|
// `toggle_search_focused`
|
|
138
157
|
// * Toggles focused variable to trigger search input focus
|
|
139
158
|
| { type: 'toggle_search_focused' }
|
|
@@ -170,6 +189,8 @@ const reducers = [
|
|
|
170
189
|
setSearchReducer,
|
|
171
190
|
setSearchResultsReducer,
|
|
172
191
|
setSearchFileVisibilityReducer,
|
|
192
|
+
setSearchLineVisibilityReducer,
|
|
193
|
+
setSearchFocusedIndexReducer,
|
|
173
194
|
toggleSearchFocusedReducer,
|
|
174
195
|
setIsSearchOpenReducer,
|
|
175
196
|
setIsSettingsOpenReducer,
|
|
@@ -58,6 +58,9 @@ export const openTabReducer = (
|
|
|
58
58
|
newTabList = [...activePane.tabList, newTabState];
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
// If the tab is persistent, the editor should focus on the next render.
|
|
62
|
+
const editorWantsFocus = !action.isTransient;
|
|
63
|
+
|
|
61
64
|
return {
|
|
62
65
|
...state,
|
|
63
66
|
pane: updatePane({
|
|
@@ -66,8 +69,6 @@ export const openTabReducer = (
|
|
|
66
69
|
newTabList,
|
|
67
70
|
newActiveFileId: action.fileId,
|
|
68
71
|
}),
|
|
69
|
-
|
|
70
|
-
// If the tab is persistent, the editor should focus on the next render.
|
|
71
|
-
editorWantsFocus: !action.isTransient,
|
|
72
|
+
editorWantsFocus,
|
|
72
73
|
};
|
|
73
74
|
};
|
|
@@ -31,6 +31,7 @@ function searchPattern(
|
|
|
31
31
|
line: j + 1,
|
|
32
32
|
index: index,
|
|
33
33
|
text: lines[j],
|
|
34
|
+
isClosed: false,
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -75,8 +76,11 @@ export const setSearchReducer = (
|
|
|
75
76
|
? {
|
|
76
77
|
...state,
|
|
77
78
|
search: {
|
|
79
|
+
...state.search,
|
|
78
80
|
pattern: action.value,
|
|
79
81
|
results: {},
|
|
82
|
+
focusedIndex: 0,
|
|
83
|
+
focusedChildIndex: null,
|
|
80
84
|
focused: true,
|
|
81
85
|
},
|
|
82
86
|
}
|
|
@@ -90,6 +94,7 @@ export const setSearchResultsReducer = (
|
|
|
90
94
|
? {
|
|
91
95
|
...state,
|
|
92
96
|
search: {
|
|
97
|
+
...state.search,
|
|
93
98
|
pattern: state.search.pattern,
|
|
94
99
|
results: searchPattern(
|
|
95
100
|
action.files,
|
|
@@ -108,13 +113,53 @@ export const setSearchFileVisibilityReducer = (
|
|
|
108
113
|
? {
|
|
109
114
|
...state,
|
|
110
115
|
search: {
|
|
116
|
+
...state.search,
|
|
111
117
|
pattern: state.search.pattern,
|
|
112
118
|
results: updateSearchFileVisibility(
|
|
113
119
|
state.search.results,
|
|
114
120
|
action.id,
|
|
115
121
|
action.visibility,
|
|
116
122
|
),
|
|
117
|
-
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
: state;
|
|
126
|
+
|
|
127
|
+
export const setSearchLineVisibilityReducer = (
|
|
128
|
+
state: VZState,
|
|
129
|
+
action: VZAction,
|
|
130
|
+
): VZState =>
|
|
131
|
+
action.type === 'hide_search_results_line'
|
|
132
|
+
? {
|
|
133
|
+
...state,
|
|
134
|
+
search: {
|
|
135
|
+
...state.search,
|
|
136
|
+
results: {
|
|
137
|
+
...state.search.results,
|
|
138
|
+
[action.id]: {
|
|
139
|
+
...state.search.results[action.id],
|
|
140
|
+
matches: state.search.results[
|
|
141
|
+
action.id
|
|
142
|
+
].matches.filter(
|
|
143
|
+
(match, index) =>
|
|
144
|
+
match.line !== action.line,
|
|
145
|
+
),
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
: state;
|
|
151
|
+
|
|
152
|
+
export const setSearchFocusedIndexReducer = (
|
|
153
|
+
state: VZState,
|
|
154
|
+
action: VZAction,
|
|
155
|
+
): VZState =>
|
|
156
|
+
action.type === 'set_active_search_index'
|
|
157
|
+
? {
|
|
158
|
+
...state,
|
|
159
|
+
search: {
|
|
160
|
+
...state.search,
|
|
161
|
+
focusedIndex: action.focusedIndex,
|
|
162
|
+
focusedChildIndex: action.childIndex,
|
|
118
163
|
},
|
|
119
164
|
}
|
|
120
165
|
: state;
|