@lvce-editor/text-search-worker 6.3.0 → 6.4.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.
@@ -1307,9 +1307,9 @@ const Match$1 = 2;
1307
1307
 
1308
1308
  const FocusElementByName = 'Viewlet.focusElementByName';
1309
1309
  const SetCss = 'Viewlet.setCss';
1310
- const SetDom2 = 'Viewlet.setDom2';
1311
1310
  const SetFocusContext = 'Viewlet.setFocusContext';
1312
1311
  const SetValueByName = 'Viewlet.setValueByName';
1312
+ const SetPatches = 'Viewlet.setPatches';
1313
1313
 
1314
1314
  const Empty = 0;
1315
1315
  const FocusIgnoreFiles = 1012;
@@ -2192,7 +2192,6 @@ const isEqual$7 = (oldState, newState) => {
2192
2192
  return oldState.deltaY === newState.deltaY && oldState.finalDeltaY === newState.finalDeltaY && oldState.height === newState.height && oldState.headerHeight === newState.headerHeight && oldState.itemHeight === newState.itemHeight && oldState.items === newState.items;
2193
2193
  };
2194
2194
 
2195
- const RenderItems = 1;
2196
2195
  const RenderFocus = 2;
2197
2196
  const RenderValue = 3;
2198
2197
  const RenderReplaceValue = 4;
@@ -2220,7 +2219,7 @@ const isEqual$3 = (oldState, newState) => {
2220
2219
  };
2221
2220
 
2222
2221
  const isEqual$2 = (oldState, newState) => {
2223
- return oldState.collapsedPaths === newState.collapsedPaths && oldState.deltaY === newState.deltaY && oldState.flags === newState.flags && oldState.focus === newState.focus && oldState.icons === newState.icons && oldState.items === newState.items && oldState.listFocused === newState.listFocused && oldState.listFocusedIndex === newState.listFocusedIndex && oldState.loaded === newState.loaded && oldState.maxLineY === newState.maxLineY && oldState.message === newState.message && oldState.minLineY === newState.minLineY && oldState.replacement === newState.replacement && oldState.searchInputErrorMessage === newState.searchInputErrorMessage;
2222
+ return oldState.collapsedPaths === newState.collapsedPaths && oldState.deltaY === newState.deltaY && oldState.flags === newState.flags && oldState.focus === newState.focus && oldState.icons === newState.icons && oldState.items === newState.items && oldState.listFocused === newState.listFocused && oldState.listFocusedIndex === newState.listFocusedIndex && oldState.loaded === newState.loaded && oldState.maxLineY === newState.maxLineY && oldState.message === newState.message && oldState.minLineY === newState.minLineY && oldState.renderFolderPaths === newState.renderFolderPaths && oldState.replacement === newState.replacement && oldState.searchInputErrorMessage === newState.searchInputErrorMessage;
2224
2223
  };
2225
2224
 
