@lvce-editor/file-search-worker 7.4.0 → 7.6.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/fileSearchWorkerMain.js +451 -111
- package/package.json +2 -5
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
const EditorWorker = 99;
|
|
2
|
-
const RendererWorker = 1;
|
|
3
|
-
|
|
4
1
|
const normalizeLine = line => {
|
|
5
2
|
if (line.startsWith('Error: ')) {
|
|
6
3
|
return line.slice('Error: '.length);
|
|
@@ -207,6 +204,14 @@ const create$b = rpcId => {
|
|
|
207
204
|
};
|
|
208
205
|
};
|
|
209
206
|
|
|
207
|
+
const EditorWorker = 99;
|
|
208
|
+
const RendererWorker = 1;
|
|
209
|
+
|
|
210
|
+
const SetDom2 = 'Viewlet.setDom2';
|
|
211
|
+
const SetPatches = 'Viewlet.setPatches';
|
|
212
|
+
|
|
213
|
+
const FocusQuickPickInput = 20;
|
|
214
|
+
|
|
210
215
|
const {
|
|
211
216
|
invoke: invoke$2,
|
|
212
217
|
set: set$2
|
|
@@ -273,42 +278,68 @@ const create$a = () => {
|
|
|
273
278
|
const states = Object.create(null);
|
|
274
279
|
const commandMapRef = {};
|
|
275
280
|
return {
|
|
276
|
-
|
|
277
|
-
|
|
281
|
+
clear() {
|
|
282
|
+
for (const key of Object.keys(states)) {
|
|
283
|
+
delete states[key];
|
|
284
|
+
}
|
|
278
285
|
},
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
};
|
|
286
|
+
diff(uid, modules, numbers) {
|
|
287
|
+
const {
|
|
288
|
+
newState,
|
|
289
|
+
oldState
|
|
290
|
+
} = states[uid];
|
|
291
|
+
const diffResult = [];
|
|
292
|
+
for (let i = 0; i < modules.length; i++) {
|
|
293
|
+
const fn = modules[i];
|
|
294
|
+
if (!fn(oldState, newState)) {
|
|
295
|
+
diffResult.push(numbers[i]);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return diffResult;
|
|
284
299
|
},
|
|
285
300
|
dispose(uid) {
|
|
286
301
|
delete states[uid];
|
|
287
302
|
},
|
|
303
|
+
get(uid) {
|
|
304
|
+
return states[uid];
|
|
305
|
+
},
|
|
306
|
+
getCommandIds() {
|
|
307
|
+
const keys = Object.keys(commandMapRef);
|
|
308
|
+
const ids = keys.map(toCommandId);
|
|
309
|
+
return ids;
|
|
310
|
+
},
|
|
288
311
|
getKeys() {
|
|
289
312
|
return Object.keys(states).map(key => {
|
|
290
|
-
return Number.
|
|
313
|
+
return Number.parseFloat(key);
|
|
291
314
|
});
|
|
292
315
|
},
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
316
|
+
registerCommands(commandMap) {
|
|
317
|
+
Object.assign(commandMapRef, commandMap);
|
|
318
|
+
},
|
|
319
|
+
set(uid, oldState, newState) {
|
|
320
|
+
states[uid] = {
|
|
321
|
+
newState,
|
|
322
|
+
oldState
|
|
323
|
+
};
|
|
297
324
|
},
|
|
298
325
|
wrapCommand(fn) {
|
|
299
326
|
const wrapped = async (uid, ...args) => {
|
|
300
327
|
const {
|
|
301
|
-
|
|
302
|
-
|
|
328
|
+
newState,
|
|
329
|
+
oldState
|
|
303
330
|
} = states[uid];
|
|
304
331
|
const newerState = await fn(newState, ...args);
|
|
305
332
|
if (oldState === newerState || newState === newerState) {
|
|
306
333
|
return;
|
|
307
334
|
}
|
|
308
|
-
const
|
|
335
|
+
const latestOld = states[uid];
|
|
336
|
+
const latestNew = {
|
|
337
|
+
...latestOld.newState,
|
|
338
|
+
...newerState
|
|
339
|
+
};
|
|
309
340
|
states[uid] = {
|
|
310
|
-
|
|
311
|
-
|
|
341
|
+
newState: latestNew,
|
|
342
|
+
oldState: latestOld.oldState
|
|
312
343
|
};
|
|
313
344
|
};
|
|
314
345
|
return wrapped;
|
|
@@ -322,27 +353,36 @@ const create$a = () => {
|
|
|
322
353
|
};
|
|
323
354
|
return wrapped;
|
|
324
355
|
},
|
|
325
|
-
|
|
326
|
-
const {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
356
|
+
wrapLoadContent(fn) {
|
|
357
|
+
const wrapped = async (uid, ...args) => {
|
|
358
|
+
const {
|
|
359
|
+
newState,
|
|
360
|
+
oldState
|
|
361
|
+
} = states[uid];
|
|
362
|
+
const result = await fn(newState, ...args);
|
|
363
|
+
const {
|
|
364
|
+
error,
|
|
365
|
+
state
|
|
366
|
+
} = result;
|
|
367
|
+
if (oldState === state || newState === state) {
|
|
368
|
+
return {
|
|
369
|
+
error
|
|
370
|
+
};
|
|
335
371
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
372
|
+
const latestOld = states[uid];
|
|
373
|
+
const latestNew = {
|
|
374
|
+
...latestOld.newState,
|
|
375
|
+
...state
|
|
376
|
+
};
|
|
377
|
+
states[uid] = {
|
|
378
|
+
newState: latestNew,
|
|
379
|
+
oldState: latestOld.oldState
|
|
380
|
+
};
|
|
381
|
+
return {
|
|
382
|
+
error
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
return wrapped;
|
|
346
386
|
}
|
|
347
387
|
};
|
|
348
388
|
};
|
|
@@ -428,6 +468,7 @@ const create$8 = (uid, uri, listItemHeight, x, y, width, height, platform, args,
|
|
|
428
468
|
cursorOffset: 0,
|
|
429
469
|
height: 300,
|
|
430
470
|
icons: [],
|
|
471
|
+
initial: true,
|
|
431
472
|
maxVisibleItems: 12,
|
|
432
473
|
picks: [],
|
|
433
474
|
recentPickIds: Object.create(null),
|
|
@@ -458,28 +499,25 @@ const create$8 = (uid, uri, listItemHeight, x, y, width, height, platform, args,
|
|
|
458
499
|
};
|
|
459
500
|
|
|
460
501
|
const RenderItems = 1;
|
|
502
|
+
const RenderIncremental = 10;
|
|
461
503
|
const RenderFocus = 2;
|
|
462
504
|
const RenderValue = 3;
|
|
463
505
|
const RenderCursorOffset = 7;
|
|
464
506
|
const RenderFocusedIndex = 8;
|
|
465
507
|
const Height = 9;
|
|
466
508
|
|
|
467
|
-
const diffType$4 = RenderFocus;
|
|
468
509
|
const isEqual$4 = (oldState, newState) => {
|
|
469
510
|
return oldState.focused === newState.focused;
|
|
470
511
|
};
|
|
471
512
|
|
|
472
|
-
const diffType$3 = RenderFocusedIndex;
|
|
473
513
|
const isEqual$3 = (oldState, newState) => {
|
|
474
514
|
return oldState.focusedIndex === newState.focusedIndex;
|
|
475
515
|
};
|
|
476
516
|
|
|
477
|
-
const diffType$2 = Height;
|
|
478
517
|
const isEqual$2 = (oldState, newState) => {
|
|
479
518
|
return oldState.items.length === newState.items.length;
|
|
480
519
|
};
|
|
481
520
|
|
|
482
|
-
const diffType$1 = RenderItems;
|
|
483
521
|
const isEqual$1 = (oldState, newState) => {
|
|
484
522
|
return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex;
|
|
485
523
|
};
|
|
@@ -490,7 +528,7 @@ const isEqual = (oldState, newState) => {
|
|
|
490
528
|
};
|
|
491
529
|
|
|
492
530
|
const modules = [isEqual$2, isEqual$1, isEqual, isEqual$3, isEqual$4];
|
|
493
|
-
const numbers = [
|
|
531
|
+
const numbers = [Height, RenderItems, diffType, RenderFocusedIndex, RenderFocus];
|
|
494
532
|
|
|
495
533
|
const diff = (oldState, newState) => {
|
|
496
534
|
const diffResult = [];
|
|
@@ -734,16 +772,6 @@ const focusPrevious = state => {
|
|
|
734
772
|
return focusIndex(state, previousIndex);
|
|
735
773
|
};
|
|
736
774
|
|
|
737
|
-
const Div = 4;
|
|
738
|
-
const Input = 6;
|
|
739
|
-
const Span = 8;
|
|
740
|
-
const Text = 12;
|
|
741
|
-
const Img = 17;
|
|
742
|
-
|
|
743
|
-
const SetDom2 = 'Viewlet.setDom2';
|
|
744
|
-
|
|
745
|
-
const FocusQuickPickInput = 20;
|
|
746
|
-
|
|
747
775
|
const Enter = 3;
|
|
748
776
|
const Escape = 8;
|
|
749
777
|
const PageUp = 10;
|
|
@@ -3133,6 +3161,7 @@ const loadContent = async state => {
|
|
|
3133
3161
|
focused: true,
|
|
3134
3162
|
focusedIndex: 0,
|
|
3135
3163
|
icons,
|
|
3164
|
+
initial: false,
|
|
3136
3165
|
inputSource: Script,
|
|
3137
3166
|
items,
|
|
3138
3167
|
maxLineY,
|
|
@@ -3152,6 +3181,351 @@ const executeCallback = id => {
|
|
|
3152
3181
|
fn();
|
|
3153
3182
|
};
|
|
3154
3183
|
|
|
3184
|
+
const SetCursorOffset = 'setCursorOffset';
|
|
3185
|
+
const SetFocusedIndex = 'setFocusedIndex';
|
|
3186
|
+
const SetItemsHeight = 'setItemsHeight';
|
|
3187
|
+
|
|
3188
|
+
const renderCursorOffset = (_oldState, newState) => {
|
|
3189
|
+
return ['Viewlet.send', newState.uid, /* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
|
|
3190
|
+
};
|
|
3191
|
+
|
|
3192
|
+
const QuickPickInput = 'QuickPickInput';
|
|
3193
|
+
|
|
3194
|
+
const renderFocus = (_oldState, _newState) => {
|
|
3195
|
+
return ['Viewlet.focusElementByName', QuickPickInput];
|
|
3196
|
+
};
|
|
3197
|
+
|
|
3198
|
+
const renderFocusedIndex = (oldState, newState) => {
|
|
3199
|
+
const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
|
|
3200
|
+
const newFocusedIndex = newState.focusedIndex - newState.minLineY;
|
|
3201
|
+
return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */oldFocusedIndex, /* newFocusedIndex */newFocusedIndex];
|
|
3202
|
+
};
|
|
3203
|
+
|
|
3204
|
+
const renderHeight = (_oldState, newState) => {
|
|
3205
|
+
const {
|
|
3206
|
+
height,
|
|
3207
|
+
uid
|
|
3208
|
+
} = newState;
|
|
3209
|
+
if (height === 0) {
|
|
3210
|
+
return ['Viewlet.send', uid, /* method */SetItemsHeight, /* height */20];
|
|
3211
|
+
}
|
|
3212
|
+
return ['Viewlet.send', uid, /* method */SetItemsHeight, /* height */height];
|
|
3213
|
+
};
|
|
3214
|
+
|
|
3215
|
+
const Div = 4;
|
|
3216
|
+
const Input = 6;
|
|
3217
|
+
const Span = 8;
|
|
3218
|
+
const Text = 12;
|
|
3219
|
+
const Img = 17;
|
|
3220
|
+
const Reference = 100;
|
|
3221
|
+
|
|
3222
|
+
const mergeClassNames = (...classNames) => {
|
|
3223
|
+
return classNames.filter(Boolean).join(' ');
|
|
3224
|
+
};
|
|
3225
|
+
|
|
3226
|
+
const px = value => {
|
|
3227
|
+
return `${value}px`;
|
|
3228
|
+
};
|
|
3229
|
+
const position = (x, y) => {
|
|
3230
|
+
return `${x}px ${y}px`;
|
|
3231
|
+
};
|
|
3232
|
+
|
|
3233
|
+
const text = data => {
|
|
3234
|
+
return {
|
|
3235
|
+
childCount: 0,
|
|
3236
|
+
text: data,
|
|
3237
|
+
type: Text
|
|
3238
|
+
};
|
|
3239
|
+
};
|
|
3240
|
+
|
|
3241
|
+
const SetText = 1;
|
|
3242
|
+
const Replace = 2;
|
|
3243
|
+
const SetAttribute = 3;
|
|
3244
|
+
const RemoveAttribute = 4;
|
|
3245
|
+
const Add = 6;
|
|
3246
|
+
const NavigateChild = 7;
|
|
3247
|
+
const NavigateParent = 8;
|
|
3248
|
+
const RemoveChild = 9;
|
|
3249
|
+
const NavigateSibling = 10;
|
|
3250
|
+
const SetReferenceNodeUid = 11;
|
|
3251
|
+
|
|
3252
|
+
const isKey = key => {
|
|
3253
|
+
return key !== 'type' && key !== 'childCount';
|
|
3254
|
+
};
|
|
3255
|
+
|
|
3256
|
+
const getKeys = node => {
|
|
3257
|
+
const keys = Object.keys(node).filter(isKey);
|
|
3258
|
+
return keys;
|
|
3259
|
+
};
|
|
3260
|
+
|
|
3261
|
+
const arrayToTree = nodes => {
|
|
3262
|
+
const result = [];
|
|
3263
|
+
let i = 0;
|
|
3264
|
+
while (i < nodes.length) {
|
|
3265
|
+
const node = nodes[i];
|
|
3266
|
+
const {
|
|
3267
|
+
children,
|
|
3268
|
+
nodesConsumed
|
|
3269
|
+
} = getChildrenWithCount(nodes, i + 1, node.childCount || 0);
|
|
3270
|
+
result.push({
|
|
3271
|
+
node,
|
|
3272
|
+
children
|
|
3273
|
+
});
|
|
3274
|
+
i += 1 + nodesConsumed;
|
|
3275
|
+
}
|
|
3276
|
+
return result;
|
|
3277
|
+
};
|
|
3278
|
+
const getChildrenWithCount = (nodes, startIndex, childCount) => {
|
|
3279
|
+
if (childCount === 0) {
|
|
3280
|
+
return {
|
|
3281
|
+
children: [],
|
|
3282
|
+
nodesConsumed: 0
|
|
3283
|
+
};
|
|
3284
|
+
}
|
|
3285
|
+
const children = [];
|
|
3286
|
+
let i = startIndex;
|
|
3287
|
+
let remaining = childCount;
|
|
3288
|
+
let totalConsumed = 0;
|
|
3289
|
+
while (remaining > 0 && i < nodes.length) {
|
|
3290
|
+
const node = nodes[i];
|
|
3291
|
+
const nodeChildCount = node.childCount || 0;
|
|
3292
|
+
const {
|
|
3293
|
+
children: nodeChildren,
|
|
3294
|
+
nodesConsumed
|
|
3295
|
+
} = getChildrenWithCount(nodes, i + 1, nodeChildCount);
|
|
3296
|
+
children.push({
|
|
3297
|
+
node,
|
|
3298
|
+
children: nodeChildren
|
|
3299
|
+
});
|
|
3300
|
+
const nodeSize = 1 + nodesConsumed;
|
|
3301
|
+
i += nodeSize;
|
|
3302
|
+
totalConsumed += nodeSize;
|
|
3303
|
+
remaining--;
|
|
3304
|
+
}
|
|
3305
|
+
return {
|
|
3306
|
+
children,
|
|
3307
|
+
nodesConsumed: totalConsumed
|
|
3308
|
+
};
|
|
3309
|
+
};
|
|
3310
|
+
|
|
3311
|
+
const compareNodes = (oldNode, newNode) => {
|
|
3312
|
+
const patches = [];
|
|
3313
|
+
// Check if node type changed - return null to signal incompatible nodes
|
|
3314
|
+
// (caller should handle this with a Replace operation)
|
|
3315
|
+
if (oldNode.type !== newNode.type) {
|
|
3316
|
+
return null;
|
|
3317
|
+
}
|
|
3318
|
+
// Handle reference nodes - special handling for uid changes
|
|
3319
|
+
if (oldNode.type === Reference) {
|
|
3320
|
+
if (oldNode.uid !== newNode.uid) {
|
|
3321
|
+
patches.push({
|
|
3322
|
+
type: SetReferenceNodeUid,
|
|
3323
|
+
uid: newNode.uid
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
return patches;
|
|
3327
|
+
}
|
|
3328
|
+
// Handle text nodes
|
|
3329
|
+
if (oldNode.type === Text && newNode.type === Text) {
|
|
3330
|
+
if (oldNode.text !== newNode.text) {
|
|
3331
|
+
patches.push({
|
|
3332
|
+
type: SetText,
|
|
3333
|
+
value: newNode.text
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3336
|
+
return patches;
|
|
3337
|
+
}
|
|
3338
|
+
// Compare attributes
|
|
3339
|
+
const oldKeys = getKeys(oldNode);
|
|
3340
|
+
const newKeys = getKeys(newNode);
|
|
3341
|
+
// Check for attribute changes
|
|
3342
|
+
for (const key of newKeys) {
|
|
3343
|
+
if (oldNode[key] !== newNode[key]) {
|
|
3344
|
+
patches.push({
|
|
3345
|
+
type: SetAttribute,
|
|
3346
|
+
key,
|
|
3347
|
+
value: newNode[key]
|
|
3348
|
+
});
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
// Check for removed attributes
|
|
3352
|
+
for (const key of oldKeys) {
|
|
3353
|
+
if (!(key in newNode)) {
|
|
3354
|
+
patches.push({
|
|
3355
|
+
type: RemoveAttribute,
|
|
3356
|
+
key
|
|
3357
|
+
});
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
return patches;
|
|
3361
|
+
};
|
|
3362
|
+
|
|
3363
|
+
const treeToArray = node => {
|
|
3364
|
+
const result = [node.node];
|
|
3365
|
+
for (const child of node.children) {
|
|
3366
|
+
result.push(...treeToArray(child));
|
|
3367
|
+
}
|
|
3368
|
+
return result;
|
|
3369
|
+
};
|
|
3370
|
+
|
|
3371
|
+
const diffChildren = (oldChildren, newChildren, patches) => {
|
|
3372
|
+
const maxLength = Math.max(oldChildren.length, newChildren.length);
|
|
3373
|
+
// Track where we are: -1 means at parent, >= 0 means at child index
|
|
3374
|
+
let currentChildIndex = -1;
|
|
3375
|
+
// Collect indices of children to remove (we'll add these patches at the end in reverse order)
|
|
3376
|
+
const indicesToRemove = [];
|
|
3377
|
+
for (let i = 0; i < maxLength; i++) {
|
|
3378
|
+
const oldNode = oldChildren[i];
|
|
3379
|
+
const newNode = newChildren[i];
|
|
3380
|
+
if (!oldNode && !newNode) {
|
|
3381
|
+
continue;
|
|
3382
|
+
}
|
|
3383
|
+
if (!oldNode) {
|
|
3384
|
+
// Add new node - we should be at the parent
|
|
3385
|
+
if (currentChildIndex >= 0) {
|
|
3386
|
+
// Navigate back to parent
|
|
3387
|
+
patches.push({
|
|
3388
|
+
type: NavigateParent
|
|
3389
|
+
});
|
|
3390
|
+
currentChildIndex = -1;
|
|
3391
|
+
}
|
|
3392
|
+
// Flatten the entire subtree so renderInternal can handle it
|
|
3393
|
+
const flatNodes = treeToArray(newNode);
|
|
3394
|
+
patches.push({
|
|
3395
|
+
type: Add,
|
|
3396
|
+
nodes: flatNodes
|
|
3397
|
+
});
|
|
3398
|
+
} else if (newNode) {
|
|
3399
|
+
// Compare nodes to see if we need any patches
|
|
3400
|
+
const nodePatches = compareNodes(oldNode.node, newNode.node);
|
|
3401
|
+
// If nodePatches is null, the node types are incompatible - need to replace
|
|
3402
|
+
if (nodePatches === null) {
|
|
3403
|
+
// Navigate to this child
|
|
3404
|
+
if (currentChildIndex === -1) {
|
|
3405
|
+
patches.push({
|
|
3406
|
+
type: NavigateChild,
|
|
3407
|
+
index: i
|
|
3408
|
+
});
|
|
3409
|
+
currentChildIndex = i;
|
|
3410
|
+
} else if (currentChildIndex !== i) {
|
|
3411
|
+
patches.push({
|
|
3412
|
+
type: NavigateSibling,
|
|
3413
|
+
index: i
|
|
3414
|
+
});
|
|
3415
|
+
currentChildIndex = i;
|
|
3416
|
+
}
|
|
3417
|
+
// Replace the entire subtree
|
|
3418
|
+
const flatNodes = treeToArray(newNode);
|
|
3419
|
+
patches.push({
|
|
3420
|
+
type: Replace,
|
|
3421
|
+
nodes: flatNodes
|
|
3422
|
+
});
|
|
3423
|
+
// After replace, we're at the new element (same position)
|
|
3424
|
+
continue;
|
|
3425
|
+
}
|
|
3426
|
+
// Check if we need to recurse into children
|
|
3427
|
+
const hasChildrenToCompare = oldNode.children.length > 0 || newNode.children.length > 0;
|
|
3428
|
+
// Only navigate to this element if we need to do something
|
|
3429
|
+
if (nodePatches.length > 0 || hasChildrenToCompare) {
|
|
3430
|
+
// Navigate to this child if not already there
|
|
3431
|
+
if (currentChildIndex === -1) {
|
|
3432
|
+
patches.push({
|
|
3433
|
+
type: NavigateChild,
|
|
3434
|
+
index: i
|
|
3435
|
+
});
|
|
3436
|
+
currentChildIndex = i;
|
|
3437
|
+
} else if (currentChildIndex !== i) {
|
|
3438
|
+
patches.push({
|
|
3439
|
+
type: NavigateSibling,
|
|
3440
|
+
index: i
|
|
3441
|
+
});
|
|
3442
|
+
currentChildIndex = i;
|
|
3443
|
+
}
|
|
3444
|
+
// Apply node patches (these apply to the current element, not children)
|
|
3445
|
+
if (nodePatches.length > 0) {
|
|
3446
|
+
patches.push(...nodePatches);
|
|
3447
|
+
}
|
|
3448
|
+
// Compare children recursively
|
|
3449
|
+
if (hasChildrenToCompare) {
|
|
3450
|
+
diffChildren(oldNode.children, newNode.children, patches);
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
} else {
|
|
3454
|
+
// Remove old node - collect the index for later removal
|
|
3455
|
+
indicesToRemove.push(i);
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
// Navigate back to parent if we ended at a child
|
|
3459
|
+
if (currentChildIndex >= 0) {
|
|
3460
|
+
patches.push({
|
|
3461
|
+
type: NavigateParent
|
|
3462
|
+
});
|
|
3463
|
+
currentChildIndex = -1;
|
|
3464
|
+
}
|
|
3465
|
+
// Add remove patches in reverse order (highest index first)
|
|
3466
|
+
// This ensures indices remain valid as we remove
|
|
3467
|
+
for (let j = indicesToRemove.length - 1; j >= 0; j--) {
|
|
3468
|
+
patches.push({
|
|
3469
|
+
type: RemoveChild,
|
|
3470
|
+
index: indicesToRemove[j]
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
};
|
|
3474
|
+
const diffTrees = (oldTree, newTree, patches, path) => {
|
|
3475
|
+
// At the root level (path.length === 0), we're already AT the element
|
|
3476
|
+
// So we compare the root node directly, then compare its children
|
|
3477
|
+
if (path.length === 0 && oldTree.length === 1 && newTree.length === 1) {
|
|
3478
|
+
const oldNode = oldTree[0];
|
|
3479
|
+
const newNode = newTree[0];
|
|
3480
|
+
// Compare root nodes
|
|
3481
|
+
const nodePatches = compareNodes(oldNode.node, newNode.node);
|
|
3482
|
+
// If nodePatches is null, the root node types are incompatible - need to replace
|
|
3483
|
+
if (nodePatches === null) {
|
|
3484
|
+
const flatNodes = treeToArray(newNode);
|
|
3485
|
+
patches.push({
|
|
3486
|
+
type: Replace,
|
|
3487
|
+
nodes: flatNodes
|
|
3488
|
+
});
|
|
3489
|
+
return;
|
|
3490
|
+
}
|
|
3491
|
+
if (nodePatches.length > 0) {
|
|
3492
|
+
patches.push(...nodePatches);
|
|
3493
|
+
}
|
|
3494
|
+
// Compare children
|
|
3495
|
+
if (oldNode.children.length > 0 || newNode.children.length > 0) {
|
|
3496
|
+
diffChildren(oldNode.children, newNode.children, patches);
|
|
3497
|
+
}
|
|
3498
|
+
} else {
|
|
3499
|
+
// Non-root level or multiple root elements - use the regular comparison
|
|
3500
|
+
diffChildren(oldTree, newTree, patches);
|
|
3501
|
+
}
|
|
3502
|
+
};
|
|
3503
|
+
|
|
3504
|
+
const removeTrailingNavigationPatches = patches => {
|
|
3505
|
+
// Find the last non-navigation patch
|
|
3506
|
+
let lastNonNavigationIndex = -1;
|
|
3507
|
+
for (let i = patches.length - 1; i >= 0; i--) {
|
|
3508
|
+
const patch = patches[i];
|
|
3509
|
+
if (patch.type !== NavigateChild && patch.type !== NavigateParent && patch.type !== NavigateSibling) {
|
|
3510
|
+
lastNonNavigationIndex = i;
|
|
3511
|
+
break;
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
// Return patches up to and including the last non-navigation patch
|
|
3515
|
+
return lastNonNavigationIndex === -1 ? [] : patches.slice(0, lastNonNavigationIndex + 1);
|
|
3516
|
+
};
|
|
3517
|
+
|
|
3518
|
+
const diffTree = (oldNodes, newNodes) => {
|
|
3519
|
+
// Step 1: Convert flat arrays to tree structures
|
|
3520
|
+
const oldTree = arrayToTree(oldNodes);
|
|
3521
|
+
const newTree = arrayToTree(newNodes);
|
|
3522
|
+
// Step 3: Compare the trees
|
|
3523
|
+
const patches = [];
|
|
3524
|
+
diffTrees(oldTree, newTree, patches, []);
|
|
3525
|
+
// Remove trailing navigation patches since they serve no purpose
|
|
3526
|
+
return removeTrailingNavigationPatches(patches);
|
|
3527
|
+
};
|
|
3528
|
+
|
|
3155
3529
|
const getVisible$1 = (items, minLineY, maxLineY, icons) => {
|
|
3156
3530
|
const range = items.slice(minLineY, maxLineY);
|
|
3157
3531
|
const protoVisibleItems = range.map((item, index) => {
|
|
@@ -3226,7 +3600,7 @@ const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
|
|
|
3226
3600
|
};
|
|
3227
3601
|
const getScrollBarY = getScrollBarOffset;
|
|
3228
3602
|
|
|
3229
|
-
const createQuickPickViewModel =
|
|
3603
|
+
const createQuickPickViewModel = newState => {
|
|
3230
3604
|
const {
|
|
3231
3605
|
cursorOffset,
|
|
3232
3606
|
deltaY,
|
|
@@ -3246,7 +3620,6 @@ const createQuickPickViewModel = (oldState, newState) => {
|
|
|
3246
3620
|
} = newState;
|
|
3247
3621
|
const protoVisibleItems = getVisible$1(items, minLineY, maxLineY, icons);
|
|
3248
3622
|
const visibleItems = getVisible(items.length, protoVisibleItems, minLineY, focusedIndex);
|
|
3249
|
-
const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
|
|
3250
3623
|
const newFocusedIndex = focusedIndex - minLineY;
|
|
3251
3624
|
const itemCount = items.length;
|
|
3252
3625
|
const listHeight = getListHeight(itemCount, itemHeight, height);
|
|
@@ -3259,7 +3632,6 @@ const createQuickPickViewModel = (oldState, newState) => {
|
|
|
3259
3632
|
focused,
|
|
3260
3633
|
height,
|
|
3261
3634
|
newFocusedIndex,
|
|
3262
|
-
oldFocusedIndex,
|
|
3263
3635
|
scrollBarHeight,
|
|
3264
3636
|
scrollBarTop: roundedScrollBarY,
|
|
3265
3637
|
uid,
|
|
@@ -3268,54 +3640,6 @@ const createQuickPickViewModel = (oldState, newState) => {
|
|
|
3268
3640
|
};
|
|
3269
3641
|
};
|
|
3270
3642
|
|
|
3271
|
-
const SetCursorOffset = 'setCursorOffset';
|
|
3272
|
-
const SetFocusedIndex = 'setFocusedIndex';
|
|
3273
|
-
const SetItemsHeight = 'setItemsHeight';
|
|
3274
|
-
|
|
3275
|
-
const renderCursorOffset = newState => {
|
|
3276
|
-
return ['Viewlet.send', newState.uid, /* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
|
|
3277
|
-
};
|
|
3278
|
-
|
|
3279
|
-
const QuickPickInput = 'QuickPickInput';
|
|
3280
|
-
|
|
3281
|
-
const renderFocus = newState => {
|
|
3282
|
-
return ['Viewlet.focusElementByName', QuickPickInput];
|
|
3283
|
-
};
|
|
3284
|
-
|
|
3285
|
-
const renderFocusedIndex = newState => {
|
|
3286
|
-
return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */newState.oldFocusedIndex, /* newFocusedIndex */newState.newFocusedIndex];
|
|
3287
|
-
};
|
|
3288
|
-
|
|
3289
|
-
const renderHeight = newState => {
|
|
3290
|
-
const {
|
|
3291
|
-
height,
|
|
3292
|
-
uid
|
|
3293
|
-
} = newState;
|
|
3294
|
-
if (height === 0) {
|
|
3295
|
-
return ['Viewlet.send', uid, /* method */SetItemsHeight, /* height */20];
|
|
3296
|
-
}
|
|
3297
|
-
return ['Viewlet.send', uid, /* method */SetItemsHeight, /* height */height];
|
|
3298
|
-
};
|
|
3299
|
-
|
|
3300
|
-
const mergeClassNames = (...classNames) => {
|
|
3301
|
-
return classNames.filter(Boolean).join(' ');
|
|
3302
|
-
};
|
|
3303
|
-
|
|
3304
|
-
const px = value => {
|
|
3305
|
-
return `${value}px`;
|
|
3306
|
-
};
|
|
3307
|
-
const position = (x, y) => {
|
|
3308
|
-
return `${x}px ${y}px`;
|
|
3309
|
-
};
|
|
3310
|
-
|
|
3311
|
-
const text = data => {
|
|
3312
|
-
return {
|
|
3313
|
-
childCount: 0,
|
|
3314
|
-
text: data,
|
|
3315
|
-
type: Text
|
|
3316
|
-
};
|
|
3317
|
-
};
|
|
3318
|
-
|
|
3319
3643
|
const ComboBox = 'combobox';
|
|
3320
3644
|
const ListBox = 'listbox';
|
|
3321
3645
|
const None = 'none';
|
|
@@ -3536,17 +3860,32 @@ const getQuickPickVirtualDom = (visibleItems, scrollBarHeight, scrollBarTop) =>
|
|
|
3536
3860
|
}, ...getQuickPickItemsVirtualDom(visibleItems), ...getScrollBarVirtualDom(scrollBarHeight, scrollBarTop)];
|
|
3537
3861
|
};
|
|
3538
3862
|
|
|
3539
|
-
const
|
|
3863
|
+
const getItemsDom = newState => {
|
|
3864
|
+
const viewModel = createQuickPickViewModel(newState);
|
|
3540
3865
|
const {
|
|
3541
3866
|
scrollBarHeight,
|
|
3542
3867
|
scrollBarTop,
|
|
3543
3868
|
visibleItems
|
|
3544
|
-
} =
|
|
3869
|
+
} = viewModel;
|
|
3545
3870
|
const dom = getQuickPickVirtualDom(visibleItems, scrollBarHeight, scrollBarTop);
|
|
3871
|
+
return dom;
|
|
3872
|
+
};
|
|
3873
|
+
const renderItems = (_oldState, newState) => {
|
|
3874
|
+
const dom = getItemsDom(newState);
|
|
3546
3875
|
return [SetDom2, dom];
|
|
3547
3876
|
};
|
|
3548
3877
|
|
|
3549
|
-
const
|
|
3878
|
+
const renderIncremental = (oldState, newState) => {
|
|
3879
|
+
const oldDom = getItemsDom(oldState);
|
|
3880
|
+
const newDom = getItemsDom(newState);
|
|
3881
|
+
if (oldState.initial) {
|
|
3882
|
+
return [SetDom2, newState.uid, newDom];
|
|
3883
|
+
}
|
|
3884
|
+
const patches = diffTree(oldDom, newDom);
|
|
3885
|
+
return [SetPatches, newState.uid, patches];
|
|
3886
|
+
};
|
|
3887
|
+
|
|
3888
|
+
const renderValue = (_oldState, newState) => {
|
|
3550
3889
|
return ['Viewlet.setValueByName', QuickPickInput, /* value */newState.value];
|
|
3551
3890
|
};
|
|
3552
3891
|
|
|
@@ -3560,6 +3899,8 @@ const getRenderer = diffType => {
|
|
|
3560
3899
|
return renderFocus;
|
|
3561
3900
|
case RenderFocusedIndex:
|
|
3562
3901
|
return renderFocusedIndex;
|
|
3902
|
+
case RenderIncremental:
|
|
3903
|
+
return renderIncremental;
|
|
3563
3904
|
case RenderItems:
|
|
3564
3905
|
return renderItems;
|
|
3565
3906
|
case RenderValue:
|
|
@@ -3571,7 +3912,6 @@ const getRenderer = diffType => {
|
|
|
3571
3912
|
|
|
3572
3913
|
const applyRender = (oldState, newState, diffResult) => {
|
|
3573
3914
|
const commands = [];
|
|
3574
|
-
const viewModel = createQuickPickViewModel(oldState, newState);
|
|
3575
3915
|
for (const item of diffResult) {
|
|
3576
3916
|
if (item === Height) {
|
|
3577
3917
|
continue;
|
|
@@ -3580,7 +3920,7 @@ const applyRender = (oldState, newState, diffResult) => {
|
|
|
3580
3920
|
continue;
|
|
3581
3921
|
}
|
|
3582
3922
|
const fn = getRenderer(item);
|
|
3583
|
-
commands.push(fn(
|
|
3923
|
+
commands.push(fn(oldState, newState));
|
|
3584
3924
|
}
|
|
3585
3925
|
return commands;
|
|
3586
3926
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/file-search-worker",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.6.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"text-search"
|
|
6
6
|
],
|
|
@@ -11,8 +11,5 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"author": "Lvce Editor",
|
|
13
13
|
"type": "module",
|
|
14
|
-
"main": "dist/fileSearchWorkerMain.js"
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"@lvce-editor/constants": "^2.9.0"
|
|
17
|
-
}
|
|
14
|
+
"main": "dist/fileSearchWorkerMain.js"
|
|
18
15
|
}
|