@lvce-editor/explorer-view 2.28.0 → 2.29.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.
@@ -1474,6 +1474,13 @@ const cancelEdit = state => {
1474
1474
  };
1475
1475
  };
1476
1476
 
1477
+ const cancelTypeAhead = state => {
1478
+ return {
1479
+ ...state,
1480
+ focusWord: ''
1481
+ };
1482
+ };
1483
+
1477
1484
  const isTopLevel$1 = dirent => {
1478
1485
  return dirent.depth === 1;
1479
1486
  };
@@ -1580,6 +1587,20 @@ const create$1 = () => {
1580
1587
  };
1581
1588
  };
1582
1589
  return wrapped;
1590
+ },
1591
+ diff(uid, modules, numbers) {
1592
+ const {
1593
+ oldState,
1594
+ newState
1595
+ } = states[uid];
1596
+ const diffResult = [];
1597
+ for (let i = 0; i < modules.length; i++) {
1598
+ const fn = modules[i];
1599
+ if (!fn(oldState, newState)) {
1600
+ diffResult.push(numbers[i]);
1601
+ }
1602
+ }
1603
+ return diffResult;
1583
1604
  }
1584
1605
  };
1585
1606
  };
@@ -1630,7 +1651,9 @@ const create2 = (uid, uri, x, y, width, height, args, parentUid, platform = 0) =
1630
1651
  editingSelection: {
1631
1652
  start: 0,
1632
1653
  end: 0
1633
- }
1654
+ },
1655
+ focusWord: '',
1656
+ focusWordTimeout: 800
1634
1657
  };
1635
1658
  set(uid, state, state);
1636
1659
  };
@@ -1671,7 +1694,9 @@ const create = (id, uri, x, y, width, height, args, parentUid, platform = 0) =>
1671
1694
  editingSelection: {
1672
1695
  start: 0,
1673
1696
  end: 0
1674
- }
1697
+ },
1698
+ focusWord: '',
1699
+ focusWordTimeout: 800
1675
1700
  };
1676
1701
  set(state.uid, state, state);
1677
1702
  return state;
@@ -1999,7 +2024,7 @@ const focusIndex = (state, index) => {
1999
2024
  } = state;
2000
2025
  const newItems = items.map((item, i) => ({
2001
2026
  ...item,
2002
- selected: i === index ? true : false
2027
+ selected: i === index ? false : false
2003
2028
  }));
