vzcode 2.34.0 → 2.35.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-nL6to42p.js → index-rg2Zvfo_.js} +131 -131
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/client/VZCodeContext/chatSessionHelpers.ts +17 -0
- package/src/client/VZCodeContext/useAIChatSession.ts +325 -0
- package/src/client/VZCodeContext/useVZCodeState.ts +23 -279
- package/src/client/VZSidebar/VisualEditor/VisualEditor.tsx +85 -202
- package/src/client/VZSidebar/VisualEditor/colorUtils.ts +25 -0
- package/src/client/VZSidebar/VisualEditor/status.ts +2 -40
- package/src/client/VZSidebar/VisualEditor/updateConfig.ts +10 -1
- package/src/client/VZSidebar/VisualEditor/utils.ts +49 -65
- package/src/client/definitionJumpListeners.ts +47 -0
- package/src/client/useKeyboardShortcuts.ts +23 -28
|
@@ -7,18 +7,13 @@ import { EditorState } from '@codemirror/state';
|
|
|
7
7
|
import { VizFileId } from '@vizhub/viz-types';
|
|
8
8
|
import { PaneId } from '../types';
|
|
9
9
|
import { editorCacheKey } from './useEditorCache';
|
|
10
|
+
import { createDefinitionJumpListeners } from './definitionJumpListeners';
|
|
10
11
|
|
|
11
12
|
/*
|
|
12
13
|
The following is a helpful resource for the following Code Mirror Syntax Tree methods below
|
|
13
14
|
https://lezer.codemirror.net/docs/ref/#common
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
|
-
// Store the element in the current editor DOM to highlight, indicating a potential jump to definition is possible
|
|
17
|
-
let activeJumpingElement: HTMLSpanElement = null;
|
|
18
|
-
|
|
19
|
-
// Store the syntax node representing the destination within the syntax tree
|
|
20
|
-
let definingNode: SyntaxNode = null;
|
|
21
|
-
|
|
22
17
|
// Example nesting types for the specific language to find level in the syntax tree
|
|
23
18
|
const nestingTypes = new Set<string>([
|
|
24
19
|
'FunctionDeclaration',
|
|
@@ -207,6 +202,9 @@ export const useKeyboardShortcuts = ({
|
|
|
207
202
|
activeFileId,
|
|
208
203
|
activePaneId,
|
|
209
204
|
);
|
|
205
|
+
// Each mounted editor owns its jump target and listeners.
|
|
206
|
+
let activeJumpingElement: HTMLSpanElement | null = null;
|
|
207
|
+
let definingNode: SyntaxNode | null = null;
|
|
210
208
|
|
|
211
209
|
const handleKeyPress = (event: KeyboardEvent) => {
|
|
212
210
|
if (shouldTriggerRun(event)) {
|
|
@@ -245,10 +243,7 @@ export const useKeyboardShortcuts = ({
|
|
|
245
243
|
|
|
246
244
|
if (event.ctrlKey === true) {
|
|
247
245
|
// On holding CTRL key, search for a potential definition jump using mouse location
|
|
248
|
-
|
|
249
|
-
'mouseover',
|
|
250
|
-
handleMouseOver,
|
|
251
|
-
);
|
|
246
|
+
jumpListeners.start();
|
|
252
247
|
}
|
|
253
248
|
|
|
254
249
|
if (event.altKey === true) {
|
|
@@ -299,17 +294,11 @@ export const useKeyboardShortcuts = ({
|
|
|
299
294
|
if (activeJumpingElement) {
|
|
300
295
|
activeJumpingElement.style.cursor = 'initial';
|
|
301
296
|
activeJumpingElement.style.textDecoration = 'none';
|
|
302
|
-
activeJumpingElement =
|
|
297
|
+
activeJumpingElement = null;
|
|
298
|
+
definingNode = null;
|
|
303
299
|
}
|
|
304
300
|
|
|
305
|
-
|
|
306
|
-
'mouseover',
|
|
307
|
-
handleMouseOver,
|
|
308
|
-
);
|
|
309
|
-
document.removeEventListener(
|
|
310
|
-
'mousedown',
|
|
311
|
-
jumpToDefinitionHandler,
|
|
312
|
-
);
|
|
301
|
+
jumpListeners.stop();
|
|
313
302
|
};
|
|
314
303
|
|
|
315
304
|
const jumpToDefinitionHandler = (
|
|
@@ -332,8 +321,11 @@ export const useKeyboardShortcuts = ({
|
|
|
332
321
|
|
|
333
322
|
// Move current cursor and center view in the editor to destination node
|
|
334
323
|
|
|
335
|
-
const editor
|
|
336
|
-
|
|
324
|
+
const editor = editorCache.get(cacheKey)?.editor;
|
|
325
|
+
if (!editor) {
|
|
326
|
+
resetActiveJumpingElement();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
337
329
|
const closestDefinition: SyntaxNode = definingNode;
|
|
338
330
|
|
|
339
331
|
editor.dispatch({
|
|
@@ -365,8 +357,8 @@ export const useKeyboardShortcuts = ({
|
|
|
365
357
|
return;
|
|
366
358
|
}
|
|
367
359
|
|
|
368
|
-
const editor
|
|
369
|
-
|
|
360
|
+
const editor = editorCache.get(cacheKey)?.editor;
|
|
361
|
+
if (!editor) return;
|
|
370
362
|
const tree = syntaxTree(editor.state);
|
|
371
363
|
const element = event.target as HTMLSpanElement;
|
|
372
364
|
|
|
@@ -423,19 +415,22 @@ export const useKeyboardShortcuts = ({
|
|
|
423
415
|
'underline';
|
|
424
416
|
|
|
425
417
|
// CTRL + Click: Jump to relative definition, which is removed on CTRL key release
|
|
426
|
-
|
|
427
|
-
'mousedown',
|
|
428
|
-
jumpToDefinitionHandler,
|
|
429
|
-
{ once: true },
|
|
430
|
-
);
|
|
418
|
+
jumpListeners.armClick();
|
|
431
419
|
}
|
|
432
420
|
}
|
|
433
421
|
};
|
|
434
422
|
|
|
423
|
+
const jumpListeners = createDefinitionJumpListeners(
|
|
424
|
+
document,
|
|
425
|
+
handleMouseOver,
|
|
426
|
+
jumpToDefinitionHandler,
|
|
427
|
+
);
|
|
428
|
+
|
|
435
429
|
document.addEventListener('keydown', handleKeyPress);
|
|
436
430
|
document.addEventListener('keyup', handleKeyRelease);
|
|
437
431
|
|
|
438
432
|
return () => {
|
|
433
|
+
resetActiveJumpingElement();
|
|
439
434
|
document.removeEventListener(
|
|
440
435
|
'keydown',
|
|
441
436
|
handleKeyPress,
|