@lvce-editor/text-search-view 1.1.0 → 1.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.
@@ -1205,6 +1205,7 @@ const HighlightDeleted = 'HighlightDeleted';
1205
1205
  const HighlightInserted = 'HighlightInserted';
1206
1206
  const IconButton = 'IconButton';
1207
1207
  const IconButtonDisabled = 'IconButtonDisabled';
1208
+ const InputBox = 'InputBox';
1208
1209
  const Label$1 = 'Label';
1209
1210
  const List$1 = 'List';
1210
1211
  const MaskIcon = 'MaskIcon';
@@ -2457,7 +2458,7 @@ const create$1 = ({
2457
2458
  };
2458
2459
  };
2459
2460
 
2460
- const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, value = '', replacement = '', platform) => {
2461
+ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, value = '', replacement = '', platform, isSearchEditor = false) => {
2461
2462
  const headerHeight = getTopHeight(0);
2462
2463
  const state = {
2463
2464
  disposed: false,
@@ -2478,6 +2479,8 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
2478
2479
  }),
2479
2480
  assetDir,
2480
2481
  collapsedPaths: [],
2482
+ contextLines: 1,
2483
+ contextLinesEnabled: false,
2481
2484
  defaultExcludes: defaultExcludes,
2482
2485
  deltaY: 0,
2483
2486
  excludeValue: '',
@@ -2495,6 +2498,7 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
2495
2498
  includeValue: '',
2496
2499
  incrementalSearch: false,
2497
2500
  inputSource: User,
2501
+ isSearchEditor,
2498
2502
  limit: 20_000,
2499
2503
  limitHit: false,
2500
2504
  limitHitWarning: '',
@@ -2570,7 +2574,7 @@ const isEqual$3 = (oldState, newState) => {
2570
2574
  };
2571
2575
 
2572
2576
  const isEqual$2 = (oldState, newState) => {
2573
- 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;
2577
+ return oldState.collapsedPaths === newState.collapsedPaths && oldState.contextLinesEnabled === newState.contextLinesEnabled && oldState.deltaY === newState.deltaY && oldState.flags === newState.flags && oldState.focus === newState.focus && oldState.icons === newState.icons && oldState.items === newState.items && oldState.isSearchEditor === newState.isSearchEditor && 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;
2574
2578
  };
2575
2579
 