2004
2029
  if (index < minLineY) {
2005
2030
  if (index < 0) {
@@ -2112,7 +2137,7 @@ const focusPrevious = state => {
2112
2137
  }
2113
2138
  };
2114
2139
 
2115
- const commandIds = ['acceptEdit', 'cancelEdit', 'collapseAll', 'copyPath', 'copyRelativePath', 'dispose', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'getMenuEntries2', 'getMouseActions', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleInputBlur', 'handleInputClick', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'removeDirent', 'rename', 'renameDirent', 'renderEventListeners', 'revealItem', 'revealItem', 'scrollDown', 'scrollUp', 'selectAll', 'selectDown', 'selectUp', 'setDeltaY', 'setSelectedIndices', 'updateEditingValue', 'updateIcons'];
2140
+ const commandIds = ['acceptEdit', 'cancelEdit', 'collapseAll', 'copyPath', 'copyRelativePath', 'dispose', 'expandAll', 'expandRecursively', 'focus', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusNone', 'focusPrevious', 'getFocusedDirent', 'getMenuEntries2', 'getMouseActions', 'handleArrowLeft', 'handleArrowLeft', 'handleArrowRight', 'handleArrowRight', 'handleBlur', 'handleClick', 'handleClickAt', 'handleClickCurrent', 'handleClickCurrentButKeepFocus', 'handleClickOpenFolder', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleCopy', 'handleDragLeave', 'handleDragOver', 'handleDrop', 'handleFocus', 'handleIconThemeChange', 'handleInputBlur', 'handleInputClick', 'handleLanguagesChanged', 'handleMouseEnter', 'handleMouseLeave', 'handlePaste', 'handlePointerDown', 'handleUpload', 'handleWheel', 'handleWorkspaceChange', 'hotReload', 'newFile', 'newFolder', 'openContainingFolder', 'refresh', 'removeDirent', 'rename', 'renameDirent', 'renderEventListeners', 'revealItem', 'revealItem', 'scrollDown', 'scrollUp', 'selectAll', 'selectDown', 'selectUp', 'setDeltaY', 'setSelectedIndices', 'cancelTypeAhead', 'updateEditingValue', 'handleKeyDown', 'updateIcons'];
2116
2141
 
2117
2142
  const getCommandIds = () => {
2118
2143
  return commandIds;
@@ -3335,6 +3360,73 @@ const handleInputClick = state => {
3335
3360
  return state;
3336
3361
  };
3337
3362
 
3363
+ const filterByFocusWord = (items, focusedIndex, focusWord) => {
3364
+ if (items.length === 0) {
3365
+ return -1;
3366
+ }
3367
+ const matches = [];
3368
+ for (let i = 0; i < items.length; i++) {
3369
+ if (items[i].toLowerCase().includes(focusWord)) {
3370
+ matches.push(i);
3371
+ }
3372
+ }
3373
+ if (matches.length === 0) {
3374
+ return -1;
3375
+ }
3376
+
3377
+ // Find the next match after the current focus
3378
+ let nextIndex = matches.findIndex(index => index > focusedIndex);
3379
+ if (nextIndex === -1) {
3380
+ // If no match found after current focus, wrap around to the first match
3381
+ nextIndex = 0;
3382
+ }
3383
+ return matches[nextIndex];
3384
+ };
3385
+
3386
+ const RE_ASCII = /^[a-z]$/;
3387
+ const isAscii = key => {
3388
+ return RE_ASCII.test(key);
3389
+ };
3390
+
3391
+ let timeout;
3392
+ const handleKeyDown = (state, key) => {
3393
+ const {
3394
+ focusWord,
3395
+ items,
3396
+ focusedIndex,
3397
+ focusWordTimeout
3398
+ } = state;
3399
+ if (focusWord && key === '') {
3400
+ return cancelTypeAhead(state);
3401
+ }
3402
+ if (!isAscii(key)) {
3403
+ return state;
3404
+ }
3405
+ const newFocusWord = focusWord + key.toLowerCase();
3406
+ const itemNames = items.map(item => item.name);
3407
+ const matchingIndex = filterByFocusWord(itemNames, focusedIndex, newFocusWord);
3408
+ if (timeout) {
3409
+ clearTimeout(timeout);
3410
+ }
3411
+
3412
+ // @ts-ignore
3413
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
3414
+ timeout = setTimeout(async () => {
3415
+ await invoke('Explorer.cancelTypeAhead');
3416
+ }, focusWordTimeout);
3417
+ if (matchingIndex === -1) {
3418
+ return {
3419
+ ...state,
3420
+ focusWord: newFocusWord
3421
+ };
3422
+ }
3423
+ return {
3424
+ ...state,
3425
+ focusWord: newFocusWord,
3426
+ focusedIndex: matchingIndex
3427
+ };
3428
+ };
3429
+
3338
3430
  // TODO add lots of tests for this
3339
3431
  const updateRoot = async state1 => {
3340
3432
  // @ts-ignore
@@ -4030,6 +4122,7 @@ const HandleInputBlur = 'handleInputBlur';
4030
4122
  const HandleInputClick = 'handleInputClick';
4031
4123
  const HandleListBlur = 'handleListBlur';
4032
4124
  const HandleListFocus = 'handleListFocus';
4125
+ const HandleListKeyDown = 'handleListKeyDown';
4033
4126
  const HandlePointerDown = 'handlePointerDown';
4034
4127
  const HandleWheel = 'handleWheel';
4035
4128
 
@@ -4214,7 +4307,8 @@ const getExplorerVirtualDom = (visibleItems, focusedIndex, root, isWide, focused
4214
4307
  onDrop: HandleDrop,
4215
4308
  onFocus: HandleListFocus,
4216
4309
  onPointerDown: HandlePointerDown,
4217
- onWheel: HandleWheel
4310
+ onWheel: HandleWheel,
4311
+ onKeyDown: HandleListKeyDown
4218
4312
  }, ...visibleItems.flatMap(getExplorerItemVirtualDom)];
4219
4313
  return dom;
4220
4314
  };
@@ -4480,6 +4574,10 @@ const renderEventListeners = () => {
4480
4574
  return [{
4481
4575
  name: HandleInputBlur,
4482
4576
  params: ['handleInputBlur']
4577
+ }, {
4578
+ name: HandleListKeyDown,
4579
+ params: ['handleKeyDown', 'event.key'],
4580
+ preventDefault: true
4483
4581
  }, {
4484
4582
  name: HandleListFocus,
4485
4583
  params: ['handleFocus', 'event.isTrusted', 'event.target.className']
@@ -4880,6 +4978,8 @@ const updateEditingValue = async (state, value, inputSource = User) => {
4880
4978
 
4881
4979
  const commandMap = {
4882
4980
  'Explorer.acceptEdit': wrapCommand(acceptEdit),
4981
+ 'Explorer.handleKeyDown': wrapCommand(handleKeyDown),
4982
+ 'Explorer.cancelTypeAhead': wrapCommand(cancelTypeAhead),
4883
4983
  'Explorer.cancelEdit': wrapCommand(cancelEdit),
4884
4984
  'Explorer.collapseAll': wrapCommand(collapseAll),
4885
4985
  'Explorer.copyPath': wrapCommand(copyPath),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "2.28.0",
3
+ "version": "2.29.0",
4
4
  "description": "Explorer Worker",
5
5
  "repository": {
6
6
  "type": "git",