2226
2225
  const isEqual$1 = (oldState, newState) => {
@@ -2254,6 +2253,13 @@ const diff2 = uid => {
2254
2253
  return diffResult;
2255
2254
  };
2256
2255
 
2256
+ const disableRenderFolderPaths = state => {
2257
+ return {
2258
+ ...state,
2259
+ renderFolderPaths: false
2260
+ };
2261
+ };
2262
+
2257
2263
  const getNewMinMax = (newItemsLength, minLineY, maxLineY, deltaY, itemHeight) => {
2258
2264
  if (maxLineY > newItemsLength) {
2259
2265
  const diff = maxLineY - minLineY;
@@ -2658,6 +2664,13 @@ const dismissItem = state => {
2658
2664
  return removeIndex(state, actualIndex);
2659
2665
  };
2660
2666
 
2667
+ const enableRenderFolderPaths = state => {
2668
+ return {
2669
+ ...state,
2670
+ renderFolderPaths: true
2671
+ };
2672
+ };
2673
+
2661
2674
  const expandDetails = state => {
2662
2675
  const {
2663
2676
  flags
@@ -4101,11 +4114,71 @@ const handlePullResultsFound = async (state, resultSearchId) => {
4101
4114
  return state;
4102
4115
  };
4103
4116
 
4117
+ const clamp$1 = (num, min, max) => {
4118
+ return Math.min(Math.max(num, min), max);
4119
+ };
4120
+
4121
+ const handleResize = async (state, x, y, width, height) => {
4122
+ const {
4123
+ deltaY,
4124
+ fileIconCache,
4125
+ headerHeight,
4126
+ itemHeight,
4127
+ listItems,
4128
+ minimumSliderSize
4129
+ } = state;
4130
+ const total = listItems.length;
4131
+ const contentHeight = total * itemHeight;
4132
+ const listHeight = height - headerHeight;
4133
+ const scrollBarHeight = getScrollBarSize$1(height, contentHeight, minimumSliderSize);
4134
+ const finalDeltaY = Math.max(contentHeight - listHeight, 0);
4135
+ const newDeltaY = clamp$1(deltaY, 0, finalDeltaY);
4136
+ const minLineY = Math.floor(newDeltaY / itemHeight);
4137
+ const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
4138
+ const maxLineY = Math.min(minLineY + numberOfVisible, total);
4139
+ const visibleItems = listItems.slice(minLineY, maxLineY);
4140
+ const {
4141
+ icons,
4142
+ newFileIconCache
4143
+ } = await getFileIcons(visibleItems, fileIconCache);
4144
+ const scrollBarY = finalDeltaY === 0 ? 0 : getScrollBarY$1(newDeltaY, finalDeltaY, listHeight, scrollBarHeight);
4145
+ return {
4146
+ ...state,
4147
+ deltaY: newDeltaY,
4148
+ fileIconCache: newFileIconCache,
4149
+ finalDeltaY,
4150
+ height,
4151
+ icons,
4152
+ maxLineY,
4153
+ minLineY,
4154
+ scrollBarHeight,
4155
+ scrollBarY,
4156
+ width,
4157
+ x,
4158
+ y
4159
+ };
4160
+ };
4161
+
4104
4162
  const handleSharedInput = (state, name, value, inputSource = Script) => {
4105
4163
  const fn = getInputHandler(name);
4106
4164
  return fn(state, value, inputSource);
4107
4165
  };
4108
4166
 
4167
+ const handleWorkspaceChange = state => {
4168
+ return {
4169
+ ...state,
4170
+ deltaY: 0,
4171
+ items: [],
4172
+ listItems: [],
4173
+ matchCount: 0,
4174
+ maxLineY: 0,
4175
+ message: '',
4176
+ minLineY: 0,
4177
+ replacement: '',
4178
+ value: ''
4179
+ };
4180
+ };
4181
+
4109
4182
  const send = async port => {
4110
4183
  await sendMessagePortToIconThemeWorker(port, 0);
4111
4184
  };
@@ -4560,6 +4633,14 @@ const getRelativePath = relativePath => {
4560
4633
  }
4561
4634
  return `/${relativePath}`; // TODO support windows paths
4562
4635
  };
4636
+ const getRelativeFolderPath = relativePath => {
4637
+ const normalized = relativePath.startsWith('./') ? relativePath.slice(2) : relativePath;
4638
+ const slashIndex = normalized.lastIndexOf('/');
4639
+ if (slashIndex === -1) {
4640
+ return '';
4641
+ }
4642
+ return normalized.slice(0, slashIndex);
4643
+ };
4563
4644
 
4564
4645
  const selectIndexPreview = async (state, searchResult, index) => {
4565
4646
  const {
@@ -4854,10 +4935,12 @@ const getTreeItemIndent = depth => {
4854
4935
  return baseIndent + depth * defaultIndent;
4855
4936
  };
4856
4937
 
4857
- const getSearchDisplayResultFile = (results, fileIcons, i, setSize, collapsedPaths, text, posInSet, relativeIndex, focused, originalResults) => {
4938
+ const getSearchDisplayResultFile = (results, fileIcons, i, setSize, collapsedPaths, text, posInSet, relativeIndex, focused, renderFolderPaths, originalResults) => {
4858
4939
  const path = text;
4859
4940
  const absolutePath = getRelativePath(path);
4860
4941
  const baseName = pathBaseName(path);
4942
+ const relativeFolderPath = getRelativeFolderPath(path);
4943
+ const displayText = renderFolderPaths && relativeFolderPath ? `${baseName} — ${relativeFolderPath}` : baseName;
4861
4944
  const index = originalResults.indexOf(results[i]);
4862
4945
  const matchCount = getMatchCount(originalResults, index);
4863
4946
  const expanded = collapsedPaths.includes(path) ? Collapsed : Expanded;
@@ -4876,7 +4959,7 @@ const getSearchDisplayResultFile = (results, fileIcons, i, setSize, collapsedPat
4876
4959
  posInSet,
4877
4960
  replacement: '',
4878
4961
  setSize,
4879
- text: baseName,
4962
+ text: displayText,
4880
4963
  title: absolutePath
4881
4964
  };
4882
4965
  };
@@ -4901,7 +4984,7 @@ const getDisplayResultMatch = (setSize, searchTermLength, replacement, text, pos
4901
4984
  };
4902
4985
  };
4903
4986
 
4904
- const getDisplayResult = (results, fileIcons, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY, originalResults) => {
4987
+ const getDisplayResult = (results, fileIcons, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, renderFolderPaths, minLineY, originalResults) => {
4905
4988
  const result = results[i];
4906
4989
  const {
4907
4990
  start,
@@ -4913,7 +4996,7 @@ const getDisplayResult = (results, fileIcons, i, setSize, searchTermLength, repl
4913
4996
  const relativeIndex = i - minLineY;
4914
4997
  switch (type) {
4915
4998
  case File:
4916
- return getSearchDisplayResultFile(results, fileIcons, i, setSize, collapsedPaths, text, posInSet, relativeIndex, focused, originalResults);
4999
+ return getSearchDisplayResultFile(results, fileIcons, i, setSize, collapsedPaths, text, posInSet, relativeIndex, focused, renderFolderPaths, originalResults);
4917
5000
  case Match:
4918
5001
  return getDisplayResultMatch(setSize, searchTermLength, replacement, text, posInSet, start, focused);
4919
5002
  default:
@@ -4921,14 +5004,14 @@ const getDisplayResult = (results, fileIcons, i, setSize, searchTermLength, repl
4921
5004
  }
4922
5005
  };
4923
5006
 
4924
- const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, fileIcons, focusedIndex, collapsedPaths, originalResults) => {
5007
+ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, fileIcons, focusedIndex, collapsedPaths, renderFolderPaths, originalResults) => {
4925
5008
  const filteredResults = getFilteredResults(results, collapsedPaths);
4926
5009
  const displayResults = [];
4927
5010
  const setSize = resultCount;
4928
5011
  const searchTermLength = searchTerm.length;
4929
5012
  const max = Math.min(filteredResults.length, maxLineY);
4930
5013
  for (let i = minLineY; i < max; i++) {
4931
- const displayResult = getDisplayResult(filteredResults, fileIcons, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY, originalResults);
5014
+ const displayResult = getDisplayResult(filteredResults, fileIcons, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, renderFolderPaths, minLineY, originalResults);
4932
5015
  displayResults.push(displayResult);
4933
5016
  }
4934
5017
  return displayResults;
@@ -4956,12 +5039,13 @@ const createViewModel = state => {
4956
5039
  maxLineY,
4957
5040
  message,
4958
5041
  minLineY,
5042
+ renderFolderPaths,
4959
5043
  replacement,
4960
5044
  scrollBarHeight,
4961
5045
  searchInputErrorMessage,
4962
5046
  value
4963
5047
  } = state;
4964
- const displayResults = getDisplayResults(listItems, itemHeight, fileCount, value, minLineY, maxLineY, replacement, icons, listFocusedIndex, collapsedPaths, items);
5048
+ const displayResults = getDisplayResults(listItems, itemHeight, fileCount, value, minLineY, maxLineY, replacement, icons, listFocusedIndex, collapsedPaths, renderFolderPaths || false, items);
4965
5049
  const focusOutline = listFocused && listFocusedIndex === -1;
4966
5050
  const scrollBarValue = deltaY / finalDeltaY * 100;
4967
5051
  const scrollBarY = getScrollBarY$1(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
@@ -4997,13 +5081,24 @@ const getTreeItemsTopRule = treeItemsTop => {
4997
5081
  top: ${roundedTreeItemsTop}px;
4998
5082
  }`;
4999
5083
  };
5000
- const getCss = (top, uniqueIndents, uniqueIndentRights, scrollBarHeight, scrollBarY, treeItemsTop) => {
5084
+ const getScrollBarThumbTopRule = scrollBarY => {
5085
+ const roundedScrollBarY = Math.round(scrollBarY);
5086
+ return `.ScrollBarThumbTop-${roundedScrollBarY} {
5087
+ transform: translateY(${roundedScrollBarY}px);
5088
+ }`;
5089
+ };
5090
+ const getCss = (top, uniqueIndents, uniqueIndentRights, scrollBarHeight, scrollBarY, treeItemsTop, headerHeight = 0) => {
5001
5091
  const rules = [`.Search {
5002
5092
  --ScrollBarHeight: ${scrollBarHeight}px;
5003
5093
  --ScrollBarTop: ${scrollBarY}px;
5004
5094
  --TreeItemsTop: ${top}px;
5005
5095
  }
5006
- `, ...uniqueIndents.map(getIndentRule), ...uniqueIndentRights.map(getIndentRightRule), getTreeItemsTopRule(treeItemsTop)];
5096
+
5097
+ .SearchHeader {
5098
+ contain: strict;
5099
+ height: ${headerHeight}px;
5100
+ }
5101
+ `, ...uniqueIndents.map(getIndentRule), ...uniqueIndentRights.map(getIndentRightRule), getTreeItemsTopRule(treeItemsTop), getScrollBarThumbTopRule(scrollBarY)];
5007
5102
  return rules.join('\n');
5008
5103
  };
5009
5104
 
@@ -5026,6 +5121,7 @@ const PaddingRight = 12;
5026
5121
 
5027
5122
  const renderCss = (oldState, newState) => {
5028
5123
  const {
5124
+ headerHeight,
5029
5125
  uid
5030
5126
  } = newState;
5031
5127
  const viewModel = createViewModel(newState);
@@ -5033,7 +5129,7 @@ const renderCss = (oldState, newState) => {
5033
5129
  const uniqueIndents = getUniqueIndents(indents);
5034
5130
  const uniqueIndentRights = [PaddingRight];
5035
5131
  const treeItemsTop = viewModel.itemHeight === 0 ? 0 : Math.round(-(viewModel.deltaY % viewModel.itemHeight));
5036
- const css = getCss(0, uniqueIndents, uniqueIndentRights, viewModel.scrollBarHeight, viewModel.scrollBarY, treeItemsTop);
5132
+ const css = getCss(0, uniqueIndents, uniqueIndentRights, viewModel.scrollBarHeight, viewModel.scrollBarY, treeItemsTop, headerHeight);
5037
5133
  return [SetCss, uid, css];
5038
5134
  };
5039
5135
 
@@ -5471,6 +5567,7 @@ const getScrollBarVirtualDom = (scrollBarHeight, scrollBarY, scrollBarValue) =>
5471
5567
  if (scrollBarHeight === 0) {
5472
5568
  return [];
5473
5569
  }
5570
+ const roundedScrollBarY = Math.round(scrollBarY);
5474
5571
  return [{
5475
5572
  ariaControls: TreeItems,
5476
5573
  ariaValueNow: scrollBarValue,
@@ -5481,9 +5578,8 @@ const getScrollBarVirtualDom = (scrollBarHeight, scrollBarY, scrollBarValue) =>
5481
5578
  type: Div
5482
5579
  }, {
5483
5580
  childCount: 0,
5484
- className: ScrollBarThumb,
5581
+ className: `${ScrollBarThumb} ScrollBarThumbTop-${roundedScrollBarY}`,
5485
5582
  height: scrollBarHeight,
5486
- translate: `0 ${scrollBarY}px`,
5487
5583
  type: Div
5488
5584
  }];
5489
5585
  };
@@ -5712,18 +5808,18 @@ const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchI
5712
5808
  }, ...getSearchHeaderVirtualDom(flags, message, searchInputErrorMessage, matchCount, focus, limitHitWarning), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight)];
5713
5809
  };
5714
5810
 
5715
- const renderItems = (oldState, newState) => {
5811
+ const getDom = newState => {
5716
5812
  const viewModel = createViewModel(newState);
5717
5813
  const dom = getSearchVirtualDom(viewModel.displayResults, viewModel.flags, viewModel.message, viewModel.focusOutline, viewModel.searchInputErrorMessage, viewModel.scrollBarHeight, viewModel.scrollBarY, viewModel.scrollBarValue, viewModel.deltaY, viewModel.itemHeight, viewModel.matchCount, newState.limitHitWarning, viewModel.focus, newState.initial);
5718
- return [SetDom2, newState.uid, dom];
5814
+ return dom;
5719
5815
  };
5720
5816
 
5721
5817
  // TODO cache rendered dom so that it can be used for dom diffing
5722
5818
  const renderIncremental = (oldState, newState) => {
5723
- const oldDom = renderItems(oldState, oldState)[2];
5724
- const newDom = renderItems(newState, newState)[2];
5819
+ const oldDom = getDom(oldState);
5820
+ const newDom = getDom(newState);
5725
5821
  const patches = diffTree(oldDom, newDom);
5726
- return ['Viewlet.setPatches', newState.uid, patches];
5822
+ return [SetPatches, newState.uid, patches];
5727
5823
  };
5728
5824
 
5729
5825
  const renderSelections = (oldState, newState) => {
@@ -5760,8 +5856,6 @@ const getRenderer = diffType => {
5760
5856
  return renderIncludeValue;
5761
5857
  case RenderIncremental:
5762
5858
  return renderIncremental;
5763
- case RenderItems:
5764
- return renderItems;
5765
5859
  case RenderReplaceValue:
5766
5860
  return renderReplacement;
5767
5861
  case RenderSelections:
@@ -6205,7 +6299,9 @@ const commandMap = {
6205
6299
  'TextSearch.copyPath': wrapCommand(copyPath$1),
6206
6300
  'TextSearch.create': create,
6207
6301
  'TextSearch.diff2': diff2,
6302
+ 'TextSearch.disableRenderFolderPaths': wrapCommand(disableRenderFolderPaths),
6208
6303
  'TextSearch.dismissItem': wrapCommand(dismissItem),
6304
+ 'TextSearch.enableRenderFolderPaths': wrapCommand(enableRenderFolderPaths),
6209
6305
  'TextSearch.expandDetails': wrapCommand(expandDetails),
6210
6306
  'TextSearch.focusFirst': wrapCommand(focusFirst),
6211
6307
  'TextSearch.focusIndex': wrapCommand(focusIndex),
@@ -6259,11 +6355,13 @@ const commandMap = {
6259
6355
  'TextSearch.handleListPointerDown': wrapCommand(handleListPointerDown),
6260
6356
  'TextSearch.handlePullResultsFound': wrapCommand(handlePullResultsFound),
6261
6357
  'TextSearch.handleReplaceInput': wrapCommand(handleReplaceInput),
6358
+ 'TextSearch.handleResize': wrapCommand(handleResize),
6262
6359
  'TextSearch.handleScrollBarCaptureLost': wrapCommand(handleScrollBarCaptureLost),
6263
6360
  'TextSearch.handleScrollBarClick': wrapCommand(handleScrollBarClick),
6264
6361
  'TextSearch.handleScrollBarMove': wrapCommand(handleScrollBarMove),
6265
6362
  'TextSearch.handleSharedInput': wrapCommand(handleSharedInput),
6266
6363
  'TextSearch.handleWheel': wrapCommand(handleWheel),
6364
+ 'TextSearch.handleWorkspaceChange': wrapCommand(handleWorkspaceChange),
6267
6365
  // not wrapped
6268
6366
  'TextSearch.initialize': initialize,
6269
6367
  'TextSearch.loadContent': wrapCommand(loadContent),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "6.3.0",
3
+ "version": "6.4.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"