2576
2580
  const isEqual$1 = (oldState, newState) => {
@@ -2758,6 +2762,8 @@ const MatchWholeWord$1 = 'Match Whole Word';
2758
2762
  const NoResults = 'No results found';
2759
2763
  const Oneresult = '1 result in 1 file';
2760
2764
  const OpenNewSearchEditor = 'Open New Search Editor';
2765
+ const ContextLines$1 = 'Context Lines';
2766
+ const ToggleContextLines$1 = 'Toggle Context Lines';
2761
2767
  const PreserveCase$1 = 'Preserve Case';
2762
2768
  const Refresh$2 = 'Refresh';
2763
2769
  const Replace = 'Replace';
@@ -2919,6 +2925,12 @@ const clearSearchResults = () => {
2919
2925
  const openNewSearchEditor = () => {
2920
2926
  return i18nString(OpenNewSearchEditor);
2921
2927
  };
2928
+ const contextLines = () => {
2929
+ return i18nString(ContextLines$1);
2930
+ };
2931
+ const toggleContextLines$1 = () => {
2932
+ return i18nString(ToggleContextLines$1);
2933
+ };
2922
2934
  const viewAsTree$1 = () => {
2923
2935
  return i18nString(ViewAsTree$1);
2924
2936
  };
@@ -3432,6 +3444,7 @@ const getMenuEntryIds = () => {
3432
3444
 
3433
3445
  const ClearAll$1 = 'ClearAll';
3434
3446
  const CollapseAll$1 = 'CollapseAll';
3447
+ const ContextLines = 'ContextLines';
3435
3448
  const FilesToExclude = 'FilesToExclude';
3436
3449
  const FilesToInclude = 'FilesToInclude';
3437
3450
  const MatchCase = 'MatchCase';
@@ -3443,6 +3456,7 @@ const ReplaceValue = 'ReplaceValue';
3443
3456
  const SearchOnlyOpenEditors = 'SearchOnlyOpenEditors';
3444
3457
  const SearchValue = 'SearchValue';
3445
3458
  const ToggleReplace = 'ToggleReplace';
3459
+ const ToggleContextLines = 'ToggleContextLines';
3446
3460
  const ToggleSearchDetails = 'ToggleSearchDetails';
3447
3461
  const UseExcludeSettings = 'UseExcludeSettings';
3448
3462
  const UseRegularExpression = 'UseRegularExpression';
@@ -4020,6 +4034,44 @@ const getReplacingMessage = (fileCount, replaceCount) => {
4020
4034
  return replacingManyOccurrencesInManyFiles(replaceCount, fileCount);
4021
4035
  };
4022
4036
 
4037
+ const prompt = (text, options) => {
4038
+ return invoke$1('ConfirmPrompt.prompt', text, options);
4039
+ };
4040
+
4041
+ const getReplaceAllConfirmText = (matchCount, fileCount, replacement) => {
4042
+ if (matchCount === 1) {
4043
+ if (replacement) {
4044
+ return confirmReplaceOneOccurrenceInOneFile(replacement);
4045
+ }
4046
+ return confirmReplaceOneOccurrenceInOneFileNoValue();
4047
+ }
4048
+ if (fileCount === 1) {
4049
+ if (replacement) {
4050
+ return confirmReplaceManyOccurrencesInOneFile(matchCount, replacement);
4051
+ }
4052
+ return confirmReplaceManyOccurrencesInOneFileNoValue(matchCount);
4053
+ }
4054
+ if (replacement) {
4055
+ return confirmReplaceManyOccurrencesInManyFiles(matchCount, fileCount, replacement);
4056
+ }
4057
+ return confirmReplaceManyOccurrencesInManyFilesNoValue(matchCount, fileCount);
4058
+ };
4059
+
4060
+ const replaceAllAndPrompt = async (workspacePath, items, replacement, matchCount, fileCount) => {
4061
+ string(workspacePath);
4062
+ array(items);
4063
+ string(replacement);
4064
+ number(matchCount);
4065
+ number(fileCount);
4066
+ const confirmTitle = replaceAll$1();
4067
+ const confirmAccept = replace();
4068
+ const confirmText = getReplaceAllConfirmText(matchCount, fileCount, replacement);
4069
+ return prompt(confirmText, {
4070
+ confirmMessage: confirmAccept,
4071
+ title: confirmTitle
4072
+ });
4073
+ };
4074
+
4023
4075
  const getActualIndex = state => {
4024
4076
  const {
4025
4077
  focusedIndex,
@@ -4115,9 +4167,22 @@ const replaceAllInFocusedFile = async (state, fileIndex) => {
4115
4167
  scrollBarHeight
4116
4168
  };
4117
4169
  };
4118
- const replaceAll = async state => {
4119
- const actualIndex = getActualIndex(state);
4120
- const fileIndex = getFileIndex$1(state, actualIndex);
4170
+ const confirmReplaceAll = async (state, fileIndex) => {
4171
+ const {
4172
+ items,
4173
+ matchCount: totalMatchCount,
4174
+ replacement,
4175
+ workspacePath
4176
+ } = state;
4177
+ const targetItems = fileIndex === -1 ? items : getFileItems(state, fileIndex);
4178
+ const fileCount = fileIndex === -1 ? targetItems.filter(item => item.type === File).length : 1;
4179
+ const matchCount = fileIndex === -1 ? totalMatchCount : Math.max(targetItems.length - 1, 0);
4180
+ if (matchCount === 0) {
4181
+ return true;
4182
+ }
4183
+ return replaceAllAndPrompt(workspacePath, targetItems, replacement, matchCount, fileCount);
4184
+ };
4185
+ const replaceAllConfirmed = async (state, fileIndex) => {
4121
4186
  if (fileIndex !== -1) {
4122
4187
  return replaceAllInFocusedFile(state, fileIndex);
4123
4188
  }
@@ -4142,6 +4207,15 @@ const replaceAll = async state => {
4142
4207
  minLineY: 0
4143
4208
  };
4144
4209
  };
4210
+ const replaceAll = async state => {
4211
+ const actualIndex = getActualIndex(state);
4212
+ const fileIndex = getFileIndex$1(state, actualIndex);
4213
+ const shouldReplace = await confirmReplaceAll(state, fileIndex);
4214
+ if (!shouldReplace) {
4215
+ return state;
4216
+ }
4217
+ return replaceAllConfirmed(state, fileIndex);
4218
+ };
4145
4219
  const replaceAllWithProgress = async context => {
4146
4220
  const state = context.getState();
4147
4221
  const {
@@ -4152,16 +4226,30 @@ const replaceAllWithProgress = async context => {
4152
4226
  const fileIndex = getFileIndex$1(state, actualIndex);
4153
4227
  const fileCount = fileIndex === -1 ? totalFileCount : 1;
4154
4228
  const matchCount = fileIndex === -1 ? totalMatchCount : Math.max(getFileItems(state, fileIndex).length - 1, 0);
4229
+ const shouldReplace = await confirmReplaceAll(state, fileIndex);
4230
+ if (!shouldReplace) {
4231
+ return;
4232
+ }
4155
4233
  const message = getReplacingMessage(fileCount, matchCount);
4156
4234
  await context.updateState(latestState => ({
4157
4235
  ...latestState,
4158
4236
  message
4159
4237
  }));
4160
4238
  await invoke$1('Search.rerender');
4161
- const updatedState = await replaceAll(context.getState());
4239
+ const updatedState = await replaceAllConfirmed(context.getState(), fileIndex);
4162
4240
  await context.updateState(() => updatedState);
4163
4241
  };
4164
4242
 
4243
+ const toggleContextLines = async state => {
4244
+ const {
4245
+ contextLinesEnabled
4246
+ } = state;
4247
+ return {
4248
+ ...state,
4249
+ contextLinesEnabled: !contextLinesEnabled
4250
+ };
4251
+ };
4252
+
4165
4253
  const toggleDetailsExpanded = state => {
4166
4254
  const {
4167
4255
  flags
@@ -4258,6 +4346,8 @@ const getClickHandler = name => {
4258
4346
  return toggleOpenEditors;
4259
4347
  case SearchValue:
4260
4348
  return focusSearchValue$1;
4349
+ case ToggleContextLines:
4350
+ return toggleContextLines;
4261
4351
  case ToggleReplace:
4262
4352
  return toggleReplace;
4263
4353
  case ToggleSearchDetails:
@@ -4323,6 +4413,17 @@ const handleIncludeInput = (state, includeValue, inputSource = Script) => {
4323
4413
  });
4324
4414
  };
4325
4415
 
4416
+ const handleContextLinesInput = async (state, value) => {
4417
+ const contextLines = Math.trunc(Number(value));
4418
+ if (!Number.isFinite(contextLines)) {
4419
+ return state;
4420
+ }
4421
+ return {
4422
+ ...state,
4423
+ contextLines: Math.max(0, contextLines)
4424
+ };
4425
+ };
4426
+
4326
4427
  const handleInput = (state, value, inputSource = Script) => {
4327
4428
  return handleUpdate(state, {
4328
4429
  inputSource,
@@ -4339,6 +4440,8 @@ const handleReplaceInput = (state, value, inputSource = Script) => {
4339
4440
 
4340
4441
  const getInputHandler = name => {
4341
4442
  switch (name) {
4443
+ case ContextLines:
4444
+ return handleContextLinesInput;
4342
4445
  case FilesToExclude:
4343
4446
  return handleExcludeInput;
4344
4447
  case FilesToInclude:
@@ -6005,6 +6108,26 @@ const getReplacePlaceholder = focus => {
6005
6108
  return replace();
6006
6109
  };
6007
6110
 
6111
+ const getSearchEditorContextLinesVirtualDom = (contextLines$1, contextLinesEnabled) => {
6112
+ const button = {
6113
+ flag: contextLinesEnabled ? CheckBoxEnabled : CheckBoxDisabled,
6114
+ icon: 'MaskIconListSelection',
6115
+ name: ToggleContextLines,
6116
+ title: toggleContextLines$1()
6117
+ };
6118
+ return [{
6119
+ ariaLabel: contextLines(),
6120
+ childCount: 0,
6121
+ className: `${InputBox} SearchEditorContextLinesInput`,
6122
+ inputType: 'number',
6123
+ min: 0,
6124
+ name: ContextLines,
6125
+ onInput: HandleInput2,
6126
+ type: Input,
6127
+ value: `${contextLines$1}`
6128
+ }, ...getSearchFieldButtonVirtualDom(button)];
6129
+ };
6130
+
6008
6131
  const getSearchPlaceholder = focus => {
6009
6132
  if (focus === FocusSearchInput) {
6010
6133
  return searchForHistory();
@@ -6030,7 +6153,7 @@ const getSearchToggleVirtualDom = replaceExpanded => {
6030
6153
  }];
6031
6154
  };
6032
6155
 
6033
- const getSearchHeaderTopVirtualDom = (flags, searchInputErrorMessage, matchCount, focus) => {
6156
+ const getSearchHeaderTopVirtualDom = (flags, searchInputErrorMessage, matchCount, focus, isSearchEditor = false, contextLines = 1, contextLinesEnabled = false) => {
6034
6157
  const inputActions = getInputActionsInput(flags);
6035
6158
  const replaceActions = getInputActionsReplace(flags, matchCount);
6036
6159
  const searchPlaceholder = getSearchPlaceholder(focus);
@@ -6046,14 +6169,25 @@ const getSearchHeaderTopVirtualDom = (flags, searchInputErrorMessage, matchCount
6046
6169
  className: SearchHeaderTopRight,
6047
6170
  role: None$2,
6048
6171
  type: Div
6049
- }, ...getSearchFieldVirtualDom(SearchValue, searchPlaceholder, HandleInput2, inputActions.inside, inputActions.outside, Boolean(searchInputErrorMessage))];
6172
+ }];
6173
+ const searchFieldDom = getSearchFieldVirtualDom(SearchValue, searchPlaceholder, HandleInput2, inputActions.inside, inputActions.outside, Boolean(searchInputErrorMessage));
6174
+ if (isSearchEditor) {
6175
+ dom.push({
6176
+ childCount: 3,
6177
+ className: SearchFieldContainer,
6178
+ role: None$2,
6179
+ type: Div
6180
+ }, ...searchFieldDom, ...getSearchEditorContextLinesVirtualDom(contextLines, contextLinesEnabled));
6181
+ } else {
6182
+ dom.push(...searchFieldDom);
6183
+ }
6050
6184
  if (flags & ReplaceExpanded) {
6051
6185
  dom.push(...getSearchFieldVirtualDom(ReplaceValue, replacePlaceholder, HandleInput2, replaceActions.inside, replaceActions.outside));
6052
6186
  }
6053
6187
  return dom;
6054
6188
  };
6055
6189
 
6056
- const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage, matchCount, focus, limitHitWarning) => {
6190
+ const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage, matchCount, focus, limitHitWarning, isSearchEditor = false, contextLines = 1, contextLinesEnabled = false) => {
6057
6191
  const warningDom = getSearchHeaderLimitHitVirtualDom(limitHitWarning);
6058
6192
  const parentNode = {
6059
6193
  childCount: 2 + (warningDom.length > 0 ? 1 : 0),
@@ -6062,7 +6196,7 @@ const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage, matc
6062
6196
  role: None$2,
6063
6197
  type: Div
6064
6198
  };
6065
- const dom = [parentNode, ...getSearchHeaderTopVirtualDom(flags, searchInputErrorMessage, matchCount, focus), ...getSearchHeaderDetailsVirtualDom(flags, message), ...warningDom];
6199
+ const dom = [parentNode, ...getSearchHeaderTopVirtualDom(flags, searchInputErrorMessage, matchCount, focus, isSearchEditor, contextLines, contextLinesEnabled), ...getSearchHeaderDetailsVirtualDom(flags, message), ...warningDom];
6066
6200
  return dom;
6067
6201
  };
6068
6202
 
@@ -6312,7 +6446,7 @@ const getSearchResultsVirtualDom = (visibleItems, focusOutline, scrollbarHeight,
6312
6446
  };
6313
6447
 
6314
6448
  const className = mergeClassNames(Viewlet, Search$3);
6315
- const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchInputErrorMessage, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight, matchCount, limitHitWarning, focus = 0, initial = false) => {
6449
+ const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchInputErrorMessage, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight, matchCount, limitHitWarning, focus = 0, initial = false, isSearchEditor = false, contextLines = 1, contextLinesEnabled = false) => {
6316
6450
  if (initial) {
6317
6451
  return [];
6318
6452
  }
@@ -6322,12 +6456,12 @@ const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchI
6322
6456
  childCount,
6323
6457
  className,
6324
6458
  type: Div
6325
- }, ...getSearchHeaderVirtualDom(flags, message, searchInputErrorMessage, matchCount, focus, limitHitWarning), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight)];
6459
+ }, ...getSearchHeaderVirtualDom(flags, message, searchInputErrorMessage, matchCount, focus, limitHitWarning, isSearchEditor, contextLines, contextLinesEnabled), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight)];
6326
6460
  };
6327
6461
 
6328
6462
  const getDom = newState => {
6329
6463
  const viewModel = createViewModel(newState);
6330
- 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);
6464
+ 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, newState.isSearchEditor, newState.contextLines, newState.contextLinesEnabled);
6331
6465
  return dom;
6332
6466
  };
6333
6467
 
@@ -6583,45 +6717,6 @@ const renderEventListeners = () => {
6583
6717
  }];
6584
6718
  };
