@lvce-editor/quick-pick-worker 4.0.0 → 4.2.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/quickPickWorkerMain.js +115 -21
- package/package.json +1 -1
|
@@ -1290,6 +1290,18 @@ const toCommandId = key => {
|
|
|
1290
1290
|
const create$2 = () => {
|
|
1291
1291
|
const states = Object.create(null);
|
|
1292
1292
|
const commandMapRef = {};
|
|
1293
|
+
const updateState = (uid, updater) => {
|
|
1294
|
+
const current = states[uid];
|
|
1295
|
+
const updatedState = updater(current.newState);
|
|
1296
|
+
if (updatedState !== current.newState) {
|
|
1297
|
+
states[uid] = {
|
|
1298
|
+
newState: updatedState,
|
|
1299
|
+
oldState: current.oldState,
|
|
1300
|
+
scheduledState: updatedState
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
return Promise.resolve(updatedState);
|
|
1304
|
+
};
|
|
1293
1305
|
return {
|
|
1294
1306
|
clear() {
|
|
1295
1307
|
for (const key of Object.keys(states)) {
|
|
@@ -1298,13 +1310,13 @@ const create$2 = () => {
|
|
|
1298
1310
|
},
|
|
1299
1311
|
diff(uid, modules, numbers) {
|
|
1300
1312
|
const {
|
|
1301
|
-
|
|
1302
|
-
|
|
1313
|
+
oldState,
|
|
1314
|
+
scheduledState
|
|
1303
1315
|
} = states[uid];
|
|
1304
1316
|
const diffResult = [];
|
|
1305
1317
|
for (let i = 0; i < modules.length; i++) {
|
|
1306
1318
|
const fn = modules[i];
|
|
1307
|
-
if (!fn(oldState,
|
|
1319
|
+
if (!fn(oldState, scheduledState)) {
|
|
1308
1320
|
diffResult.push(numbers[i]);
|
|
1309
1321
|
}
|
|
1310
1322
|
}
|
|
@@ -1322,18 +1334,27 @@ const create$2 = () => {
|
|
|
1322
1334
|
return ids;
|
|
1323
1335
|
},
|
|
1324
1336
|
getKeys() {
|
|
1325
|
-
return Object.keys(states).map(
|
|
1326
|
-
return Number.parseFloat(key);
|
|
1327
|
-
});
|
|
1337
|
+
return Object.keys(states).map(Number);
|
|
1328
1338
|
},
|
|
1329
1339
|
registerCommands(commandMap) {
|
|
1330
1340
|
Object.assign(commandMapRef, commandMap);
|
|
1331
1341
|
},
|
|
1332
|
-
set(uid, oldState, newState) {
|
|
1342
|
+
set(uid, oldState, newState, scheduledState) {
|
|
1333
1343
|
states[uid] = {
|
|
1334
1344
|
newState,
|
|
1335
|
-
oldState
|
|
1345
|
+
oldState,
|
|
1346
|
+
scheduledState: scheduledState ?? newState
|
|
1347
|
+
};
|
|
1348
|
+
},
|
|
1349
|
+
wrapAsyncCommand(fn) {
|
|
1350
|
+
const wrapped = async (uid, ...args) => {
|
|
1351
|
+
const context = {
|
|
1352
|
+
getState: () => states[uid].newState,
|
|
1353
|
+
updateState: updater => updateState(uid, updater)
|
|
1354
|
+
};
|
|
1355
|
+
await fn(context, ...args);
|
|
1336
1356
|
};
|
|
1357
|
+
return wrapped;
|
|
1337
1358
|
},
|
|
1338
1359
|
wrapCommand(fn) {
|
|
1339
1360
|
const wrapped = async (uid, ...args) => {
|
|
@@ -1352,7 +1373,8 @@ const create$2 = () => {
|
|
|
1352
1373
|
};
|
|
1353
1374
|
states[uid] = {
|
|
1354
1375
|
newState: latestNew,
|
|
1355
|
-
oldState: latestOld.oldState
|
|
1376
|
+
oldState: latestOld.oldState,
|
|
1377
|
+
scheduledState: latestNew
|
|
1356
1378
|
};
|
|
1357
1379
|
};
|
|
1358
1380
|
return wrapped;
|
|
@@ -1389,7 +1411,8 @@ const create$2 = () => {
|
|
|
1389
1411
|
};
|
|
1390
1412
|
states[uid] = {
|
|
1391
1413
|
newState: latestNew,
|
|
1392
|
-
oldState: latestOld.oldState
|
|
1414
|
+
oldState: latestOld.oldState,
|
|
1415
|
+
scheduledState: latestNew
|
|
1393
1416
|
};
|
|
1394
1417
|
return {
|
|
1395
1418
|
error
|
|
@@ -1406,6 +1429,7 @@ const {
|
|
|
1406
1429
|
getCommandIds,
|
|
1407
1430
|
registerCommands,
|
|
1408
1431
|
set: set$1,
|
|
1432
|
+
wrapAsyncCommand,
|
|
1409
1433
|
wrapCommand
|
|
1410
1434
|
} = create$2();
|
|
1411
1435
|
|
|
@@ -1579,7 +1603,7 @@ const handleScrollBarPointerUp = (state, pointerId) => {
|
|
|
1579
1603
|
};
|
|
1580
1604
|
};
|
|
1581
1605
|
|
|
1582
|
-
const create = (uid, uri, listItemHeight, x, y, width, height, platform, args, workspaceUri, assetDir) => {
|
|
1606
|
+
const create = (uid, uri, listItemHeight, x, y, width, height, platform, args, _renderAllItems, workspaceUri, assetDir) => {
|
|
1583
1607
|
const state = {
|
|
1584
1608
|
allowEmptyResult: false,
|
|
1585
1609
|
cursorOffset: 0,
|
|
@@ -2710,6 +2734,9 @@ const parseGotoline = value => {
|
|
|
2710
2734
|
if (Number.isNaN(wantedLine)) {
|
|
2711
2735
|
return -1;
|
|
2712
2736
|
}
|
|
2737
|
+
if (wantedLine < 1) {
|
|
2738
|
+
return -1;
|
|
2739
|
+
}
|
|
2713
2740
|
return wantedLine;
|
|
2714
2741
|
};
|
|
2715
2742
|
|
|
@@ -3093,6 +3120,10 @@ const getQuickPickSubProviderId = (id, prefix) => {
|
|
|
3093
3120
|
}
|
|
3094
3121
|
};
|
|
3095
3122
|
|
|
3123
|
+
const requestVersions = new Map();
|
|
3124
|
+
const requestVersionGenerator = {
|
|
3125
|
+
value: 0
|
|
3126
|
+
};
|
|
3096
3127
|
const isQuickInput = args => {
|
|
3097
3128
|
const options = args.at(-1);
|
|
3098
3129
|
return options?.mode === 'quickInput';
|
|
@@ -3143,6 +3174,51 @@ const setValue = async (state, newValue) => {
|
|
|
3143
3174
|
value: newValue
|
|
3144
3175
|
};
|
|
3145
3176
|
};
|
|
3177
|
+
const setValueWithContext = async (context, newValue) => {
|
|
3178
|
+
const state = context.getState();
|
|
3179
|
+
if (state.value === newValue) {
|
|
3180
|
+
return;
|
|
3181
|
+
}
|
|
3182
|
+
const requestVersion = ++requestVersionGenerator.value;
|
|
3183
|
+
requestVersions.set(state.uid, requestVersion);
|
|
3184
|
+
const result = await setValue(state, newValue);
|
|
3185
|
+
await context.updateState(latestState => {
|
|
3186
|
+
if (requestVersions.get(latestState.uid) !== requestVersion) {
|
|
3187
|
+
return latestState;
|
|
3188
|
+
}
|
|
3189
|
+
return {
|
|
3190
|
+
...latestState,
|
|
3191
|
+
fileIconCache: result.fileIconCache,
|
|
3192
|
+
finalDeltaY: result.finalDeltaY,
|
|
3193
|
+
focusedIndex: result.focusedIndex,
|
|
3194
|
+
icons: result.icons,
|
|
3195
|
+
inputSource: result.inputSource,
|
|
3196
|
+
items: result.items,
|
|
3197
|
+
picks: result.picks,
|
|
3198
|
+
value: result.value
|
|
3199
|
+
};
|
|
3200
|
+
});
|
|
3201
|
+
if (requestVersions.get(state.uid) === requestVersion) {
|
|
3202
|
+
requestVersions.delete(state.uid);
|
|
3203
|
+
}
|
|
3204
|
+
};
|
|
3205
|
+
|
|
3206
|
+
const handleInputWithContext = async (context, newValue, cursorOffset, inputSource = Script) => {
|
|
3207
|
+
const state = context.getState();
|
|
3208
|
+
if (state.value !== newValue) {
|
|
3209
|
+
await setValueWithContext(context, newValue);
|
|
3210
|
+
}
|
|
3211
|
+
await context.updateState(latestState => {
|
|
3212
|
+
if (latestState.value !== newValue) {
|
|
3213
|
+
return latestState;
|
|
3214
|
+
}
|
|
3215
|
+
return {
|
|
3216
|
+
...latestState,
|
|
3217
|
+
cursorOffset,
|
|
3218
|
+
inputSource
|
|
3219
|
+
};
|
|
3220
|
+
});
|
|
3221
|
+
};
|
|
3146
3222
|
|
|
3147
3223
|
// TODO when user types letters -> no need to query provider again -> just filter existing results
|
|
3148
3224
|
const handleInput = async (state, newValue, cursorOffset, inputSource = Script) => {
|
|
@@ -3385,7 +3461,7 @@ const parseArgs = (subId, args) => {
|
|
|
3385
3461
|
placeholder: last.placeholder ? String(last.placeholder) : ''
|
|
3386
3462
|
};
|
|
3387
3463
|
};
|
|
3388
|
-
const
|
|
3464
|
+
const getLoadedState = async state => {
|
|
3389
3465
|
const {
|
|
3390
3466
|
args,
|
|
3391
3467
|
assetDir,
|
|
@@ -3418,7 +3494,6 @@ const loadContent = async state => {
|
|
|
3418
3494
|
const finalDeltaY = getFinalDeltaY(listHeight, itemHeight, items.length);
|
|
3419
3495
|
const parsedArgs = parseArgs(subId, args);
|
|
3420
3496
|
const finalValue = parsedArgs.initialValue || value;
|
|
3421
|
-
notifyVisible();
|
|
3422
3497
|
return {
|
|
3423
3498
|
...state,
|
|
3424
3499
|
args,
|
|
@@ -3440,6 +3515,30 @@ const loadContent = async state => {
|
|
|
3440
3515
|
value: finalValue
|
|
3441
3516
|
};
|
|
3442
3517
|
};
|
|
3518
|
+
const loadContentWithContext = async context => {
|
|
3519
|
+
const state = context.getState();
|
|
3520
|
+
const loadedState = await getLoadedState(state);
|
|
3521
|
+
await context.updateState(latestState => ({
|
|
3522
|
+
...latestState,
|
|
3523
|
+
cursorOffset: loadedState.cursorOffset,
|
|
3524
|
+
fileIconCache: loadedState.fileIconCache,
|
|
3525
|
+
finalDeltaY: loadedState.finalDeltaY,
|
|
3526
|
+
focused: loadedState.focused,
|
|
3527
|
+
focusedIndex: loadedState.focusedIndex,
|
|
3528
|
+
icons: loadedState.icons,
|
|
3529
|
+
initial: loadedState.initial,
|
|
3530
|
+
inputSource: loadedState.inputSource,
|
|
3531
|
+
items: loadedState.items,
|
|
3532
|
+
maxLineY: loadedState.maxLineY,
|
|
3533
|
+
minLineY: loadedState.minLineY,
|
|
3534
|
+
picks: loadedState.picks,
|
|
3535
|
+
placeholder: loadedState.placeholder,
|
|
3536
|
+
providerId: loadedState.providerId,
|
|
3537
|
+
state: loadedState.state,
|
|
3538
|
+
value: loadedState.value
|
|
3539
|
+
}));
|
|
3540
|
+
notifyVisible();
|
|
3541
|
+
};
|
|
3443
3542
|
|
|
3444
3543
|
const SetCursorOffset = 'setCursorOffset';
|
|
3445
3544
|
const SetFocusedIndex = 'setFocusedIndex';
|
|
@@ -3910,7 +4009,6 @@ const Viewlet = 'Viewlet';
|
|
|
3910
4009
|
|
|
3911
4010
|
const HandleWheel = 'handleWheel';
|
|
3912
4011
|
const HandlePointerDown = 'handlePointerDown';
|
|
3913
|
-
const HandleBeforeInput = 'handleBeforeInput';
|
|
3914
4012
|
const HandleBlur = 'handleBlur';
|
|
3915
4013
|
const HandleFocus = 'handleFocus';
|
|
3916
4014
|
const HandleInput = 'handleInput';
|
|
@@ -3934,7 +4032,6 @@ const getQuickPickInputVirtualDom = (placeholder = '') => {
|
|
|
3934
4032
|
className: InputBox,
|
|
3935
4033
|
inputType: 'text',
|
|
3936
4034
|
name: QuickPickInput,
|
|
3937
|
-
onBeforeInput: HandleBeforeInput,
|
|
3938
4035
|
onBlur: HandleBlur,
|
|
3939
4036
|
onFocus: HandleFocus,
|
|
3940
4037
|
onInput: HandleInput,
|
|
@@ -4228,9 +4325,6 @@ const renderEventListeners = () => {
|
|
|
4228
4325
|
}, {
|
|
4229
4326
|
name: HandleBlur,
|
|
4230
4327
|
params: ['handleBlur']
|
|
4231
|
-
}, {
|
|
4232
|
-
name: HandleBeforeInput,
|
|
4233
|
-
params: ['handleBeforeInput']
|
|
4234
4328
|
}, {
|
|
4235
4329
|
name: HandleInput,
|
|
4236
4330
|
params: ['handleInput', 'event.target.value']
|
|
@@ -4338,21 +4432,21 @@ const commandMap = {
|
|
|
4338
4432
|
'QuickPick.handleBlur': wrapCommand(handleBlur),
|
|
4339
4433
|
'QuickPick.handleClickAt': wrapCommand(handleClickAt),
|
|
4340
4434
|
'QuickPick.handleFocus': wrapCommand(handleFocus),
|
|
4341
|
-
'QuickPick.handleInput':
|
|
4435
|
+
'QuickPick.handleInput': wrapAsyncCommand(handleInputWithContext),
|
|
4342
4436
|
'QuickPick.handleMessagePort': handleMessagePort,
|
|
4343
4437
|
'QuickPick.handleScrollBarPointerDown': wrapCommand(handleScrollBarPointerDown),
|
|
4344
4438
|
'QuickPick.handleScrollBarPointerMove': wrapCommand(handleScrollBarPointerMove),
|
|
4345
4439
|
'QuickPick.handleScrollBarPointerUp': wrapCommand(handleScrollBarPointerUp),
|
|
4346
4440
|
'QuickPick.handleWheel': wrapCommand(handleWheel),
|
|
4347
4441
|
'QuickPick.initialize': initialize,
|
|
4348
|
-
'QuickPick.loadContent':
|
|
4442
|
+
'QuickPick.loadContent': wrapAsyncCommand(loadContentWithContext),
|
|
4349
4443
|
'QuickPick.render2': render2,
|
|
4350
4444
|
'QuickPick.renderEventListeners': renderEventListeners,
|
|
4351
4445
|
'QuickPick.selectCurrentIndex': wrapCommand(selectCurrentIndex),
|
|
4352
4446
|
'QuickPick.selectIndex': wrapCommand(selectIndex),
|
|
4353
4447
|
'QuickPick.selectItem': wrapCommand(selectItem),
|
|
4354
4448
|
'QuickPick.setDeltaY': wrapCommand(setDeltaY),
|
|
4355
|
-
'QuickPick.setValue':
|
|
4449
|
+
'QuickPick.setValue': wrapAsyncCommand(setValueWithContext),
|
|
4356
4450
|
'QuickPick.showQuickInput': showQuickInput,
|
|
4357
4451
|
'QuickPick.showQuickPick': showQuickPick,
|
|
4358
4452
|
'QuickPick.waitUntilVisible': waitUntilVisible
|