6585
6719
 
6586
- const prompt = (text, options) => {
6587
- return invoke$1('ConfirmPrompt.prompt', text, options);
6588
- };
6589
-
6590
- const getReplaceAllConfirmText = (matchCount, fileCount, replacement) => {
6591
- if (matchCount === 1) {
6592
- if (replacement) {
6593
- return confirmReplaceOneOccurrenceInOneFile(replacement);
6594
- }
6595
- return confirmReplaceOneOccurrenceInOneFileNoValue();
6596
- }
6597
- if (fileCount === 1) {
6598
- if (replacement) {
6599
- return confirmReplaceManyOccurrencesInOneFile(matchCount, replacement);
6600
- }
6601
- return confirmReplaceManyOccurrencesInOneFileNoValue(matchCount);
6602
- }
6603
- if (replacement) {
6604
- return confirmReplaceManyOccurrencesInManyFiles(matchCount, fileCount, replacement);
6605
- }
6606
- return confirmReplaceManyOccurrencesInManyFilesNoValue(matchCount, fileCount);
6607
- };
6608
-
6609
- const replaceAllAndPrompt = async (workspacePath, items, replacement, matchCount, fileCount) => {
6610
- string(workspacePath);
6611
- array(items);
6612
- string(replacement);
6613
- number(matchCount);
6614
- number(fileCount);
6615
- const confirmTitle = replaceAll$1();
6616
- const confirmAccept = replace();
6617
- const confirmText = getReplaceAllConfirmText(matchCount, fileCount, replacement);
6618
- const shouldReplace = await prompt(confirmText, {
6619
- confirmMessage: confirmAccept,
6620
- title: confirmTitle
6621
- });
6622
- return shouldReplace;
6623
- };
6624
-
6625
6720
  const replaceAllInFile = async state => {
6626
6721
  // TODO replace occurrance for focused file
6627
6722
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-view",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Text Search View",
5
5
  "keywords": [
6
6
  "text-search"