@lvce-editor/text-search-worker 2.4.0 → 2.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/textSearchWorkerMain.js +1383 -1172
- package/package.json +1 -1
|
@@ -86,7 +86,7 @@ const set$1 = (id, fn) => {
|
|
|
86
86
|
const get$1 = id => {
|
|
87
87
|
return state$1.callbacks[id];
|
|
88
88
|
};
|
|
89
|
-
const remove = id => {
|
|
89
|
+
const remove$1 = id => {
|
|
90
90
|
delete state$1.callbacks[id];
|
|
91
91
|
};
|
|
92
92
|
const state$2 = {
|
|
@@ -119,7 +119,7 @@ const resolve = (id, args) => {
|
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
121
|
fn(args);
|
|
122
|
-
remove(id);
|
|
122
|
+
remove$1(id);
|
|
123
123
|
};
|
|
124
124
|
const create$2 = (method, params) => {
|
|
125
125
|
const {
|
|
@@ -429,8 +429,11 @@ const states = Object.create(null);
|
|
|
429
429
|
const get = uid => {
|
|
430
430
|
return states[uid];
|
|
431
431
|
};
|
|
432
|
-
const set = (uid,
|
|
433
|
-
states[uid] =
|
|
432
|
+
const set = (uid, oldState, newState) => {
|
|
433
|
+
states[uid] = {
|
|
434
|
+
oldState,
|
|
435
|
+
newState
|
|
436
|
+
};
|
|
434
437
|
};
|
|
435
438
|
|
|
436
439
|
const create$1 = ({
|
|
@@ -502,136 +505,38 @@ const create = (uid, x, y, width, height, workspacePath) => {
|
|
|
502
505
|
message: '',
|
|
503
506
|
collapsedPaths: []
|
|
504
507
|
};
|
|
505
|
-
set(uid, state);
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
const focusMatchCase$1 = state => {
|
|
509
|
-
return {
|
|
510
|
-
...state,
|
|
511
|
-
focus: FocusSearchMatchCase
|
|
512
|
-
};
|
|
508
|
+
set(uid, state, state);
|
|
513
509
|
};
|
|
514
510
|
|
|
515
|
-
|
|
516
|
-
return {
|
|
517
|
-
...state,
|
|
518
|
-
focus: FocusSearchReplaceInput
|
|
519
|
-
};
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
const focusSearchValue$1 = state => {
|
|
523
|
-
return {
|
|
524
|
-
...state,
|
|
525
|
-
focus: FocusSearchInput
|
|
526
|
-
};
|
|
527
|
-
};
|
|
511
|
+
// based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
|
|
528
512
|
|
|
529
|
-
const
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
513
|
+
const insertInto = (array, start, newItems) => {
|
|
514
|
+
const originalLength = array.length;
|
|
515
|
+
const newItemsLength = newItems.length;
|
|
516
|
+
array.length = originalLength + newItemsLength;
|
|
517
|
+
// Move the items after the start index, start from the end so that we don't overwrite any value.
|
|
518
|
+
for (let i = originalLength - 1; i >= start; i--) {
|
|
519
|
+
array[i + newItemsLength] = array[i];
|
|
520
|
+
}
|
|
521
|
+
for (let i = 0; i < newItemsLength; i++) {
|
|
522
|
+
array[i + start] = newItems[i];
|
|
535
523
|
}
|
|
536
|
-
return focusMatchCase$1(state);
|
|
537
524
|
};
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
const None = 'none';
|
|
541
|
-
const Status = 'status';
|
|
542
|
-
const Tree = 'tree';
|
|
543
|
-
const TreeItem$1 = 'treeitem';
|
|
544
|
-
const ToolBar = 'toolbar';
|
|
545
|
-
|
|
546
|
-
const Chevron = 'Chevron';
|
|
547
|
-
const CloseMaskIcon = 'MaskIcon MaskIconClose';
|
|
548
|
-
const Empty = '';
|
|
549
|
-
const FileIcon = 'FileIcon';
|
|
550
|
-
const IconButton = 'IconButton';
|
|
551
|
-
const Actions = 'Actions';
|
|
552
|
-
const FocusOutline = 'FocusOutline';
|
|
553
|
-
const Highlight = 'Highlight';
|
|
554
|
-
const HighlightDeleted = 'HighlightDeleted';
|
|
555
|
-
const HighlightInserted = 'HighlightInserted';
|
|
556
|
-
const Label = 'Label';
|
|
557
|
-
const List = 'List';
|
|
558
|
-
const MaskIcon = 'MaskIcon';
|
|
559
|
-
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
560
|
-
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
561
|
-
const MultilineInputBox = 'MultilineInputBox';
|
|
562
|
-
const Search$1 = 'Search';
|
|
563
|
-
const SearchField = 'SearchField';
|
|
564
|
-
const SearchFieldButtons = 'SearchFieldButtons';
|
|
565
|
-
const SearchFieldContainer = 'SearchFieldContainer';
|
|
566
|
-
const SearchHeader = 'SearchHeader';
|
|
567
|
-
const SearchHeaderTop = 'SearchHeaderTop';
|
|
568
|
-
const SearchRemove = 'SearchRemove';
|
|
569
|
-
const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
|
|
570
|
-
const SourceControlBadge = 'SourceControlBadge';
|
|
571
|
-
const TreeItem = 'TreeItem';
|
|
572
|
-
const TreeItemActive = 'TreeItemActive';
|
|
573
|
-
const Viewlet = 'Viewlet';
|
|
574
|
-
const ViewletSearchMessage = 'ViewletSearchMessage';
|
|
575
|
-
|
|
576
|
-
const Button$1 = 1;
|
|
577
|
-
|
|
578
|
-
const Button = 1;
|
|
579
|
-
const Div = 4;
|
|
580
|
-
const Input = 6;
|
|
581
|
-
const Span = 8;
|
|
582
|
-
const Text = 12;
|
|
583
|
-
const Img = 17;
|
|
584
|
-
const Ins = 20;
|
|
585
|
-
const Del = 21;
|
|
586
|
-
const TextArea = 62;
|
|
587
|
-
|
|
588
|
-
const getIconVirtualDom = (icon, type = Div) => {
|
|
589
|
-
return {
|
|
590
|
-
type,
|
|
591
|
-
className: `MaskIcon MaskIcon${icon}`,
|
|
592
|
-
role: None,
|
|
593
|
-
childCount: 0
|
|
594
|
-
};
|
|
525
|
+
const push = (array, newItems) => {
|
|
526
|
+
insertInto(array, array.length, newItems);
|
|
595
527
|
};
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
const {
|
|
599
|
-
id,
|
|
600
|
-
icon,
|
|
601
|
-
command
|
|
602
|
-
} = action;
|
|
603
|
-
return [{
|
|
604
|
-
type: Button,
|
|
605
|
-
className: IconButton,
|
|
606
|
-
title: id,
|
|
607
|
-
'data-command': command,
|
|
608
|
-
childCount: 1
|
|
609
|
-
}, getIconVirtualDom(icon)];
|
|
528
|
+
const isLastIndex = (array, index) => {
|
|
529
|
+
return index === array.length - 1;
|
|
610
530
|
};
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
switch (action.type) {
|
|
614
|
-
case Button$1:
|
|
615
|
-
return getActionButtonVirtualDom(action);
|
|
616
|
-
default:
|
|
617
|
-
return [];
|
|
618
|
-
}
|
|
531
|
+
const lastIndex = array => {
|
|
532
|
+
return array.length - 1;
|
|
619
533
|
};
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
role: ToolBar,
|
|
626
|
-
childCount: actions.length
|
|
627
|
-
}, ...actions.flatMap(getActionVirtualDom)];
|
|
534
|
+
const toSpliced = (array, index, deleteCount, ...inserted) => {
|
|
535
|
+
return [...array.slice(0, index), ...inserted, ...array.slice(index + deleteCount)];
|
|
536
|
+
};
|
|
537
|
+
const remove = (array, index, deleteCount) => {
|
|
538
|
+
return toSpliced(array, index, deleteCount);
|
|
628
539
|
};
|
|
629
|
-
|
|
630
|
-
const ClearAll = 'ClearAll';
|
|
631
|
-
const CollapseAll = 'CollapseAll';
|
|
632
|
-
const ListFlat = 'ListFlat';
|
|
633
|
-
const NewFile = 'NewFile';
|
|
634
|
-
const Refresh = 'Refresh';
|
|
635
540
|
|
|
636
541
|
class AssertionError extends Error {
|
|
637
542
|
constructor(message) {
|
|
@@ -754,870 +659,747 @@ const collapseAll = () => {
|
|
|
754
659
|
return i18nString(UiStrings.CollapseAll);
|
|
755
660
|
};
|
|
756
661
|
|
|
757
|
-
const
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
id: openNewSearchEditor(),
|
|
771
|
-
icon: NewFile,
|
|
772
|
-
command: ''
|
|
773
|
-
}, {
|
|
774
|
-
type: Button$1,
|
|
775
|
-
id: viewAsTree(),
|
|
776
|
-
icon: ListFlat,
|
|
777
|
-
command: ''
|
|
778
|
-
}, {
|
|
779
|
-
type: Button$1,
|
|
780
|
-
id: collapseAll(),
|
|
781
|
-
icon: CollapseAll,
|
|
782
|
-
command: ''
|
|
783
|
-
}];
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
const getFileIcon = () => {
|
|
787
|
-
return '';
|
|
662
|
+
const getStatusMessage = (resultCount, fileResultCount) => {
|
|
663
|
+
number(resultCount);
|
|
664
|
+
number(fileResultCount);
|
|
665
|
+
if (resultCount === 0) {
|
|
666
|
+
return noResults();
|
|
667
|
+
}
|
|
668
|
+
if (resultCount === 1) {
|
|
669
|
+
return oneResult();
|
|
670
|
+
}
|
|
671
|
+
if (fileResultCount === 1) {
|
|
672
|
+
return manyResultsInOneFile(resultCount);
|
|
673
|
+
}
|
|
674
|
+
return manyResultsInManyFiles(resultCount, fileResultCount);
|
|
788
675
|
};
|
|
789
676
|
|
|
790
677
|
const File$1 = 1;
|
|
791
678
|
const Match = 2;
|
|
792
679
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
680
|
+
const getSetSize = (items, index) => {
|
|
681
|
+
let setSize = 0;
|
|
682
|
+
for (let i = index + 1; i < items.length; i++) {
|
|
683
|
+
if (items[i].type === File$1) {
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
setSize++;
|
|
800
687
|
}
|
|
801
|
-
return
|
|
688
|
+
return setSize;
|
|
802
689
|
};
|
|
803
|
-
|
|
804
|
-
const
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
const
|
|
817
|
-
|
|
818
|
-
|
|
690
|
+
const getRemoveIndicesFile = (items, item, index, matchCount, fileCount) => {
|
|
691
|
+
const setSize = getSetSize(items, index);
|
|
692
|
+
return {
|
|
693
|
+
startIndex: index,
|
|
694
|
+
removeCount: setSize + 1,
|
|
695
|
+
newFocusedIndex: index + setSize + 1 < items.length ? index : index - 1,
|
|
696
|
+
newFileCount: fileCount - 1,
|
|
697
|
+
newMatchCount: matchCount - setSize
|
|
698
|
+
};
|
|
699
|
+
};
|
|
700
|
+
const getRemoveIndicesMatch = (items, index, matchCount, fileCount) => {
|
|
701
|
+
for (let i = index; i >= 0; i--) {
|
|
702
|
+
if (items[i].type === File$1) {
|
|
703
|
+
const setSize = getSetSize(items, i);
|
|
704
|
+
if (setSize === 1) {
|
|
705
|
+
return {
|
|
706
|
+
startIndex: i,
|
|
707
|
+
removeCount: 2,
|
|
708
|
+
newFocusedIndex: i - 1,
|
|
709
|
+
newFileCount: fileCount - 1,
|
|
710
|
+
newMatchCount: matchCount - 1
|
|
711
|
+
};
|
|
712
|
+
}
|
|
819
713
|
return {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
setSize,
|
|
826
|
-
top,
|
|
827
|
-
lineNumber,
|
|
828
|
-
matchStart: 0,
|
|
829
|
-
matchLength: 0,
|
|
830
|
-
replacement: '',
|
|
831
|
-
depth: 0,
|
|
832
|
-
matchCount: 0,
|
|
833
|
-
focused
|
|
714
|
+
startIndex: index,
|
|
715
|
+
removeCount: 1,
|
|
716
|
+
newFocusedIndex: index,
|
|
717
|
+
newFileCount: fileCount,
|
|
718
|
+
newMatchCount: matchCount - 1
|
|
834
719
|
};
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
throw new Error('could not compute indices to remove');
|
|
723
|
+
};
|
|
724
|
+
const getRemoveIndices = (items, index, matchCount, fileCount) => {
|
|
725
|
+
const item = items[index];
|
|
726
|
+
switch (item.type) {
|
|
727
|
+
case File$1:
|
|
728
|
+
return getRemoveIndicesFile(items, item, index, matchCount, fileCount);
|
|
835
729
|
case Match:
|
|
836
|
-
return
|
|
837
|
-
title: text,
|
|
838
|
-
type: Match,
|
|
839
|
-
text: text,
|
|
840
|
-
icon: '',
|
|
841
|
-
posInSet,
|
|
842
|
-
setSize,
|
|
843
|
-
top,
|
|
844
|
-
lineNumber,
|
|
845
|
-
matchStart: start,
|
|
846
|
-
matchLength: searchTermLength,
|
|
847
|
-
replacement,
|
|
848
|
-
depth: 1,
|
|
849
|
-
matchCount: 0,
|
|
850
|
-
focused
|
|
851
|
-
};
|
|
730
|
+
return getRemoveIndicesMatch(items, index, matchCount, fileCount);
|
|
852
731
|
default:
|
|
853
|
-
throw new Error('
|
|
732
|
+
throw new Error('unknown search result type');
|
|
854
733
|
}
|
|
855
734
|
};
|
|
856
|
-
|
|
857
|
-
const getFilteredResults = (results, collapsedPaths) => {
|
|
858
|
-
const filteredResults = [];
|
|
859
|
-
let isExcluded = false;
|
|
860
|
-
for (const result of results) {
|
|
861
|
-
if (result.type === File$1) {
|
|
862
|
-
if (collapsedPaths.includes(result.text)) {
|
|
863
|
-
isExcluded = true;
|
|
864
|
-
} else {
|
|
865
|
-
isExcluded = false;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
if (!isExcluded) {
|
|
869
|
-
filteredResults.push(result);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
return filteredResults;
|
|
873
|
-
};
|
|
874
|
-
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, collapsedPaths, focusedIndex) => {
|
|
875
|
-
const displayResults = [];
|
|
876
|
-
const filteredResults = getFilteredResults(results, collapsedPaths);
|
|
877
|
-
const setSize = resultCount;
|
|
878
|
-
const searchTermLength = searchTerm.length;
|
|
879
|
-
let fileResult = {
|
|
880
|
-
matchCount: 0
|
|
881
|
-
};
|
|
882
|
-
for (let i = minLineY; i < maxLineY; i++) {
|
|
883
|
-
const result = filteredResults[i];
|
|
884
|
-
const displayResult = getDisplayResult(result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
|
|
885
|
-
displayResults.push(displayResult);
|
|
886
|
-
if (result.type === File$1) {
|
|
887
|
-
fileResult = displayResult;
|
|
888
|
-
} else {
|
|
889
|
-
fileResult.matchCount++;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
return displayResults;
|
|
893
|
-
};
|
|
894
|
-
|
|
895
|
-
const HandleClick = 'handleClick';
|
|
896
|
-
const HandleHeaderClick = 'handleHeaderClick';
|
|
897
|
-
const HandleHeaderFocusIn = 'handleHeaderFocusIn';
|
|
898
|
-
const HandleListBlur = 'handleListBlur';
|
|
899
|
-
|
|
900
|
-
const getSearchFieldButtonVirtualDom = button => {
|
|
735
|
+
const removeItemFromItems = (items, index, matchCount, fileCount) => {
|
|
901
736
|
const {
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
}
|
|
915
|
-
type: Div,
|
|
916
|
-
className: `MaskIcon ${icon}`,
|
|
917
|
-
childCount: 0
|
|
918
|
-
}];
|
|
737
|
+
startIndex,
|
|
738
|
+
removeCount,
|
|
739
|
+
newFocusedIndex,
|
|
740
|
+
newFileCount,
|
|
741
|
+
newMatchCount
|
|
742
|
+
} = getRemoveIndices(items, index, matchCount, fileCount);
|
|
743
|
+
const newItems = remove(items, startIndex, removeCount);
|
|
744
|
+
return {
|
|
745
|
+
newItems,
|
|
746
|
+
newFocusedIndex,
|
|
747
|
+
newFileCount,
|
|
748
|
+
newMatchCount
|
|
749
|
+
};
|
|
919
750
|
};
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
spellcheck: false,
|
|
931
|
-
autocapitalize: 'off',
|
|
932
|
-
autocorrect: 'off',
|
|
933
|
-
placeholder,
|
|
934
|
-
name,
|
|
935
|
-
onInput,
|
|
936
|
-
onFocus,
|
|
937
|
-
childCount: 0
|
|
938
|
-
}, {
|
|
939
|
-
type: Div,
|
|
940
|
-
className: SearchFieldButtons,
|
|
941
|
-
childCount: insideButtons.length
|
|
942
|
-
}, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom)];
|
|
943
|
-
if (outsideButtons.length > 0) {
|
|
944
|
-
dom.unshift({
|
|
945
|
-
type: Div,
|
|
946
|
-
className: SearchFieldContainer,
|
|
947
|
-
role: None,
|
|
948
|
-
childCount: 1 + outsideButtons.length
|
|
949
|
-
});
|
|
950
|
-
dom.push(...outsideButtons.flatMap(getSearchFieldButtonVirtualDom));
|
|
751
|
+
const getNewMinMax = (newItemsLength, minLineY, maxLineY, deltaY, itemHeight) => {
|
|
752
|
+
if (maxLineY > newItemsLength) {
|
|
753
|
+
const diff = maxLineY - minLineY;
|
|
754
|
+
const newMinLineY = Math.max(newItemsLength - diff, 0);
|
|
755
|
+
const newDeltaY = newMinLineY * itemHeight;
|
|
756
|
+
return {
|
|
757
|
+
newDeltaY,
|
|
758
|
+
newMinLineY,
|
|
759
|
+
newMaxLineY: newItemsLength
|
|
760
|
+
};
|
|
951
761
|
}
|
|
952
|
-
return dom;
|
|
953
|
-
};
|
|
954
|
-
|
|
955
|
-
const text = data => {
|
|
956
762
|
return {
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
763
|
+
newDeltaY: deltaY,
|
|
764
|
+
newMinLineY: minLineY,
|
|
765
|
+
newMaxLineY: maxLineY
|
|
960
766
|
};
|
|
961
767
|
};
|
|
962
|
-
|
|
963
|
-
const
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
childCount: 2
|
|
976
|
-
}, {
|
|
977
|
-
type: Button,
|
|
978
|
-
className: `IconButton SearchToggleButton ${replaceExpanded ? SearchToggleButtonExpanded : ''}`,
|
|
979
|
-
title: 'Toggle Replace',
|
|
980
|
-
ariaLabel: 'Toggle Replace',
|
|
981
|
-
ariaExpanded: replaceExpanded,
|
|
982
|
-
childCount: 1,
|
|
983
|
-
'data-command': 'toggleReplace'
|
|
984
|
-
}, {
|
|
985
|
-
type: Div,
|
|
986
|
-
className: `${MaskIcon} ${replaceExpanded ? MaskIconChevronDown : MaskIconChevronRight}`,
|
|
987
|
-
childCount: 0
|
|
988
|
-
}, {
|
|
989
|
-
type: Div,
|
|
990
|
-
className: 'SearchHeaderTopRight',
|
|
991
|
-
role: None,
|
|
992
|
-
childCount: replaceExpanded ? 2 : 1
|
|
993
|
-
}, ...getSearchFieldVirtualDom('search-value', 'Search', 'handleInput', [{
|
|
994
|
-
icon: 'MaskIconCaseSensitive',
|
|
995
|
-
checked: matchCase,
|
|
996
|
-
title: 'Match Case'
|
|
997
|
-
}, {
|
|
998
|
-
icon: 'MaskIconWholeWord',
|
|
999
|
-
checked: matchWholeWord,
|
|
1000
|
-
title: 'Match Whole Word'
|
|
1001
|
-
}, {
|
|
1002
|
-
icon: 'MaskIconRegex',
|
|
1003
|
-
checked: useRegularExpression,
|
|
1004
|
-
title: 'Use Regular Expression'
|
|
1005
|
-
}], [])];
|
|
1006
|
-
if (replaceExpanded) {
|
|
1007
|
-
dom.push(...getSearchFieldVirtualDom('search-replace-value', 'Replace', 'handleReplaceInput', [{
|
|
1008
|
-
icon: 'MaskIconPreserveCase',
|
|
1009
|
-
checked: false,
|
|
1010
|
-
title: 'Preserve Case'
|
|
1011
|
-
}], [{
|
|
1012
|
-
icon: 'MaskIconReplaceAll',
|
|
1013
|
-
checked: false,
|
|
1014
|
-
title: 'Replace All'
|
|
1015
|
-
}]));
|
|
1016
|
-
}
|
|
1017
|
-
if (detailsExpanded) {
|
|
1018
|
-
console.log({
|
|
1019
|
-
detailsExpanded
|
|
1020
|
-
});
|
|
1021
|
-
dom[0].childCount++;
|
|
1022
|
-
dom.push({
|
|
1023
|
-
type: Div,
|
|
1024
|
-
className: 'SearchHeaderDetails',
|
|
1025
|
-
childCount: 4
|
|
1026
|
-
}, text('files to include'), {
|
|
1027
|
-
type: Input,
|
|
1028
|
-
childCount: 0
|
|
1029
|
-
}, text('files to exclude'), {
|
|
1030
|
-
type: Input,
|
|
1031
|
-
childCount: 0
|
|
1032
|
-
});
|
|
768
|
+
const dismissItem = state => {
|
|
769
|
+
const {
|
|
770
|
+
items,
|
|
771
|
+
listFocusedIndex,
|
|
772
|
+
fileCount,
|
|
773
|
+
matchCount,
|
|
774
|
+
minLineY,
|
|
775
|
+
maxLineY,
|
|
776
|
+
deltaY,
|
|
777
|
+
itemHeight
|
|
778
|
+
} = state;
|
|
779
|
+
if (listFocusedIndex === -1) {
|
|
780
|
+
return state;
|
|
1033
781
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
782
|
+
const {
|
|
783
|
+
newItems,
|
|
784
|
+
newFocusedIndex,
|
|
785
|
+
newMatchCount,
|
|
786
|
+
newFileCount
|
|
787
|
+
} = removeItemFromItems(items, listFocusedIndex, matchCount, fileCount);
|
|
788
|
+
const message = getStatusMessage(newMatchCount, newFileCount);
|
|
789
|
+
const {
|
|
790
|
+
newMinLineY,
|
|
791
|
+
newMaxLineY,
|
|
792
|
+
newDeltaY
|
|
793
|
+
} = getNewMinMax(newItems.length, minLineY, maxLineY, deltaY, itemHeight);
|
|
794
|
+
return {
|
|
795
|
+
...state,
|
|
796
|
+
items: newItems,
|
|
797
|
+
listFocusedIndex: newFocusedIndex,
|
|
798
|
+
message,
|
|
799
|
+
matchCount: newMatchCount,
|
|
800
|
+
fileCount: newFileCount,
|
|
801
|
+
minLineY: newMinLineY,
|
|
802
|
+
maxLineY: newMaxLineY,
|
|
803
|
+
deltaY: newDeltaY
|
|
804
|
+
};
|
|
1043
805
|
};
|
|
1044
806
|
|
|
1045
|
-
const
|
|
807
|
+
const focusMatchCase$1 = state => {
|
|
1046
808
|
return {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
childCount: 0
|
|
809
|
+
...state,
|
|
810
|
+
focus: FocusSearchMatchCase
|
|
1050
811
|
};
|
|
1051
812
|
};
|
|
1052
813
|
|
|
1053
|
-
const
|
|
814
|
+
const focusReplaceValue$1 = state => {
|
|
1054
815
|
return {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
src: icon,
|
|
1058
|
-
role: None,
|
|
1059
|
-
childCount: 0
|
|
816
|
+
...state,
|
|
817
|
+
focus: FocusSearchReplaceInput
|
|
1060
818
|
};
|
|
1061
819
|
};
|
|
1062
820
|
|
|
1063
|
-
const
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
};
|
|
1068
|
-
const inserted = {
|
|
1069
|
-
type: Ins,
|
|
1070
|
-
className: HighlightInserted,
|
|
1071
|
-
childCount: 1
|
|
1072
|
-
};
|
|
1073
|
-
const highlighted = {
|
|
1074
|
-
type: Span,
|
|
1075
|
-
className: Highlight,
|
|
1076
|
-
childCount: 1
|
|
1077
|
-
};
|
|
1078
|
-
const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) => {
|
|
1079
|
-
const dom = [];
|
|
1080
|
-
const label = {
|
|
1081
|
-
type: Div,
|
|
1082
|
-
className: Label + ' Grow',
|
|
1083
|
-
childCount: 1
|
|
821
|
+
const focusSearchValue$1 = state => {
|
|
822
|
+
return {
|
|
823
|
+
...state,
|
|
824
|
+
focus: FocusSearchInput
|
|
1084
825
|
};
|
|
1085
|
-
dom.push(label);
|
|
1086
|
-
if (matchLength) {
|
|
1087
|
-
const before = displayText.slice(0, matchStart);
|
|
1088
|
-
const highlight = displayText.slice(matchStart, matchStart + matchLength);
|
|
1089
|
-
const after = displayText.slice(matchStart + matchLength);
|
|
1090
|
-
if (replacement) {
|
|
1091
|
-
dom.push(text(before), deleted, text(highlight), inserted, text(replacement), text(after));
|
|
1092
|
-
label.childCount = 4;
|
|
1093
|
-
} else {
|
|
1094
|
-
label.childCount = 3;
|
|
1095
|
-
dom.push(text(before), highlighted, text(highlight), text(after));
|
|
1096
|
-
}
|
|
1097
|
-
} else {
|
|
1098
|
-
dom.push(text(displayText));
|
|
1099
|
-
}
|
|
1100
|
-
return dom;
|
|
1101
826
|
};
|
|
1102
827
|
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1105
|
-
const getSearchResultVirtualDom = rowInfo => {
|
|
828
|
+
const focusSearchValueNext = state => {
|
|
1106
829
|
const {
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
title,
|
|
1112
|
-
icon,
|
|
1113
|
-
setSize,
|
|
1114
|
-
posInSet,
|
|
1115
|
-
depth,
|
|
1116
|
-
replacement,
|
|
1117
|
-
matchCount,
|
|
1118
|
-
focused
|
|
1119
|
-
} = rowInfo;
|
|
1120
|
-
const treeItem = {
|
|
1121
|
-
type: Div,
|
|
1122
|
-
role: TreeItem$1,
|
|
1123
|
-
className: TreeItem,
|
|
1124
|
-
title,
|
|
1125
|
-
ariaSetSize: setSize,
|
|
1126
|
-
ariaLevel: depth,
|
|
1127
|
-
ariaPosInSet: posInSet,
|
|
1128
|
-
ariaLabel: title,
|
|
1129
|
-
ariaDescription: '',
|
|
1130
|
-
childCount: 1,
|
|
1131
|
-
paddingLeft: `${Number(depth) + 1}rem`,
|
|
1132
|
-
// TODO use classname and dynamic css
|
|
1133
|
-
paddingRight: PaddingRight
|
|
1134
|
-
};
|
|
1135
|
-
if (focused) {
|
|
1136
|
-
treeItem.className += ' ' + TreeItemActive;
|
|
1137
|
-
}
|
|
1138
|
-
switch (type) {
|
|
1139
|
-
case File$1:
|
|
1140
|
-
treeItem.ariaExpanded = 'true';
|
|
1141
|
-
break;
|
|
1142
|
-
}
|
|
1143
|
-
const dom = [];
|
|
1144
|
-
dom.push(treeItem);
|
|
1145
|
-
if (type === File$1) {
|
|
1146
|
-
treeItem.childCount += 2;
|
|
1147
|
-
dom.push(getChevronDownVirtualDom(), getFileIconVirtualDom(icon));
|
|
1148
|
-
}
|
|
1149
|
-
dom.push(...getLabelVirtualDom(displayText, matchLength, matchStart, replacement));
|
|
1150
|
-
if (matchCount) {
|
|
1151
|
-
treeItem.childCount++;
|
|
1152
|
-
dom.push(...getBadgeVirtualDom(SourceControlBadge, matchCount));
|
|
830
|
+
replaceExpanded
|
|
831
|
+
} = state;
|
|
832
|
+
if (replaceExpanded) {
|
|
833
|
+
return focusReplaceValue$1(state);
|
|
1153
834
|
}
|
|
1154
|
-
|
|
1155
|
-
dom.push({
|
|
1156
|
-
type: Div,
|
|
1157
|
-
className: SearchRemove,
|
|
1158
|
-
childCount: 1
|
|
1159
|
-
}, {
|
|
1160
|
-
type: Div,
|
|
1161
|
-
className: CloseMaskIcon,
|
|
1162
|
-
childCount: 0
|
|
1163
|
-
});
|
|
1164
|
-
return dom;
|
|
835
|
+
return focusMatchCase$1(state);
|
|
1165
836
|
};
|
|
1166
837
|
|
|
1167
|
-
const
|
|
1168
|
-
|
|
1169
|
-
|
|
838
|
+
const CheckBox = 'checkbox';
|
|
839
|
+
const None = 'none';
|
|
840
|
+
const Status = 'status';
|
|
841
|
+
const Tree = 'tree';
|
|
842
|
+
const TreeItem$1 = 'treeitem';
|
|
843
|
+
const ToolBar = 'toolbar';
|
|
1170
844
|
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
-
|
|
845
|
+
const Chevron = 'Chevron';
|
|
846
|
+
const CloseMaskIcon = 'MaskIcon MaskIconClose';
|
|
847
|
+
const Empty = '';
|
|
848
|
+
const FileIcon = 'FileIcon';
|
|
849
|
+
const IconButton = 'IconButton';
|
|
850
|
+
const Actions = 'Actions';
|
|
851
|
+
const FocusOutline = 'FocusOutline';
|
|
852
|
+
const Highlight = 'Highlight';
|
|
853
|
+
const HighlightDeleted = 'HighlightDeleted';
|
|
854
|
+
const HighlightInserted = 'HighlightInserted';
|
|
855
|
+
const Label = 'Label';
|
|
856
|
+
const List = 'List';
|
|
857
|
+
const MaskIcon = 'MaskIcon';
|
|
858
|
+
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
859
|
+
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
860
|
+
const MultilineInputBox = 'MultilineInputBox';
|
|
861
|
+
const Search$1 = 'Search';
|
|
862
|
+
const SearchField = 'SearchField';
|
|
863
|
+
const SearchFieldButtons = 'SearchFieldButtons';
|
|
864
|
+
const SearchFieldContainer = 'SearchFieldContainer';
|
|
865
|
+
const SearchHeader = 'SearchHeader';
|
|
866
|
+
const SearchHeaderTop = 'SearchHeaderTop';
|
|
867
|
+
const SearchRemove = 'SearchRemove';
|
|
868
|
+
const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
|
|
869
|
+
const SourceControlBadge = 'SourceControlBadge';
|
|
870
|
+
const TreeItem = 'TreeItem';
|
|
871
|
+
const TreeItemActive = 'TreeItemActive';
|
|
872
|
+
const Viewlet = 'Viewlet';
|
|
873
|
+
const ViewletSearchMessage = 'ViewletSearchMessage';
|
|
1174
874
|
|
|
1175
|
-
const
|
|
1176
|
-
/**
|
|
1177
|
-
* @type {any[]}
|
|
1178
|
-
*/
|
|
1179
|
-
const dom = [];
|
|
1180
|
-
dom.push({
|
|
1181
|
-
type: Div,
|
|
1182
|
-
className: mergeClassNames(Viewlet, Search$1),
|
|
1183
|
-
childCount: 2
|
|
1184
|
-
});
|
|
1185
|
-
dom.push(...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded));
|
|
1186
|
-
dom.push({
|
|
1187
|
-
type: Div,
|
|
1188
|
-
className: ViewletSearchMessage,
|
|
1189
|
-
role: Status,
|
|
1190
|
-
tabIndex: 0,
|
|
1191
|
-
childCount: 1
|
|
1192
|
-
}, text(message));
|
|
1193
|
-
dom.push({
|
|
1194
|
-
type: Div,
|
|
1195
|
-
className: mergeClassNames(Viewlet, List, focusOutline ? FocusOutline : Empty),
|
|
1196
|
-
role: Tree,
|
|
1197
|
-
tabIndex: 0,
|
|
1198
|
-
childCount: visibleItems.length,
|
|
1199
|
-
onClick: HandleClick,
|
|
1200
|
-
onBlur: HandleListBlur
|
|
1201
|
-
});
|
|
1202
|
-
dom.push(...getSearchResultsVirtualDom(visibleItems));
|
|
1203
|
-
return dom;
|
|
1204
|
-
};
|
|
875
|
+
const Button$1 = 1;
|
|
1205
876
|
|
|
1206
|
-
const
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
877
|
+
const Button = 1;
|
|
878
|
+
const Div = 4;
|
|
879
|
+
const Input = 6;
|
|
880
|
+
const Span = 8;
|
|
881
|
+
const Text = 12;
|
|
882
|
+
const Img = 17;
|
|
883
|
+
const Ins = 20;
|
|
884
|
+
const Del = 21;
|
|
885
|
+
const TextArea = 62;
|
|
886
|
+
|
|
887
|
+
const getIconVirtualDom = (icon, type = Div) => {
|
|
1211
888
|
return {
|
|
1212
|
-
|
|
1213
|
-
|
|
889
|
+
type,
|
|
890
|
+
className: `MaskIcon MaskIcon${icon}`,
|
|
891
|
+
role: None,
|
|
892
|
+
childCount: 0
|
|
1214
893
|
};
|
|
1215
894
|
};
|
|
1216
895
|
|
|
1217
|
-
const
|
|
1218
|
-
|
|
896
|
+
const getActionButtonVirtualDom = action => {
|
|
897
|
+
const {
|
|
898
|
+
id,
|
|
899
|
+
icon,
|
|
900
|
+
command
|
|
901
|
+
} = action;
|
|
902
|
+
return [{
|
|
903
|
+
type: Button,
|
|
904
|
+
className: IconButton,
|
|
905
|
+
title: id,
|
|
906
|
+
'data-command': command,
|
|
907
|
+
childCount: 1
|
|
908
|
+
}, getIconVirtualDom(icon)];
|
|
1219
909
|
};
|
|
1220
|
-
|
|
1221
|
-
|
|
910
|
+
|
|
911
|
+
const getActionVirtualDom = action => {
|
|
912
|
+
switch (action.type) {
|
|
913
|
+
case Button$1:
|
|
914
|
+
return getActionButtonVirtualDom(action);
|
|
915
|
+
default:
|
|
916
|
+
return [];
|
|
917
|
+
}
|
|
1222
918
|
};
|
|
1223
|
-
|
|
1224
|
-
|
|
919
|
+
|
|
920
|
+
const getActionsVirtualDom = actions => {
|
|
921
|
+
return [{
|
|
922
|
+
type: Div,
|
|
923
|
+
className: Actions,
|
|
924
|
+
role: ToolBar,
|
|
925
|
+
childCount: actions.length
|
|
926
|
+
}, ...actions.flatMap(getActionVirtualDom)];
|
|
1225
927
|
};
|
|
1226
|
-
|
|
1227
|
-
|
|
928
|
+
|
|
929
|
+
const ClearAll = 'ClearAll';
|
|
930
|
+
const CollapseAll = 'CollapseAll';
|
|
931
|
+
const ListFlat = 'ListFlat';
|
|
932
|
+
const NewFile = 'NewFile';
|
|
933
|
+
const Refresh = 'Refresh';
|
|
934
|
+
|
|
935
|
+
const getActions = () => {
|
|
936
|
+
return [{
|
|
937
|
+
type: Button$1,
|
|
938
|
+
id: refresh$1(),
|
|
939
|
+
icon: Refresh,
|
|
940
|
+
command: 'refresh'
|
|
941
|
+
}, {
|
|
942
|
+
type: Button$1,
|
|
943
|
+
id: clearSearchResults(),
|
|
944
|
+
icon: ClearAll,
|
|
945
|
+
command: 'clearSearchResults'
|
|
946
|
+
}, {
|
|
947
|
+
type: Button$1,
|
|
948
|
+
id: openNewSearchEditor(),
|
|
949
|
+
icon: NewFile,
|
|
950
|
+
command: ''
|
|
951
|
+
}, {
|
|
952
|
+
type: Button$1,
|
|
953
|
+
id: viewAsTree(),
|
|
954
|
+
icon: ListFlat,
|
|
955
|
+
command: ''
|
|
956
|
+
}, {
|
|
957
|
+
type: Button$1,
|
|
958
|
+
id: collapseAll(),
|
|
959
|
+
icon: CollapseAll,
|
|
960
|
+
command: ''
|
|
961
|
+
}];
|
|
1228
962
|
};
|
|
1229
963
|
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
// 20px fill 100px but when scrolled 6 items are needed
|
|
1233
|
-
const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
1234
|
-
return Math.ceil(listHeight / itemHeight) + 1;
|
|
964
|
+
const getFileIcon = () => {
|
|
965
|
+
return '';
|
|
1235
966
|
};
|
|
1236
967
|
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
|
|
1241
|
-
const newDeltaY = newMinLineY * itemHeight;
|
|
1242
|
-
return {
|
|
1243
|
-
...state,
|
|
1244
|
-
focusedIndex: index,
|
|
1245
|
-
minLineY: newMinLineY,
|
|
1246
|
-
maxLineY: newMaxLineY,
|
|
1247
|
-
focused: true,
|
|
1248
|
-
deltaY: newDeltaY
|
|
1249
|
-
};
|
|
968
|
+
// TODO this should be in FileSystem module
|
|
969
|
+
const pathBaseName = path => {
|
|
970
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
1250
971
|
};
|
|
1251
|
-
const
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
|
|
1255
|
-
const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
|
|
1256
|
-
return {
|
|
1257
|
-
...state,
|
|
1258
|
-
focusedIndex: index,
|
|
1259
|
-
minLineY: newMinLineY,
|
|
1260
|
-
maxLineY: newMaxLineY,
|
|
1261
|
-
focused: true,
|
|
1262
|
-
deltaY: newDeltaY
|
|
1263
|
-
};
|
|
1264
|
-
};
|
|
1265
|
-
const focusIndex = (state, index) => {
|
|
1266
|
-
const {
|
|
1267
|
-
itemHeight,
|
|
1268
|
-
minLineY,
|
|
1269
|
-
maxLineY,
|
|
1270
|
-
headerHeight,
|
|
1271
|
-
height,
|
|
1272
|
-
items
|
|
1273
|
-
} = state;
|
|
1274
|
-
const itemsLength = items.length;
|
|
1275
|
-
if (itemsLength === 0) {
|
|
1276
|
-
return state;
|
|
1277
|
-
}
|
|
1278
|
-
number(itemHeight);
|
|
1279
|
-
if (index === -1) {
|
|
1280
|
-
return {
|
|
1281
|
-
...state,
|
|
1282
|
-
focusedIndex: -1,
|
|
1283
|
-
focused: true
|
|
1284
|
-
};
|
|
1285
|
-
}
|
|
1286
|
-
const listHeight = height - headerHeight;
|
|
1287
|
-
if (index < minLineY + 1) {
|
|
1288
|
-
return focusIndexScrollUp(state, index, listHeight, itemHeight, itemsLength);
|
|
1289
|
-
}
|
|
1290
|
-
if (index >= maxLineY - 1) {
|
|
1291
|
-
return focusIndexScrollDown(state, index, listHeight, itemHeight, itemsLength);
|
|
972
|
+
const getAbsolutePath = relativePath => {
|
|
973
|
+
if (relativePath.startsWith('./')) {
|
|
974
|
+
return `/${relativePath.slice(2)}`; // TODO support windows paths
|
|
1292
975
|
}
|
|
1293
|
-
return {
|
|
1294
|
-
...state,
|
|
1295
|
-
focusedIndex: index,
|
|
1296
|
-
focused: true
|
|
1297
|
-
};
|
|
1298
|
-
};
|
|
1299
|
-
|
|
1300
|
-
const focusFirst = state => {
|
|
1301
|
-
const firstIndex = first();
|
|
1302
|
-
return focusIndex(state, firstIndex);
|
|
1303
|
-
};
|
|
1304
|
-
|
|
1305
|
-
const focusLast = state => {
|
|
1306
|
-
const {
|
|
1307
|
-
items
|
|
1308
|
-
} = state;
|
|
1309
|
-
const lastIndex = last(items);
|
|
1310
|
-
return focusIndex(state, lastIndex);
|
|
976
|
+
return `/${relativePath}`; // TODO support windows paths
|
|
1311
977
|
};
|
|
1312
978
|
|
|
1313
|
-
const
|
|
979
|
+
const getDisplayResult = (result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex) => {
|
|
1314
980
|
const {
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
981
|
+
type,
|
|
982
|
+
text,
|
|
983
|
+
lineNumber,
|
|
984
|
+
start
|
|
985
|
+
} = result;
|
|
986
|
+
const posInSet = i + 1;
|
|
987
|
+
const top = i * itemHeight;
|
|
988
|
+
const focused = i === focusedIndex;
|
|
989
|
+
switch (type) {
|
|
990
|
+
case File$1:
|
|
991
|
+
const path = text;
|
|
992
|
+
const absolutePath = getAbsolutePath(path);
|
|
993
|
+
const baseName = pathBaseName(path);
|
|
994
|
+
return {
|
|
995
|
+
title: absolutePath,
|
|
996
|
+
type: File$1,
|
|
997
|
+
text: baseName,
|
|
998
|
+
icon: getFileIcon(),
|
|
999
|
+
posInSet,
|
|
1000
|
+
setSize,
|
|
1001
|
+
top,
|
|
1002
|
+
lineNumber,
|
|
1003
|
+
matchStart: 0,
|
|
1004
|
+
matchLength: 0,
|
|
1005
|
+
replacement: '',
|
|
1006
|
+
depth: 0,
|
|
1007
|
+
matchCount: 0,
|
|
1008
|
+
focused
|
|
1009
|
+
};
|
|
1010
|
+
case Match:
|
|
1011
|
+
return {
|
|
1012
|
+
title: text,
|
|
1013
|
+
type: Match,
|
|
1014
|
+
text: text,
|
|
1015
|
+
icon: '',
|
|
1016
|
+
posInSet,
|
|
1017
|
+
setSize,
|
|
1018
|
+
top,
|
|
1019
|
+
lineNumber,
|
|
1020
|
+
matchStart: start,
|
|
1021
|
+
matchLength: searchTermLength,
|
|
1022
|
+
replacement,
|
|
1023
|
+
depth: 1,
|
|
1024
|
+
matchCount: 0,
|
|
1025
|
+
focused
|
|
1026
|
+
};
|
|
1027
|
+
default:
|
|
1028
|
+
throw new Error('unexpected search result type');
|
|
1029
|
+
}
|
|
1320
1030
|
};
|
|
1321
1031
|
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
const
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1032
|
+
const getFilteredResults = (results, collapsedPaths) => {
|
|
1033
|
+
const filteredResults = [];
|
|
1034
|
+
let isExcluded = false;
|
|
1035
|
+
for (const result of results) {
|
|
1036
|
+
if (result.type === File$1) {
|
|
1037
|
+
if (collapsedPaths.includes(result.text)) {
|
|
1038
|
+
isExcluded = true;
|
|
1039
|
+
} else {
|
|
1040
|
+
isExcluded = false;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
if (!isExcluded) {
|
|
1044
|
+
filteredResults.push(result);
|
|
1045
|
+
}
|
|
1334
1046
|
}
|
|
1047
|
+
return filteredResults;
|
|
1335
1048
|
};
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
const
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
if (isLastIndex(items, focusedIndex)) {
|
|
1354
|
-
return state;
|
|
1049
|
+
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, collapsedPaths, focusedIndex) => {
|
|
1050
|
+
const displayResults = [];
|
|
1051
|
+
const filteredResults = getFilteredResults(results, collapsedPaths);
|
|
1052
|
+
const setSize = resultCount;
|
|
1053
|
+
const searchTermLength = searchTerm.length;
|
|
1054
|
+
let fileResult = {
|
|
1055
|
+
matchCount: 0
|
|
1056
|
+
};
|
|
1057
|
+
for (let i = minLineY; i < maxLineY; i++) {
|
|
1058
|
+
const result = filteredResults[i];
|
|
1059
|
+
const displayResult = getDisplayResult(result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
|
|
1060
|
+
displayResults.push(displayResult);
|
|
1061
|
+
if (result.type === File$1) {
|
|
1062
|
+
fileResult = displayResult;
|
|
1063
|
+
} else {
|
|
1064
|
+
fileResult.matchCount++;
|
|
1065
|
+
}
|
|
1355
1066
|
}
|
|
1356
|
-
|
|
1357
|
-
return focusIndex(state, indexNextPage);
|
|
1067
|
+
return displayResults;
|
|
1358
1068
|
};
|
|
1359
1069
|
|
|
1360
|
-
const
|
|
1070
|
+
const HandleClick = 'handleClick';
|
|
1071
|
+
const HandleHeaderClick = 'handleHeaderClick';
|
|
1072
|
+
const HandleHeaderFocusIn = 'handleHeaderFocusIn';
|
|
1073
|
+
const HandleListBlur = 'handleListBlur';
|
|
1074
|
+
|
|
1075
|
+
const getSearchFieldButtonVirtualDom = button => {
|
|
1361
1076
|
const {
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
} =
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1077
|
+
icon,
|
|
1078
|
+
checked,
|
|
1079
|
+
title
|
|
1080
|
+
} = button;
|
|
1081
|
+
return [{
|
|
1082
|
+
type: Div,
|
|
1083
|
+
className: `SearchFieldButton ${checked ? 'SearchFieldButtonChecked' : ''}`,
|
|
1084
|
+
title,
|
|
1085
|
+
role: CheckBox,
|
|
1086
|
+
ariaChecked: checked,
|
|
1087
|
+
tabIndex: 0,
|
|
1088
|
+
childCount: 1
|
|
1089
|
+
}, {
|
|
1090
|
+
type: Div,
|
|
1091
|
+
className: `MaskIcon ${icon}`,
|
|
1092
|
+
childCount: 0
|
|
1093
|
+
}];
|
|
1371
1094
|
};
|
|
1372
1095
|
|
|
1373
|
-
const
|
|
1374
|
-
const {
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1096
|
+
const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '') => {
|
|
1097
|
+
const dom = [{
|
|
1098
|
+
type: Div,
|
|
1099
|
+
className: SearchField,
|
|
1100
|
+
role: None,
|
|
1101
|
+
childCount: 2
|
|
1102
|
+
}, {
|
|
1103
|
+
type: TextArea,
|
|
1104
|
+
className: MultilineInputBox,
|
|
1105
|
+
spellcheck: false,
|
|
1106
|
+
autocapitalize: 'off',
|
|
1107
|
+
autocorrect: 'off',
|
|
1108
|
+
placeholder,
|
|
1109
|
+
name,
|
|
1110
|
+
onInput,
|
|
1111
|
+
onFocus,
|
|
1112
|
+
childCount: 0
|
|
1113
|
+
}, {
|
|
1114
|
+
type: Div,
|
|
1115
|
+
className: SearchFieldButtons,
|
|
1116
|
+
childCount: insideButtons.length
|
|
1117
|
+
}, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom)];
|
|
1118
|
+
if (outsideButtons.length > 0) {
|
|
1119
|
+
dom.unshift({
|
|
1120
|
+
type: Div,
|
|
1121
|
+
className: SearchFieldContainer,
|
|
1122
|
+
role: None,
|
|
1123
|
+
childCount: 1 + outsideButtons.length
|
|
1124
|
+
});
|
|
1125
|
+
dom.push(...outsideButtons.flatMap(getSearchFieldButtonVirtualDom));
|
|
1380
1126
|
}
|
|
1381
|
-
|
|
1382
|
-
return focusIndex(state, previousIndex);
|
|
1127
|
+
return dom;
|
|
1383
1128
|
};
|
|
1384
1129
|
|
|
1385
|
-
const
|
|
1386
|
-
const relativeY = eventY - y + deltaY;
|
|
1387
|
-
const index = Math.floor(relativeY / itemHeight);
|
|
1388
|
-
return index;
|
|
1389
|
-
};
|
|
1390
|
-
|
|
1391
|
-
const openUri = async (path, focus = true, props = {}) => {
|
|
1392
|
-
await invoke$1(/* Main.openUri */'Main.openUri', /* uri */path, /* focus */focus, props);
|
|
1393
|
-
};
|
|
1394
|
-
|
|
1395
|
-
const getFileIndex = (items, index) => {
|
|
1396
|
-
for (let i = index; i >= 0; i--) {
|
|
1397
|
-
const item = items[i];
|
|
1398
|
-
if (item.type === File$1) {
|
|
1399
|
-
return i;
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
return -1;
|
|
1403
|
-
};
|
|
1404
|
-
const selectIndexFile = async (state, searchResult, index) => {
|
|
1405
|
-
const {
|
|
1406
|
-
collapsedPaths
|
|
1407
|
-
} = state;
|
|
1408
|
-
const path = getAbsolutePath(searchResult.text);
|
|
1409
|
-
string(path);
|
|
1410
|
-
return {
|
|
1411
|
-
...state,
|
|
1412
|
-
collapsedPaths: [...collapsedPaths, path],
|
|
1413
|
-
listFocusedIndex: index,
|
|
1414
|
-
listFocused: true
|
|
1415
|
-
};
|
|
1416
|
-
};
|
|
1417
|
-
const selectIndexPreview = async (state, searchResult, index) => {
|
|
1418
|
-
const {
|
|
1419
|
-
items
|
|
1420
|
-
} = state;
|
|
1421
|
-
const fileIndex = getFileIndex(items, index);
|
|
1422
|
-
if (fileIndex === -1) {
|
|
1423
|
-
throw new Error('Search result is missing file');
|
|
1424
|
-
}
|
|
1425
|
-
const {
|
|
1426
|
-
lineNumber
|
|
1427
|
-
} = searchResult;
|
|
1428
|
-
// console.log({ searchResult })
|
|
1429
|
-
const fileResult = items[fileIndex];
|
|
1430
|
-
const path = getAbsolutePath(fileResult.text);
|
|
1431
|
-
string(path);
|
|
1432
|
-
await openUri(path, true, {
|
|
1433
|
-
selections: new Uint32Array([lineNumber, 0, lineNumber, 0])
|
|
1434
|
-
});
|
|
1130
|
+
const text = data => {
|
|
1435
1131
|
return {
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1132
|
+
type: Text,
|
|
1133
|
+
text: data,
|
|
1134
|
+
childCount: 0
|
|
1439
1135
|
};
|
|
1440
1136
|
};
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1137
|
+
|
|
1138
|
+
const getSearchHeaderVirtualDom = (replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded) => {
|
|
1139
|
+
const dom = [{
|
|
1140
|
+
type: Div,
|
|
1141
|
+
className: SearchHeader,
|
|
1142
|
+
role: None,
|
|
1143
|
+
childCount: 2,
|
|
1144
|
+
onClick: HandleHeaderClick,
|
|
1145
|
+
onFocusIn: HandleHeaderFocusIn
|
|
1146
|
+
}, {
|
|
1147
|
+
type: Div,
|
|
1148
|
+
className: SearchHeaderTop,
|
|
1149
|
+
role: None,
|
|
1150
|
+
childCount: 2
|
|
1151
|
+
}, {
|
|
1152
|
+
type: Button,
|
|
1153
|
+
className: `IconButton SearchToggleButton ${replaceExpanded ? SearchToggleButtonExpanded : ''}`,
|
|
1154
|
+
title: 'Toggle Replace',
|
|
1155
|
+
ariaLabel: 'Toggle Replace',
|
|
1156
|
+
ariaExpanded: replaceExpanded,
|
|
1157
|
+
childCount: 1,
|
|
1158
|
+
'data-command': 'toggleReplace'
|
|
1159
|
+
}, {
|
|
1160
|
+
type: Div,
|
|
1161
|
+
className: `${MaskIcon} ${replaceExpanded ? MaskIconChevronDown : MaskIconChevronRight}`,
|
|
1162
|
+
childCount: 0
|
|
1163
|
+
}, {
|
|
1164
|
+
type: Div,
|
|
1165
|
+
className: 'SearchHeaderTopRight',
|
|
1166
|
+
role: None,
|
|
1167
|
+
childCount: replaceExpanded ? 2 : 1
|
|
1168
|
+
}, ...getSearchFieldVirtualDom('search-value', 'Search', 'handleInput', [{
|
|
1169
|
+
icon: 'MaskIconCaseSensitive',
|
|
1170
|
+
checked: matchCase,
|
|
1171
|
+
title: 'Match Case'
|
|
1172
|
+
}, {
|
|
1173
|
+
icon: 'MaskIconWholeWord',
|
|
1174
|
+
checked: matchWholeWord,
|
|
1175
|
+
title: 'Match Whole Word'
|
|
1176
|
+
}, {
|
|
1177
|
+
icon: 'MaskIconRegex',
|
|
1178
|
+
checked: useRegularExpression,
|
|
1179
|
+
title: 'Use Regular Expression'
|
|
1180
|
+
}], [])];
|
|
1181
|
+
if (replaceExpanded) {
|
|
1182
|
+
dom.push(...getSearchFieldVirtualDom('search-replace-value', 'Replace', 'handleReplaceInput', [{
|
|
1183
|
+
icon: 'MaskIconPreserveCase',
|
|
1184
|
+
checked: false,
|
|
1185
|
+
title: 'Preserve Case'
|
|
1186
|
+
}], [{
|
|
1187
|
+
icon: 'MaskIconReplaceAll',
|
|
1188
|
+
checked: false,
|
|
1189
|
+
title: 'Replace All'
|
|
1190
|
+
}]));
|
|
1448
1191
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1192
|
+
if (detailsExpanded) {
|
|
1193
|
+
console.log({
|
|
1194
|
+
detailsExpanded
|
|
1195
|
+
});
|
|
1196
|
+
dom[0].childCount++;
|
|
1197
|
+
dom.push({
|
|
1198
|
+
type: Div,
|
|
1199
|
+
className: 'SearchHeaderDetails',
|
|
1200
|
+
childCount: 4
|
|
1201
|
+
}, text('files to include'), {
|
|
1202
|
+
type: Input,
|
|
1203
|
+
childCount: 0
|
|
1204
|
+
}, text('files to exclude'), {
|
|
1205
|
+
type: Input,
|
|
1206
|
+
childCount: 0
|
|
1207
|
+
});
|
|
1460
1208
|
}
|
|
1209
|
+
return dom;
|
|
1461
1210
|
};
|
|
1462
1211
|
|
|
1463
|
-
const
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
} = state;
|
|
1470
|
-
const index = getListIndex(eventX, eventY, x, y, deltaY, itemHeight);
|
|
1471
|
-
return selectIndex(state, index);
|
|
1212
|
+
const getBadgeVirtualDom = (className, count) => {
|
|
1213
|
+
return [{
|
|
1214
|
+
type: Div,
|
|
1215
|
+
className: `Badge ${className}`,
|
|
1216
|
+
childCount: 1
|
|
1217
|
+
}, text(`${count}`)];
|
|
1472
1218
|
};
|
|
1473
1219
|
|
|
1474
|
-
const
|
|
1220
|
+
const getChevronDownVirtualDom = (extraClassName = '') => {
|
|
1475
1221
|
return {
|
|
1476
|
-
|
|
1477
|
-
|
|
1222
|
+
type: Div,
|
|
1223
|
+
className: `${Chevron} MaskIconChevronDown ${extraClassName}`,
|
|
1224
|
+
childCount: 0
|
|
1478
1225
|
};
|
|
1479
1226
|
};
|
|
1480
1227
|
|
|
1481
|
-
|
|
1482
|
-
*
|
|
1483
|
-
* @param {number} size
|
|
1484
|
-
* @param {number} contentSize
|
|
1485
|
-
* @param {number} minimumSliderSize
|
|
1486
|
-
* @returns
|
|
1487
|
-
*/
|
|
1488
|
-
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
1489
|
-
if (size >= contentSize) {
|
|
1490
|
-
return 0;
|
|
1491
|
-
}
|
|
1492
|
-
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
1493
|
-
};
|
|
1494
|
-
const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
|
|
1495
|
-
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
1496
|
-
return scrollBarOffset;
|
|
1497
|
-
};
|
|
1498
|
-
const getScrollBarY = getScrollBarOffset;
|
|
1499
|
-
const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
|
|
1500
|
-
const halfScrollBarHeight = scrollBarHeight / 2;
|
|
1501
|
-
if (relativeY <= halfScrollBarHeight) {
|
|
1502
|
-
// clicked at top
|
|
1503
|
-
return {
|
|
1504
|
-
percent: 0,
|
|
1505
|
-
handleOffset: relativeY
|
|
1506
|
-
};
|
|
1507
|
-
}
|
|
1508
|
-
if (relativeY <= height - halfScrollBarHeight) {
|
|
1509
|
-
// clicked in middle
|
|
1510
|
-
return {
|
|
1511
|
-
percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
|
|
1512
|
-
handleOffset: halfScrollBarHeight
|
|
1513
|
-
};
|
|
1514
|
-
}
|
|
1515
|
-
// clicked at bottom
|
|
1228
|
+
const getFileIconVirtualDom = icon => {
|
|
1516
1229
|
return {
|
|
1517
|
-
|
|
1518
|
-
|
|
1230
|
+
type: Img,
|
|
1231
|
+
className: FileIcon,
|
|
1232
|
+
src: icon,
|
|
1233
|
+
role: None,
|
|
1234
|
+
childCount: 0
|
|
1519
1235
|
};
|
|
1520
1236
|
};
|
|
1521
1237
|
|
|
1522
|
-
const
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1238
|
+
const deleted = {
|
|
1239
|
+
type: Del,
|
|
1240
|
+
className: HighlightDeleted,
|
|
1241
|
+
childCount: 1
|
|
1242
|
+
};
|
|
1243
|
+
const inserted = {
|
|
1244
|
+
type: Ins,
|
|
1245
|
+
className: HighlightInserted,
|
|
1246
|
+
childCount: 1
|
|
1247
|
+
};
|
|
1248
|
+
const highlighted = {
|
|
1249
|
+
type: Span,
|
|
1250
|
+
className: Highlight,
|
|
1251
|
+
childCount: 1
|
|
1252
|
+
};
|
|
1253
|
+
const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) => {
|
|
1254
|
+
const dom = [];
|
|
1255
|
+
const label = {
|
|
1256
|
+
type: Div,
|
|
1257
|
+
className: Label + ' Grow',
|
|
1258
|
+
childCount: 1
|
|
1259
|
+
};
|
|
1260
|
+
dom.push(label);
|
|
1261
|
+
if (matchLength) {
|
|
1262
|
+
const before = displayText.slice(0, matchStart);
|
|
1263
|
+
const highlight = displayText.slice(matchStart, matchStart + matchLength);
|
|
1264
|
+
const after = displayText.slice(matchStart + matchLength);
|
|
1265
|
+
if (replacement) {
|
|
1266
|
+
dom.push(text(before), deleted, text(highlight), inserted, text(replacement), text(after));
|
|
1267
|
+
label.childCount = 4;
|
|
1268
|
+
} else {
|
|
1269
|
+
label.childCount = 3;
|
|
1270
|
+
dom.push(text(before), highlighted, text(highlight), text(after));
|
|
1271
|
+
}
|
|
1272
|
+
} else {
|
|
1273
|
+
dom.push(text(displayText));
|
|
1274
|
+
}
|
|
1275
|
+
return dom;
|
|
1527
1276
|
};
|
|
1528
1277
|
|
|
1529
|
-
const
|
|
1530
|
-
|
|
1531
|
-
|
|
1278
|
+
const PaddingRight = '12px';
|
|
1279
|
+
|
|
1280
|
+
const getSearchResultVirtualDom = rowInfo => {
|
|
1532
1281
|
const {
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
const
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1282
|
+
type,
|
|
1283
|
+
matchStart,
|
|
1284
|
+
matchLength,
|
|
1285
|
+
text: displayText,
|
|
1286
|
+
title,
|
|
1287
|
+
icon,
|
|
1288
|
+
setSize,
|
|
1289
|
+
posInSet,
|
|
1290
|
+
depth,
|
|
1291
|
+
replacement,
|
|
1292
|
+
matchCount,
|
|
1293
|
+
focused
|
|
1294
|
+
} = rowInfo;
|
|
1295
|
+
const treeItem = {
|
|
1296
|
+
type: Div,
|
|
1297
|
+
role: TreeItem$1,
|
|
1298
|
+
className: TreeItem,
|
|
1299
|
+
title,
|
|
1300
|
+
ariaSetSize: setSize,
|
|
1301
|
+
ariaLevel: depth,
|
|
1302
|
+
ariaPosInSet: posInSet,
|
|
1303
|
+
ariaLabel: title,
|
|
1304
|
+
ariaDescription: '',
|
|
1305
|
+
childCount: 1,
|
|
1306
|
+
paddingLeft: `${Number(depth) + 1}rem`,
|
|
1307
|
+
// TODO use classname and dynamic css
|
|
1308
|
+
paddingRight: PaddingRight
|
|
1552
1309
|
};
|
|
1310
|
+
if (focused) {
|
|
1311
|
+
treeItem.className += ' ' + TreeItemActive;
|
|
1312
|
+
}
|
|
1313
|
+
switch (type) {
|
|
1314
|
+
case File$1:
|
|
1315
|
+
treeItem.ariaExpanded = 'true';
|
|
1316
|
+
break;
|
|
1317
|
+
}
|
|
1318
|
+
const dom = [];
|
|
1319
|
+
dom.push(treeItem);
|
|
1320
|
+
if (type === File$1) {
|
|
1321
|
+
treeItem.childCount += 2;
|
|
1322
|
+
dom.push(getChevronDownVirtualDom(), getFileIconVirtualDom(icon));
|
|
1323
|
+
}
|
|
1324
|
+
dom.push(...getLabelVirtualDom(displayText, matchLength, matchStart, replacement));
|
|
1325
|
+
if (matchCount) {
|
|
1326
|
+
treeItem.childCount++;
|
|
1327
|
+
dom.push(...getBadgeVirtualDom(SourceControlBadge, matchCount));
|
|
1328
|
+
}
|
|
1329
|
+
treeItem.childCount++;
|
|
1330
|
+
dom.push({
|
|
1331
|
+
type: Div,
|
|
1332
|
+
className: SearchRemove,
|
|
1333
|
+
childCount: 1
|
|
1334
|
+
}, {
|
|
1335
|
+
type: Div,
|
|
1336
|
+
className: CloseMaskIcon,
|
|
1337
|
+
childCount: 0
|
|
1338
|
+
});
|
|
1339
|
+
return dom;
|
|
1553
1340
|
};
|
|
1554
1341
|
|
|
1555
|
-
const
|
|
1556
|
-
|
|
1557
|
-
y,
|
|
1558
|
-
deltaY,
|
|
1559
|
-
headerHeight,
|
|
1560
|
-
finalDeltaY,
|
|
1561
|
-
scrollBarHeight,
|
|
1562
|
-
height
|
|
1563
|
-
} = state;
|
|
1564
|
-
const contentHeight = height - headerHeight;
|
|
1565
|
-
const relativeY = eventY - y - headerHeight;
|
|
1566
|
-
const currentScrollBarY = getScrollBarY(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
|
|
1567
|
-
const diff = relativeY - currentScrollBarY;
|
|
1568
|
-
if (diff >= 0 && diff < scrollBarHeight) {
|
|
1569
|
-
return {
|
|
1570
|
-
...state,
|
|
1571
|
-
handleOffset: diff,
|
|
1572
|
-
scrollBarActive: true
|
|
1573
|
-
};
|
|
1574
|
-
}
|
|
1575
|
-
const {
|
|
1576
|
-
percent,
|
|
1577
|
-
handleOffset
|
|
1578
|
-
} = getNewDeltaPercent(contentHeight, scrollBarHeight, relativeY);
|
|
1579
|
-
const newDeltaY = percent * finalDeltaY;
|
|
1580
|
-
return {
|
|
1581
|
-
...setDeltaY(state, newDeltaY),
|
|
1582
|
-
handleOffset,
|
|
1583
|
-
scrollBarActive: true
|
|
1584
|
-
};
|
|
1342
|
+
const getSearchResultsVirtualDom = visibleItems => {
|
|
1343
|
+
return visibleItems.flatMap(getSearchResultVirtualDom);
|
|
1585
1344
|
};
|
|
1586
1345
|
|
|
1587
|
-
const
|
|
1588
|
-
|
|
1589
|
-
// clicked in middle
|
|
1590
|
-
return relativeY / (contentHeight - scrollBarHeight);
|
|
1591
|
-
}
|
|
1592
|
-
// clicked at bottom
|
|
1593
|
-
return 1;
|
|
1346
|
+
const mergeClassNames = (...classNames) => {
|
|
1347
|
+
return classNames.filter(Boolean).join(' ');
|
|
1594
1348
|
};
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1349
|
+
|
|
1350
|
+
const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWholeWord, useRegularExpression, message, detailsExpanded, focusOutline) => {
|
|
1351
|
+
/**
|
|
1352
|
+
* @type {any[]}
|
|
1353
|
+
*/
|
|
1354
|
+
const dom = [];
|
|
1355
|
+
dom.push({
|
|
1356
|
+
type: Div,
|
|
1357
|
+
className: mergeClassNames(Viewlet, Search$1),
|
|
1358
|
+
childCount: 2
|
|
1359
|
+
});
|
|
1360
|
+
dom.push(...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded));
|
|
1361
|
+
dom.push({
|
|
1362
|
+
type: Div,
|
|
1363
|
+
className: ViewletSearchMessage,
|
|
1364
|
+
role: Status,
|
|
1365
|
+
tabIndex: 0,
|
|
1366
|
+
childCount: 1
|
|
1367
|
+
}, text(message));
|
|
1368
|
+
dom.push({
|
|
1369
|
+
type: Div,
|
|
1370
|
+
className: mergeClassNames(Viewlet, List, focusOutline ? FocusOutline : Empty),
|
|
1371
|
+
role: Tree,
|
|
1372
|
+
tabIndex: 0,
|
|
1373
|
+
childCount: visibleItems.length,
|
|
1374
|
+
onClick: HandleClick,
|
|
1375
|
+
onBlur: HandleListBlur
|
|
1376
|
+
});
|
|
1377
|
+
dom.push(...getSearchResultsVirtualDom(visibleItems));
|
|
1378
|
+
return dom;
|
|
1609
1379
|
};
|
|
1610
1380
|
|
|
1611
|
-
const
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1381
|
+
const handleIconThemeChange = state => {
|
|
1382
|
+
const {
|
|
1383
|
+
items
|
|
1384
|
+
} = state;
|
|
1385
|
+
const newItems = [...items];
|
|
1386
|
+
return {
|
|
1387
|
+
...state,
|
|
1388
|
+
items: newItems
|
|
1389
|
+
};
|
|
1615
1390
|
};
|
|
1616
1391
|
|
|
1617
1392
|
const handleError = async (error, notify = true, prefix = '') => {
|
|
1618
1393
|
console.error(`[text-search-worker] ${error}`);
|
|
1619
1394
|
};
|
|
1620
1395
|
|
|
1396
|
+
// TODO optimize this function to return the minimum number
|
|
1397
|
+
// of visible items needed, e.g. when not scrolled 5 items with
|
|
1398
|
+
// 20px fill 100px but when scrolled 6 items are needed
|
|
1399
|
+
const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
1400
|
+
return Math.ceil(listHeight / itemHeight) + 1;
|
|
1401
|
+
};
|
|
1402
|
+
|
|
1621
1403
|
const getTextSearchResultCounts = results => {
|
|
1622
1404
|
let resultCount = 0;
|
|
1623
1405
|
let fileCount = 0;
|
|
@@ -1643,6 +1425,47 @@ const isEmptyString = string => {
|
|
|
1643
1425
|
return string === EmptyString;
|
|
1644
1426
|
};
|
|
1645
1427
|
|
|
1428
|
+
/**
|
|
1429
|
+
*
|
|
1430
|
+
* @param {number} size
|
|
1431
|
+
* @param {number} contentSize
|
|
1432
|
+
* @param {number} minimumSliderSize
|
|
1433
|
+
* @returns
|
|
1434
|
+
*/
|
|
1435
|
+
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
1436
|
+
if (size >= contentSize) {
|
|
1437
|
+
return 0;
|
|
1438
|
+
}
|
|
1439
|
+
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
1440
|
+
};
|
|
1441
|
+
const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
|
|
1442
|
+
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
1443
|
+
return scrollBarOffset;
|
|
1444
|
+
};
|
|
1445
|
+
const getScrollBarY = getScrollBarOffset;
|
|
1446
|
+
const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
|
|
1447
|
+
const halfScrollBarHeight = scrollBarHeight / 2;
|
|
1448
|
+
if (relativeY <= halfScrollBarHeight) {
|
|
1449
|
+
// clicked at top
|
|
1450
|
+
return {
|
|
1451
|
+
percent: 0,
|
|
1452
|
+
handleOffset: relativeY
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
1455
|
+
if (relativeY <= height - halfScrollBarHeight) {
|
|
1456
|
+
// clicked in middle
|
|
1457
|
+
return {
|
|
1458
|
+
percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
|
|
1459
|
+
handleOffset: halfScrollBarHeight
|
|
1460
|
+
};
|
|
1461
|
+
}
|
|
1462
|
+
// clicked at bottom
|
|
1463
|
+
return {
|
|
1464
|
+
percent: 1,
|
|
1465
|
+
handleOffset: scrollBarHeight - height + relativeY
|
|
1466
|
+
};
|
|
1467
|
+
};
|
|
1468
|
+
|
|
1646
1469
|
const RE_PROTOCOL = /^([a-z\-]+):\/\//;
|
|
1647
1470
|
const getProtocol = uri => {
|
|
1648
1471
|
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
@@ -2091,279 +1914,599 @@ const getHandle = async uri => {
|
|
|
2091
1914
|
} catch (error) {
|
|
2092
1915
|
throw new VError$1(error, 'Failed to get handle');
|
|
2093
1916
|
}
|
|
2094
|
-
};
|
|
2095
|
-
|
|
2096
|
-
const getDirectoryHandle = async uri => {
|
|
2097
|
-
const handle = await getHandle(uri);
|
|
2098
|
-
if (handle) {
|
|
2099
|
-
return handle;
|
|
1917
|
+
};
|
|
1918
|
+
|
|
1919
|
+
const getDirectoryHandle = async uri => {
|
|
1920
|
+
const handle = await getHandle(uri);
|
|
1921
|
+
if (handle) {
|
|
1922
|
+
return handle;
|
|
1923
|
+
}
|
|
1924
|
+
const dirname$1 = dirname('/', uri);
|
|
1925
|
+
if (uri === dirname$1) {
|
|
1926
|
+
return undefined;
|
|
1927
|
+
}
|
|
1928
|
+
return getDirectoryHandle(dirname$1);
|
|
1929
|
+
};
|
|
1930
|
+
|
|
1931
|
+
const NotReadableError = 'NotReadableError';
|
|
1932
|
+
|
|
1933
|
+
const isNotReadableError = error => {
|
|
1934
|
+
return error && error.name === NotReadableError;
|
|
1935
|
+
};
|
|
1936
|
+
|
|
1937
|
+
const getFile = handle => {
|
|
1938
|
+
return handle.getFile();
|
|
1939
|
+
};
|
|
1940
|
+
|
|
1941
|
+
const textSearchInText = (file, content, query) => {
|
|
1942
|
+
const results = [];
|
|
1943
|
+
const lines = splitLines$1(content);
|
|
1944
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1945
|
+
const line = lines[i];
|
|
1946
|
+
const index = line.indexOf(query);
|
|
1947
|
+
if (index !== -1) {
|
|
1948
|
+
results.push({
|
|
1949
|
+
type: Match,
|
|
1950
|
+
text: line,
|
|
1951
|
+
start: index,
|
|
1952
|
+
end: index + query.length,
|
|
1953
|
+
lineNumber: i
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
if (results.length > 0) {
|
|
1958
|
+
results.unshift({
|
|
1959
|
+
type: File$1,
|
|
1960
|
+
text: file,
|
|
1961
|
+
start: 0,
|
|
1962
|
+
end: 0,
|
|
1963
|
+
lineNumber: 0
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
return results;
|
|
1967
|
+
};
|
|
1968
|
+
|
|
1969
|
+
const textSearchInFile = async (all, handle, absolutePath, query) => {
|
|
1970
|
+
try {
|
|
1971
|
+
const file = await getFile(handle);
|
|
1972
|
+
const content = await file.text();
|
|
1973
|
+
const results = textSearchInText(absolutePath, content, query);
|
|
1974
|
+
push(all, results);
|
|
1975
|
+
} catch (error) {
|
|
1976
|
+
if (isNotReadableError(error)) {
|
|
1977
|
+
// ignore
|
|
1978
|
+
return;
|
|
1979
|
+
}
|
|
1980
|
+
throw error;
|
|
1981
|
+
}
|
|
1982
|
+
};
|
|
1983
|
+
|
|
1984
|
+
const textSearchRecursively = async (all, parent, handle, query) => {
|
|
1985
|
+
const childHandles = [];
|
|
1986
|
+
// TODO
|
|
1987
|
+
// await FileSystemHtml.getChildHandles(handle)
|
|
1988
|
+
const promises = [];
|
|
1989
|
+
for (const childHandle of childHandles) {
|
|
1990
|
+
const absolutePath = parent + '/' + childHandle.name;
|
|
1991
|
+
switch (childHandle.kind) {
|
|
1992
|
+
case Directory:
|
|
1993
|
+
promises.push(textSearchRecursively(all, absolutePath, childHandle, query));
|
|
1994
|
+
break;
|
|
1995
|
+
case File:
|
|
1996
|
+
promises.push(textSearchInFile(all, childHandle, absolutePath, query));
|
|
1997
|
+
break;
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
await Promise.all(promises);
|
|
2001
|
+
};
|
|
2002
|
+
const textSearch$3 = async (scheme, root, query) => {
|
|
2003
|
+
string(scheme);
|
|
2004
|
+
string(root);
|
|
2005
|
+
string(query);
|
|
2006
|
+
const relativeRoot = root.slice('html://'.length);
|
|
2007
|
+
const handle = await getDirectoryHandle(relativeRoot);
|
|
2008
|
+
if (!handle) {
|
|
2009
|
+
throw new VError$1(`Folder not found ${relativeRoot}`);
|
|
2010
|
+
}
|
|
2011
|
+
const all = [];
|
|
2012
|
+
await textSearchRecursively(all, '', handle, query);
|
|
2013
|
+
return all;
|
|
2014
|
+
};
|
|
2015
|
+
|
|
2016
|
+
const getRipGrepArgs = ({
|
|
2017
|
+
threads,
|
|
2018
|
+
isCaseSensitive,
|
|
2019
|
+
searchString,
|
|
2020
|
+
useRegularExpression
|
|
2021
|
+
}) => {
|
|
2022
|
+
const ripGrepArgs = ['--hidden', '--no-require-git', '--smart-case', '--stats', '--json'];
|
|
2023
|
+
ripGrepArgs.push('--threads', `${threads}`);
|
|
2024
|
+
if (isCaseSensitive) {
|
|
2025
|
+
ripGrepArgs.push('--case-sensitive');
|
|
2026
|
+
} else {
|
|
2027
|
+
ripGrepArgs.push('--ignore-case');
|
|
2028
|
+
}
|
|
2029
|
+
if (useRegularExpression) {
|
|
2030
|
+
ripGrepArgs.push('--regexp', searchString);
|
|
2031
|
+
} else {
|
|
2032
|
+
ripGrepArgs.push('--fixed-strings');
|
|
2033
|
+
ripGrepArgs.push('--');
|
|
2034
|
+
ripGrepArgs.push(searchString);
|
|
2035
|
+
}
|
|
2036
|
+
ripGrepArgs.push('.');
|
|
2037
|
+
return ripGrepArgs;
|
|
2038
|
+
};
|
|
2039
|
+
|
|
2040
|
+
const invoke = (method, ...params) => {
|
|
2041
|
+
return invoke$1('SearchProcess.invoke', method, ...params);
|
|
2042
|
+
};
|
|
2043
|
+
|
|
2044
|
+
const textSearch$2 = async (scheme, root, query, options) => {
|
|
2045
|
+
const ripGrepArgs = getRipGrepArgs({
|
|
2046
|
+
...options,
|
|
2047
|
+
searchString: query
|
|
2048
|
+
});
|
|
2049
|
+
const actualOptions = {
|
|
2050
|
+
ripGrepArgs,
|
|
2051
|
+
searchDir: root
|
|
2052
|
+
};
|
|
2053
|
+
const result = await invoke('TextSearch.search', actualOptions);
|
|
2054
|
+
// TODO api is weird
|
|
2055
|
+
return result.results;
|
|
2056
|
+
};
|
|
2057
|
+
|
|
2058
|
+
const textSearch$1 = (scheme, root, query) => {
|
|
2059
|
+
// TODO ask renderer worker for files
|
|
2060
|
+
const entries = Object.entries({});
|
|
2061
|
+
const results = [];
|
|
2062
|
+
for (const [key, value] of entries) {
|
|
2063
|
+
// @ts-ignore
|
|
2064
|
+
if (value.includes(query)) {
|
|
2065
|
+
results.push([key, [{
|
|
2066
|
+
absoluteOffset: 0,
|
|
2067
|
+
preview: value
|
|
2068
|
+
}]]);
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
return results;
|
|
2072
|
+
};
|
|
2073
|
+
|
|
2074
|
+
const getProvider = scheme => {
|
|
2075
|
+
switch (scheme) {
|
|
2076
|
+
case '':
|
|
2077
|
+
return textSearch$2;
|
|
2078
|
+
case 'web':
|
|
2079
|
+
return textSearch$1;
|
|
2080
|
+
case 'fetch':
|
|
2081
|
+
return textSearch$4;
|
|
2082
|
+
case 'html':
|
|
2083
|
+
return textSearch$3;
|
|
2084
|
+
default:
|
|
2085
|
+
return textSearch$5;
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
|
|
2089
|
+
const textSearch = async (root, query, options, assetDir) => {
|
|
2090
|
+
string(root);
|
|
2091
|
+
string(query);
|
|
2092
|
+
const scheme = getProtocol(root);
|
|
2093
|
+
const provider = getProvider(scheme);
|
|
2094
|
+
const results = await provider(scheme, root, query, options, assetDir);
|
|
2095
|
+
return results;
|
|
2096
|
+
};
|
|
2097
|
+
|
|
2098
|
+
const handleUpdate = async (state, update) => {
|
|
2099
|
+
const partialNewState = {
|
|
2100
|
+
...state,
|
|
2101
|
+
...update
|
|
2102
|
+
};
|
|
2103
|
+
try {
|
|
2104
|
+
const {
|
|
2105
|
+
height,
|
|
2106
|
+
itemHeight,
|
|
2107
|
+
minimumSliderSize,
|
|
2108
|
+
headerHeight,
|
|
2109
|
+
matchCase,
|
|
2110
|
+
value,
|
|
2111
|
+
threads,
|
|
2112
|
+
useRegularExpression
|
|
2113
|
+
} = partialNewState;
|
|
2114
|
+
if (isEmptyString(value)) {
|
|
2115
|
+
return {
|
|
2116
|
+
...partialNewState,
|
|
2117
|
+
minLineY: 0,
|
|
2118
|
+
maxLineY: 0,
|
|
2119
|
+
deltaY: 0,
|
|
2120
|
+
items: [],
|
|
2121
|
+
matchIndex: 0,
|
|
2122
|
+
matchCount: 0,
|
|
2123
|
+
message: '',
|
|
2124
|
+
loaded: true
|
|
2125
|
+
};
|
|
2126
|
+
}
|
|
2127
|
+
const root = state.workspacePath;
|
|
2128
|
+
const results = await textSearch(root, value, {
|
|
2129
|
+
threads,
|
|
2130
|
+
isCaseSensitive: matchCase,
|
|
2131
|
+
useRegularExpression
|
|
2132
|
+
}, state.assetDir);
|
|
2133
|
+
if (!Array.isArray(results)) {
|
|
2134
|
+
throw new TypeError('results must be of type array');
|
|
2135
|
+
}
|
|
2136
|
+
const {
|
|
2137
|
+
fileCount,
|
|
2138
|
+
resultCount
|
|
2139
|
+
} = getTextSearchResultCounts(results);
|
|
2140
|
+
const message = getStatusMessage(resultCount, fileCount);
|
|
2141
|
+
const total = results.length;
|
|
2142
|
+
const contentHeight = total * itemHeight;
|
|
2143
|
+
const listHeight = height - headerHeight;
|
|
2144
|
+
const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
|
|
2145
|
+
const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
2146
|
+
const maxLineY = Math.min(numberOfVisible, total);
|
|
2147
|
+
const finalDeltaY = Math.max(contentHeight - listHeight, 0);
|
|
2148
|
+
return {
|
|
2149
|
+
...partialNewState,
|
|
2150
|
+
minLineY: 0,
|
|
2151
|
+
deltaY: 0,
|
|
2152
|
+
value,
|
|
2153
|
+
items: results,
|
|
2154
|
+
message,
|
|
2155
|
+
maxLineY: maxLineY,
|
|
2156
|
+
scrollBarHeight,
|
|
2157
|
+
finalDeltaY,
|
|
2158
|
+
threads,
|
|
2159
|
+
fileCount,
|
|
2160
|
+
matchCount: resultCount,
|
|
2161
|
+
loaded: true
|
|
2162
|
+
};
|
|
2163
|
+
} catch (error) {
|
|
2164
|
+
handleError(error);
|
|
2165
|
+
return {
|
|
2166
|
+
...partialNewState,
|
|
2167
|
+
message: `${error}`,
|
|
2168
|
+
items: [],
|
|
2169
|
+
matchCount: 0,
|
|
2170
|
+
fileCount: 0,
|
|
2171
|
+
minLineY: 0,
|
|
2172
|
+
maxLineY: 0
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
};
|
|
2176
|
+
|
|
2177
|
+
const handleInput = (state, value, inputSource = Script) => {
|
|
2178
|
+
return handleUpdate(state, {
|
|
2179
|
+
value,
|
|
2180
|
+
inputSource
|
|
2181
|
+
});
|
|
2182
|
+
};
|
|
2183
|
+
|
|
2184
|
+
const first = () => {
|
|
2185
|
+
return 0;
|
|
2186
|
+
};
|
|
2187
|
+
const last = items => {
|
|
2188
|
+
return items.length - 1;
|
|
2189
|
+
};
|
|
2190
|
+
const next = (items, index) => {
|
|
2191
|
+
return (index + 1) % items.length;
|
|
2192
|
+
};
|
|
2193
|
+
const previous = (items, index) => {
|
|
2194
|
+
return index === 0 ? items.length - 1 : index - 1;
|
|
2195
|
+
};
|
|
2196
|
+
|
|
2197
|
+
const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
2198
|
+
const newMinLineY = index;
|
|
2199
|
+
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
2200
|
+
const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
|
|
2201
|
+
const newDeltaY = newMinLineY * itemHeight;
|
|
2202
|
+
return {
|
|
2203
|
+
...state,
|
|
2204
|
+
focusedIndex: index,
|
|
2205
|
+
minLineY: newMinLineY,
|
|
2206
|
+
maxLineY: newMaxLineY,
|
|
2207
|
+
focused: true,
|
|
2208
|
+
deltaY: newDeltaY
|
|
2209
|
+
};
|
|
2210
|
+
};
|
|
2211
|
+
const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
2212
|
+
const newMaxLineY = Math.min(index + 1, itemsLength);
|
|
2213
|
+
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
2214
|
+
const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
|
|
2215
|
+
const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
|
|
2216
|
+
return {
|
|
2217
|
+
...state,
|
|
2218
|
+
focusedIndex: index,
|
|
2219
|
+
minLineY: newMinLineY,
|
|
2220
|
+
maxLineY: newMaxLineY,
|
|
2221
|
+
focused: true,
|
|
2222
|
+
deltaY: newDeltaY
|
|
2223
|
+
};
|
|
2224
|
+
};
|
|
2225
|
+
const focusIndex = (state, index) => {
|
|
2226
|
+
const {
|
|
2227
|
+
itemHeight,
|
|
2228
|
+
minLineY,
|
|
2229
|
+
maxLineY,
|
|
2230
|
+
headerHeight,
|
|
2231
|
+
height,
|
|
2232
|
+
items
|
|
2233
|
+
} = state;
|
|
2234
|
+
const itemsLength = items.length;
|
|
2235
|
+
if (itemsLength === 0) {
|
|
2236
|
+
return state;
|
|
2237
|
+
}
|
|
2238
|
+
number(itemHeight);
|
|
2239
|
+
if (index === -1) {
|
|
2240
|
+
return {
|
|
2241
|
+
...state,
|
|
2242
|
+
focusedIndex: -1,
|
|
2243
|
+
focused: true
|
|
2244
|
+
};
|
|
2100
2245
|
}
|
|
2101
|
-
const
|
|
2102
|
-
if (
|
|
2103
|
-
return
|
|
2246
|
+
const listHeight = height - headerHeight;
|
|
2247
|
+
if (index < minLineY + 1) {
|
|
2248
|
+
return focusIndexScrollUp(state, index, listHeight, itemHeight, itemsLength);
|
|
2104
2249
|
}
|
|
2105
|
-
|
|
2250
|
+
if (index >= maxLineY - 1) {
|
|
2251
|
+
return focusIndexScrollDown(state, index, listHeight, itemHeight, itemsLength);
|
|
2252
|
+
}
|
|
2253
|
+
return {
|
|
2254
|
+
...state,
|
|
2255
|
+
focusedIndex: index,
|
|
2256
|
+
focused: true
|
|
2257
|
+
};
|
|
2106
2258
|
};
|
|
2107
2259
|
|
|
2108
|
-
const
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
return error && error.name === NotReadableError;
|
|
2260
|
+
const focusFirst = state => {
|
|
2261
|
+
const firstIndex = first();
|
|
2262
|
+
return focusIndex(state, firstIndex);
|
|
2112
2263
|
};
|
|
2113
2264
|
|
|
2114
|
-
const
|
|
2115
|
-
|
|
2265
|
+
const focusLast = state => {
|
|
2266
|
+
const {
|
|
2267
|
+
items
|
|
2268
|
+
} = state;
|
|
2269
|
+
const lastIndex = last(items);
|
|
2270
|
+
return focusIndex(state, lastIndex);
|
|
2116
2271
|
};
|
|
2117
2272
|
|
|
2118
|
-
const
|
|
2119
|
-
const
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
results.push({
|
|
2126
|
-
type: Match,
|
|
2127
|
-
text: line,
|
|
2128
|
-
start: index,
|
|
2129
|
-
end: index + query.length,
|
|
2130
|
-
lineNumber: i
|
|
2131
|
-
});
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
if (results.length > 0) {
|
|
2135
|
-
results.unshift({
|
|
2136
|
-
type: File$1,
|
|
2137
|
-
text: file,
|
|
2138
|
-
start: 0,
|
|
2139
|
-
end: 0,
|
|
2140
|
-
lineNumber: 0
|
|
2141
|
-
});
|
|
2142
|
-
}
|
|
2143
|
-
return results;
|
|
2273
|
+
const focusNext = state => {
|
|
2274
|
+
const {
|
|
2275
|
+
focusedIndex,
|
|
2276
|
+
items
|
|
2277
|
+
} = state;
|
|
2278
|
+
const nextIndex = next(items, focusedIndex);
|
|
2279
|
+
return focusIndex(state, nextIndex);
|
|
2144
2280
|
};
|
|
2145
2281
|
|
|
2146
|
-
const
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
return;
|
|
2156
|
-
}
|
|
2157
|
-
throw error;
|
|
2282
|
+
const focusNextPage = state => {
|
|
2283
|
+
const {
|
|
2284
|
+
focusedIndex,
|
|
2285
|
+
items,
|
|
2286
|
+
maxLineY,
|
|
2287
|
+
minLineY
|
|
2288
|
+
} = state;
|
|
2289
|
+
if (isLastIndex(items, focusedIndex)) {
|
|
2290
|
+
return state;
|
|
2158
2291
|
}
|
|
2292
|
+
const indexNextPage = Math.min(maxLineY + (maxLineY - minLineY) - 2, lastIndex(items));
|
|
2293
|
+
return focusIndex(state, indexNextPage);
|
|
2159
2294
|
};
|
|
2160
2295
|
|
|
2161
|
-
const
|
|
2162
|
-
const
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
case Directory:
|
|
2170
|
-
promises.push(textSearchRecursively(all, absolutePath, childHandle, query));
|
|
2171
|
-
break;
|
|
2172
|
-
case File:
|
|
2173
|
-
promises.push(textSearchInFile(all, childHandle, absolutePath, query));
|
|
2174
|
-
break;
|
|
2175
|
-
}
|
|
2296
|
+
const focusPreviousPage = state => {
|
|
2297
|
+
const {
|
|
2298
|
+
focusedIndex,
|
|
2299
|
+
minLineY,
|
|
2300
|
+
maxLineY
|
|
2301
|
+
} = state;
|
|
2302
|
+
if (focusedIndex === 0 || focusedIndex === -1) {
|
|
2303
|
+
return state;
|
|
2176
2304
|
}
|
|
2177
|
-
|
|
2305
|
+
const indexPreviousPage = Math.max(minLineY - (maxLineY - minLineY) + 1, 0);
|
|
2306
|
+
return focusIndex(state, indexPreviousPage);
|
|
2178
2307
|
};
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
if (
|
|
2186
|
-
|
|
2308
|
+
|
|
2309
|
+
const focusPrevious = state => {
|
|
2310
|
+
const {
|
|
2311
|
+
focusedIndex,
|
|
2312
|
+
items
|
|
2313
|
+
} = state;
|
|
2314
|
+
if (focusedIndex === 0 || focusedIndex === -1) {
|
|
2315
|
+
return state;
|
|
2187
2316
|
}
|
|
2188
|
-
const
|
|
2189
|
-
|
|
2190
|
-
return all;
|
|
2317
|
+
const previousIndex = previous(items, focusedIndex);
|
|
2318
|
+
return focusIndex(state, previousIndex);
|
|
2191
2319
|
};
|
|
2192
2320
|
|
|
2193
|
-
const
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
useRegularExpression
|
|
2198
|
-
}) => {
|
|
2199
|
-
const ripGrepArgs = ['--hidden', '--no-require-git', '--smart-case', '--stats', '--json'];
|
|
2200
|
-
ripGrepArgs.push('--threads', `${threads}`);
|
|
2201
|
-
if (isCaseSensitive) {
|
|
2202
|
-
ripGrepArgs.push('--case-sensitive');
|
|
2203
|
-
} else {
|
|
2204
|
-
ripGrepArgs.push('--ignore-case');
|
|
2205
|
-
}
|
|
2206
|
-
if (useRegularExpression) {
|
|
2207
|
-
ripGrepArgs.push('--regexp', searchString);
|
|
2208
|
-
} else {
|
|
2209
|
-
ripGrepArgs.push('--fixed-strings');
|
|
2210
|
-
ripGrepArgs.push('--');
|
|
2211
|
-
ripGrepArgs.push(searchString);
|
|
2212
|
-
}
|
|
2213
|
-
ripGrepArgs.push('.');
|
|
2214
|
-
return ripGrepArgs;
|
|
2321
|
+
const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight) => {
|
|
2322
|
+
const relativeY = eventY - y + deltaY;
|
|
2323
|
+
const index = Math.floor(relativeY / itemHeight);
|
|
2324
|
+
return index;
|
|
2215
2325
|
};
|
|
2216
2326
|
|
|
2217
|
-
const
|
|
2218
|
-
|
|
2327
|
+
const openUri = async (path, focus = true, props = {}) => {
|
|
2328
|
+
await invoke$1(/* Main.openUri */'Main.openUri', /* uri */path, /* focus */focus, props);
|
|
2219
2329
|
};
|
|
2220
2330
|
|
|
2221
|
-
const
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2331
|
+
const getFileIndex = (items, index) => {
|
|
2332
|
+
for (let i = index; i >= 0; i--) {
|
|
2333
|
+
const item = items[i];
|
|
2334
|
+
if (item.type === File$1) {
|
|
2335
|
+
return i;
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
return -1;
|
|
2339
|
+
};
|
|
2340
|
+
const selectIndexFile = async (state, searchResult, index) => {
|
|
2341
|
+
const {
|
|
2342
|
+
collapsedPaths
|
|
2343
|
+
} = state;
|
|
2344
|
+
const path = getAbsolutePath(searchResult.text);
|
|
2345
|
+
string(path);
|
|
2346
|
+
return {
|
|
2347
|
+
...state,
|
|
2348
|
+
collapsedPaths: [...collapsedPaths, path],
|
|
2349
|
+
listFocusedIndex: index,
|
|
2350
|
+
listFocused: true
|
|
2351
|
+
};
|
|
2352
|
+
};
|
|
2353
|
+
const selectIndexPreview = async (state, searchResult, index) => {
|
|
2354
|
+
const {
|
|
2355
|
+
items
|
|
2356
|
+
} = state;
|
|
2357
|
+
const fileIndex = getFileIndex(items, index);
|
|
2358
|
+
if (fileIndex === -1) {
|
|
2359
|
+
throw new Error('Search result is missing file');
|
|
2360
|
+
}
|
|
2361
|
+
const {
|
|
2362
|
+
lineNumber
|
|
2363
|
+
} = searchResult;
|
|
2364
|
+
// console.log({ searchResult })
|
|
2365
|
+
const fileResult = items[fileIndex];
|
|
2366
|
+
const path = getAbsolutePath(fileResult.text);
|
|
2367
|
+
string(path);
|
|
2368
|
+
await openUri(path, true, {
|
|
2369
|
+
selections: new Uint32Array([lineNumber, 0, lineNumber, 0])
|
|
2225
2370
|
});
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2371
|
+
return {
|
|
2372
|
+
...state,
|
|
2373
|
+
listFocusedIndex: index,
|
|
2374
|
+
listFocused: false
|
|
2229
2375
|
};
|
|
2230
|
-
const result = await invoke('TextSearch.search', actualOptions);
|
|
2231
|
-
// TODO api is weird
|
|
2232
|
-
return result.results;
|
|
2233
2376
|
};
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2377
|
+
const selectIndex = async (state, index, isClose) => {
|
|
2378
|
+
if (index === -1) {
|
|
2379
|
+
return {
|
|
2380
|
+
...state,
|
|
2381
|
+
listFocused: true,
|
|
2382
|
+
listFocusedIndex: -1
|
|
2383
|
+
};
|
|
2384
|
+
}
|
|
2385
|
+
const {
|
|
2386
|
+
items
|
|
2387
|
+
} = state;
|
|
2388
|
+
const searchResult = items[index];
|
|
2389
|
+
switch (searchResult.type) {
|
|
2390
|
+
case File$1:
|
|
2391
|
+
return selectIndexFile(state, searchResult, index);
|
|
2392
|
+
case Match:
|
|
2393
|
+
return selectIndexPreview(state, searchResult, index);
|
|
2394
|
+
default:
|
|
2395
|
+
throw new Error(`unexpected search result type ${searchResult.type}`);
|
|
2247
2396
|
}
|
|
2248
|
-
return results;
|
|
2249
2397
|
};
|
|
2250
2398
|
|
|
2251
|
-
const
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
return textSearch$3;
|
|
2261
|
-
default:
|
|
2262
|
-
return textSearch$5;
|
|
2263
|
-
}
|
|
2399
|
+
const handleClickAt = async (state, eventX, eventY) => {
|
|
2400
|
+
const {
|
|
2401
|
+
x,
|
|
2402
|
+
y,
|
|
2403
|
+
itemHeight,
|
|
2404
|
+
deltaY
|
|
2405
|
+
} = state;
|
|
2406
|
+
const index = getListIndex(eventX, eventY, x, y, deltaY, itemHeight);
|
|
2407
|
+
return selectIndex(state, index);
|
|
2264
2408
|
};
|
|
2265
2409
|
|
|
2266
|
-
const
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
const results = await provider(scheme, root, query, options, assetDir);
|
|
2272
|
-
return results;
|
|
2410
|
+
const handleScrollBarCaptureLost = state => {
|
|
2411
|
+
return {
|
|
2412
|
+
...state,
|
|
2413
|
+
scrollBarActive: false
|
|
2414
|
+
};
|
|
2273
2415
|
};
|
|
2274
2416
|
|
|
2275
|
-
const
|
|
2276
|
-
number(
|
|
2277
|
-
number(
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
}
|
|
2281
|
-
if (resultCount === 1) {
|
|
2282
|
-
return oneResult();
|
|
2283
|
-
}
|
|
2284
|
-
if (fileResultCount === 1) {
|
|
2285
|
-
return manyResultsInOneFile(resultCount);
|
|
2286
|
-
}
|
|
2287
|
-
return manyResultsInManyFiles(resultCount, fileResultCount);
|
|
2417
|
+
const clamp = (num, min, max) => {
|
|
2418
|
+
number(num);
|
|
2419
|
+
number(min);
|
|
2420
|
+
number(max);
|
|
2421
|
+
return Math.min(Math.max(num, min), max);
|
|
2288
2422
|
};
|
|
2289
2423
|
|
|
2290
|
-
const
|
|
2291
|
-
|
|
2424
|
+
const setDeltaY = (state, value) => {
|
|
2425
|
+
object(state);
|
|
2426
|
+
number(value);
|
|
2427
|
+
const {
|
|
2428
|
+
itemHeight,
|
|
2429
|
+
finalDeltaY,
|
|
2430
|
+
deltaY,
|
|
2431
|
+
height,
|
|
2432
|
+
headerHeight
|
|
2433
|
+
} = state;
|
|
2434
|
+
const listHeight = height - headerHeight;
|
|
2435
|
+
const newDeltaY = clamp(value, 0, finalDeltaY);
|
|
2436
|
+
if (deltaY === newDeltaY) {
|
|
2437
|
+
return state;
|
|
2438
|
+
}
|
|
2439
|
+
// TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
|
|
2440
|
+
const minLineY = Math.floor(newDeltaY / itemHeight);
|
|
2441
|
+
const maxLineY = minLineY + getNumberOfVisibleItems(listHeight, itemHeight);
|
|
2442
|
+
return {
|
|
2292
2443
|
...state,
|
|
2293
|
-
|
|
2444
|
+
deltaY: newDeltaY,
|
|
2445
|
+
minLineY,
|
|
2446
|
+
maxLineY
|
|
2294
2447
|
};
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
deltaY: 0,
|
|
2312
|
-
items: [],
|
|
2313
|
-
matchIndex: 0,
|
|
2314
|
-
matchCount: 0,
|
|
2315
|
-
message: '',
|
|
2316
|
-
loaded: true
|
|
2317
|
-
};
|
|
2318
|
-
}
|
|
2319
|
-
const root = state.workspacePath;
|
|
2320
|
-
const results = await textSearch(root, value, {
|
|
2321
|
-
threads,
|
|
2322
|
-
isCaseSensitive: matchCase,
|
|
2323
|
-
useRegularExpression
|
|
2324
|
-
}, state.assetDir);
|
|
2325
|
-
if (!Array.isArray(results)) {
|
|
2326
|
-
throw new TypeError('results must be of type array');
|
|
2327
|
-
}
|
|
2328
|
-
const {
|
|
2329
|
-
fileCount,
|
|
2330
|
-
resultCount
|
|
2331
|
-
} = getTextSearchResultCounts(results);
|
|
2332
|
-
const message = getStatusMessage(resultCount, fileCount);
|
|
2333
|
-
const total = results.length;
|
|
2334
|
-
const contentHeight = total * itemHeight;
|
|
2335
|
-
const listHeight = height - headerHeight;
|
|
2336
|
-
const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
|
|
2337
|
-
const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
2338
|
-
const maxLineY = Math.min(numberOfVisible, total);
|
|
2339
|
-
const finalDeltaY = Math.max(contentHeight - listHeight, 0);
|
|
2340
|
-
return {
|
|
2341
|
-
...partialNewState,
|
|
2342
|
-
minLineY: 0,
|
|
2343
|
-
deltaY: 0,
|
|
2344
|
-
value,
|
|
2345
|
-
items: results,
|
|
2346
|
-
message,
|
|
2347
|
-
maxLineY: maxLineY,
|
|
2348
|
-
scrollBarHeight,
|
|
2349
|
-
finalDeltaY,
|
|
2350
|
-
threads,
|
|
2351
|
-
fileCount,
|
|
2352
|
-
matchCount: resultCount,
|
|
2353
|
-
loaded: true
|
|
2354
|
-
};
|
|
2355
|
-
} catch (error) {
|
|
2356
|
-
handleError(error);
|
|
2448
|
+
};
|
|
2449
|
+
|
|
2450
|
+
const handleScrollBarClick = (state, eventY) => {
|
|
2451
|
+
const {
|
|
2452
|
+
y,
|
|
2453
|
+
deltaY,
|
|
2454
|
+
headerHeight,
|
|
2455
|
+
finalDeltaY,
|
|
2456
|
+
scrollBarHeight,
|
|
2457
|
+
height
|
|
2458
|
+
} = state;
|
|
2459
|
+
const contentHeight = height - headerHeight;
|
|
2460
|
+
const relativeY = eventY - y - headerHeight;
|
|
2461
|
+
const currentScrollBarY = getScrollBarY(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
|
|
2462
|
+
const diff = relativeY - currentScrollBarY;
|
|
2463
|
+
if (diff >= 0 && diff < scrollBarHeight) {
|
|
2357
2464
|
return {
|
|
2358
|
-
...
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
matchCount: 0,
|
|
2362
|
-
fileCount: 0,
|
|
2363
|
-
minLineY: 0,
|
|
2364
|
-
maxLineY: 0
|
|
2465
|
+
...state,
|
|
2466
|
+
handleOffset: diff,
|
|
2467
|
+
scrollBarActive: true
|
|
2365
2468
|
};
|
|
2366
2469
|
}
|
|
2470
|
+
const {
|
|
2471
|
+
percent,
|
|
2472
|
+
handleOffset
|
|
2473
|
+
} = getNewDeltaPercent(contentHeight, scrollBarHeight, relativeY);
|
|
2474
|
+
const newDeltaY = percent * finalDeltaY;
|
|
2475
|
+
return {
|
|
2476
|
+
...setDeltaY(state, newDeltaY),
|
|
2477
|
+
handleOffset,
|
|
2478
|
+
scrollBarActive: true
|
|
2479
|
+
};
|
|
2480
|
+
};
|
|
2481
|
+
|
|
2482
|
+
const getNewPercent = (contentHeight, scrollBarHeight, relativeY) => {
|
|
2483
|
+
if (relativeY <= contentHeight - scrollBarHeight / 2) {
|
|
2484
|
+
// clicked in middle
|
|
2485
|
+
return relativeY / (contentHeight - scrollBarHeight);
|
|
2486
|
+
}
|
|
2487
|
+
// clicked at bottom
|
|
2488
|
+
return 1;
|
|
2489
|
+
};
|
|
2490
|
+
const handleScrollBarMove = (state, eventY) => {
|
|
2491
|
+
const {
|
|
2492
|
+
y,
|
|
2493
|
+
headerHeight,
|
|
2494
|
+
handleOffset,
|
|
2495
|
+
finalDeltaY,
|
|
2496
|
+
height,
|
|
2497
|
+
scrollBarHeight
|
|
2498
|
+
} = state;
|
|
2499
|
+
const relativeY = eventY - y - headerHeight - handleOffset;
|
|
2500
|
+
const contentHeight = height - headerHeight;
|
|
2501
|
+
const newPercent = getNewPercent(contentHeight, scrollBarHeight, relativeY);
|
|
2502
|
+
const newDeltaY = newPercent * finalDeltaY;
|
|
2503
|
+
return setDeltaY(state, newDeltaY);
|
|
2504
|
+
};
|
|
2505
|
+
|
|
2506
|
+
const handleWheel = (state, deltaMode, deltaY) => {
|
|
2507
|
+
number(deltaMode);
|
|
2508
|
+
number(deltaY);
|
|
2509
|
+
return setDeltaY(state, state.deltaY + deltaY);
|
|
2367
2510
|
};
|
|
2368
2511
|
|
|
2369
2512
|
const getSavedValue = savedState => {
|
|
@@ -2387,8 +2530,7 @@ const getSavedCollapsedPaths = savedState => {
|
|
|
2387
2530
|
const getThreads = () => {
|
|
2388
2531
|
return 1;
|
|
2389
2532
|
};
|
|
2390
|
-
const loadContent = async (
|
|
2391
|
-
const state = get(uid);
|
|
2533
|
+
const loadContent = async (state, savedState) => {
|
|
2392
2534
|
const savedValue = getSavedValue(savedState);
|
|
2393
2535
|
const savedReplaceExpanded = getSavedReplaceExpanded(savedState);
|
|
2394
2536
|
const savedCollapsedPaths = getSavedCollapsedPaths(savedState);
|
|
@@ -2422,7 +2564,7 @@ const renderItems = {
|
|
|
2422
2564
|
const displayResults = getDisplayResults(newState.items, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.collapsedPaths, newState.focusedIndex);
|
|
2423
2565
|
const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
|
|
2424
2566
|
const dom = getSearchVirtualDom(displayResults, newState.replaceExpanded, newState.matchCase, newState.matchWholeWord, newState.useRegularExpression, newState.message, newState.detailsExpanded, focusOutline);
|
|
2425
|
-
return ['Viewlet.setDom2', dom];
|
|
2567
|
+
return ['Viewlet.setDom2', newState.uid, dom];
|
|
2426
2568
|
}
|
|
2427
2569
|
};
|
|
2428
2570
|
const getSelector = focusKey => {
|
|
@@ -2451,7 +2593,11 @@ const renderFocus = {
|
|
|
2451
2593
|
}
|
|
2452
2594
|
};
|
|
2453
2595
|
const render = [renderItems, renderFocus];
|
|
2454
|
-
const doRender =
|
|
2596
|
+
const doRender = uid => {
|
|
2597
|
+
const {
|
|
2598
|
+
oldState,
|
|
2599
|
+
newState
|
|
2600
|
+
} = get(uid);
|
|
2455
2601
|
const commands = [];
|
|
2456
2602
|
for (const fn of render) {
|
|
2457
2603
|
if (!fn.isEqual(oldState, newState)) {
|
|
@@ -2461,21 +2607,51 @@ const doRender = (oldState, newState) => {
|
|
|
2461
2607
|
return commands;
|
|
2462
2608
|
};
|
|
2463
2609
|
|
|
2610
|
+
const saveState = uid => {
|
|
2611
|
+
const {
|
|
2612
|
+
newState
|
|
2613
|
+
} = get(uid);
|
|
2614
|
+
const {
|
|
2615
|
+
value,
|
|
2616
|
+
replaceExpanded
|
|
2617
|
+
} = newState;
|
|
2618
|
+
return {
|
|
2619
|
+
value,
|
|
2620
|
+
replaceExpanded
|
|
2621
|
+
};
|
|
2622
|
+
};
|
|
2623
|
+
|
|
2624
|
+
const setFocus = async focusKey => {
|
|
2625
|
+
await invoke$1('Focus.setFocus', focusKey);
|
|
2626
|
+
};
|
|
2627
|
+
|
|
2628
|
+
const getSearchFocusKey = key => {
|
|
2629
|
+
switch (key) {
|
|
2630
|
+
case 'search-value':
|
|
2631
|
+
return FocusSearchInput;
|
|
2632
|
+
case 'search-replace-value':
|
|
2633
|
+
return FocusSearchReplaceInput;
|
|
2634
|
+
case 'Match Case':
|
|
2635
|
+
return FocusSearchMatchCase;
|
|
2636
|
+
case 'Match Whole Word':
|
|
2637
|
+
return FocusSearchWholeWord;
|
|
2638
|
+
case 'Use Regular Expression':
|
|
2639
|
+
return FocusSearchRegex;
|
|
2640
|
+
case 'Replace All':
|
|
2641
|
+
return FocusSearchReplaceAll;
|
|
2642
|
+
case 'Preserve Case':
|
|
2643
|
+
return FocusSearchPreserveCase;
|
|
2644
|
+
default:
|
|
2645
|
+
return Empty$1;
|
|
2646
|
+
}
|
|
2647
|
+
};
|
|
2648
|
+
|
|
2464
2649
|
const focusSearchValue = state => {
|
|
2465
2650
|
return {
|
|
2466
2651
|
...state,
|
|
2467
2652
|
focus: FocusSearchInput
|
|
2468
2653
|
};
|
|
2469
2654
|
};
|
|
2470
|
-
const focusSearchValueNext = state => {
|
|
2471
|
-
const {
|
|
2472
|
-
replaceExpanded
|
|
2473
|
-
} = state;
|
|
2474
|
-
if (replaceExpanded) {
|
|
2475
|
-
return focusReplaceValue(state);
|
|
2476
|
-
}
|
|
2477
|
-
return focusMatchCase(state);
|
|
2478
|
-
};
|
|
2479
2655
|
const focusMatchCasePrevious = state => {
|
|
2480
2656
|
const {
|
|
2481
2657
|
replaceExpanded
|
|
@@ -2527,6 +2703,17 @@ const focusReplaceAll = state => {
|
|
|
2527
2703
|
focus: FocusSearchReplaceAll
|
|
2528
2704
|
};
|
|
2529
2705
|
};
|
|
2706
|
+
const handleFocusIn = (state, key) => {
|
|
2707
|
+
const focusKey = getSearchFocusKey(key);
|
|
2708
|
+
if (state.focus === focusKey) {
|
|
2709
|
+
return state;
|
|
2710
|
+
}
|
|
2711
|
+
setFocus(focusKey);
|
|
2712
|
+
return {
|
|
2713
|
+
...state,
|
|
2714
|
+
focus: focusKey
|
|
2715
|
+
};
|
|
2716
|
+
};
|
|
2530
2717
|
|
|
2531
2718
|
const submit = state => {
|
|
2532
2719
|
return handleUpdate(state, {
|
|
@@ -2535,6 +2722,16 @@ const submit = state => {
|
|
|
2535
2722
|
});
|
|
2536
2723
|
};
|
|
2537
2724
|
|
|
2725
|
+
const toggleReplace = state => {
|
|
2726
|
+
const {
|
|
2727
|
+
replaceExpanded
|
|
2728
|
+
} = state;
|
|
2729
|
+
return {
|
|
2730
|
+
...state,
|
|
2731
|
+
replaceExpanded: !replaceExpanded
|
|
2732
|
+
};
|
|
2733
|
+
};
|
|
2734
|
+
|
|
2538
2735
|
const Keyboard = -1;
|
|
2539
2736
|
|
|
2540
2737
|
const show = async (x, y, id, ...args) => {
|
|
@@ -2568,47 +2765,61 @@ const handleContextMenu = (state, button, x, y) => {
|
|
|
2568
2765
|
}
|
|
2569
2766
|
};
|
|
2570
2767
|
|
|
2768
|
+
const wrapCommand = fn => {
|
|
2769
|
+
const wrapped = async (uid, ...args) => {
|
|
2770
|
+
const {
|
|
2771
|
+
newState
|
|
2772
|
+
} = get(uid);
|
|
2773
|
+
const newerState = await fn(newState, ...args);
|
|
2774
|
+
set(uid, newState, newerState);
|
|
2775
|
+
};
|
|
2776
|
+
return wrapped;
|
|
2777
|
+
};
|
|
2778
|
+
|
|
2571
2779
|
const commandMap = {
|
|
2572
|
-
'
|
|
2573
|
-
'
|
|
2574
|
-
'
|
|
2575
|
-
'
|
|
2576
|
-
'TextSearch.
|
|
2577
|
-
'TextSearch.
|
|
2780
|
+
'TextSearch.clearSearchResults': wrapCommand(clearSearchResults$1),
|
|
2781
|
+
'TextSearch.copy': wrapCommand(copy),
|
|
2782
|
+
'TextSearch.handleInput': wrapCommand(handleInput),
|
|
2783
|
+
'TextSearch.dismissItem': wrapCommand(dismissItem),
|
|
2784
|
+
'TextSearch.focusFirst': wrapCommand(focusFirst),
|
|
2785
|
+
'TextSearch.focusIndex': wrapCommand(focusIndex),
|
|
2786
|
+
'TextSearch.focusLast': wrapCommand(focusLast),
|
|
2787
|
+
'TextSearch.focusMatchCase': wrapCommand(focusMatchCase$1),
|
|
2788
|
+
'TextSearch.focusMatchCasePrevious': wrapCommand(focusMatchCasePrevious),
|
|
2789
|
+
'TextSearch.focusMatchWholeWord': wrapCommand(focusMatchWholeWord),
|
|
2790
|
+
'TextSearch.focusNext': wrapCommand(focusNext),
|
|
2791
|
+
'TextSearch.focusNextPage': wrapCommand(focusNextPage),
|
|
2792
|
+
'TextSearch.focusPreserveCase': wrapCommand(focusPreserveCase),
|
|
2793
|
+
'TextSearch.focusPrevious': wrapCommand(focusPrevious),
|
|
2794
|
+
'TextSearch.focusPreviousPage': wrapCommand(focusPreviousPage),
|
|
2795
|
+
'TextSearch.focusRegex': wrapCommand(focusRegex),
|
|
2796
|
+
'TextSearch.focusRegexNext': wrapCommand(focusRegexNext),
|
|
2797
|
+
'TextSearch.focusReplaceAll': wrapCommand(focusReplaceAll),
|
|
2798
|
+
'TextSearch.focusReplaceValue': wrapCommand(focusReplaceValue$1),
|
|
2799
|
+
'TextSearch.focusReplaceValueNext': wrapCommand(focusReplaceValueNext),
|
|
2800
|
+
'TextSearch.focusSearchValue': wrapCommand(focusSearchValue$1),
|
|
2801
|
+
'TextSearch.focusSearchValueNext': wrapCommand(focusSearchValueNext),
|
|
2802
|
+
'TextSearch.getActions': wrapCommand(getActions),
|
|
2803
|
+
'TextSearch.getActionsVirtualDom': wrapCommand(getActionsVirtualDom),
|
|
2804
|
+
'TextSearch.getSearchDisplayResults': wrapCommand(getDisplayResults),
|
|
2805
|
+
'TextSearch.getVirtualDom': wrapCommand(getSearchVirtualDom),
|
|
2806
|
+
'TextSearch.handleClickAt': wrapCommand(handleClickAt),
|
|
2807
|
+
'TextSearch.handleContextMenu': wrapCommand(handleContextMenu),
|
|
2808
|
+
'TextSearch.handleFocusIn': wrapCommand(handleFocusIn),
|
|
2809
|
+
'TextSearch.handleIconThemeChange': wrapCommand(handleIconThemeChange),
|
|
2810
|
+
'TextSearch.handleScrollBarCaptureLost': wrapCommand(handleScrollBarCaptureLost),
|
|
2811
|
+
'TextSearch.handleScrollBarClick': wrapCommand(handleScrollBarClick),
|
|
2812
|
+
'TextSearch.handleScrollBarMove': wrapCommand(handleScrollBarMove),
|
|
2813
|
+
'TextSearch.handleWheel': wrapCommand(handleWheel),
|
|
2814
|
+
'TextSearch.loadContent': wrapCommand(loadContent),
|
|
2815
|
+
'TextSearch.refresh': wrapCommand(refresh),
|
|
2816
|
+
'TextSearch.submit': wrapCommand(submit),
|
|
2817
|
+
'TextSearch.toggleReplace': wrapCommand(toggleReplace),
|
|
2818
|
+
// not wrapped
|
|
2578
2819
|
'TextSearch.create': create,
|
|
2579
|
-
'TextSearch.
|
|
2580
|
-
'TextSearch.
|
|
2581
|
-
|
|
2582
|
-
'TextSearch.focusLast': focusLast,
|
|
2583
|
-
'TextSearch.focusMatchCase': focusMatchCase,
|
|
2584
|
-
'TextSearch.focusMatchCasePrevious': focusMatchCasePrevious,
|
|
2585
|
-
'TextSearch.focusMatchWholeWord': focusMatchWholeWord,
|
|
2586
|
-
'TextSearch.focusNext': focusNext,
|
|
2587
|
-
'TextSearch.focusNextPage': focusNextPage,
|
|
2588
|
-
'TextSearch.focusPreserveCase': focusPreserveCase,
|
|
2589
|
-
'TextSearch.focusPrevious': focusPrevious,
|
|
2590
|
-
'TextSearch.focusPreviousPage': focusPreviousPage,
|
|
2591
|
-
'TextSearch.focusRegex': focusRegex,
|
|
2592
|
-
'TextSearch.focusRegexNext': focusRegexNext,
|
|
2593
|
-
'TextSearch.focusReplaceAll': focusReplaceAll,
|
|
2594
|
-
'TextSearch.focusReplaceValue': focusReplaceValue,
|
|
2595
|
-
'TextSearch.focusReplaceValueNext': focusReplaceValueNext,
|
|
2596
|
-
'TextSearch.focusSearchValue': focusSearchValue,
|
|
2597
|
-
'TextSearch.focusSearchValueNext': focusSearchValueNext,
|
|
2598
|
-
'TextSearch.getActions': getActions,
|
|
2599
|
-
'TextSearch.getActionsVirtualDom': getActionsVirtualDom,
|
|
2600
|
-
'TextSearch.getSearchDisplayResults': getDisplayResults,
|
|
2601
|
-
'TextSearch.getVirtualDom': getSearchVirtualDom,
|
|
2602
|
-
'TextSearch.handleClickAt': handleClickAt,
|
|
2603
|
-
'TextSearch.handleContextMenu': handleContextMenu,
|
|
2604
|
-
'TextSearch.handleIconThemeChange': handleIconThemeChange,
|
|
2605
|
-
'TextSearch.handleScrollBarCaptureLost': handleScrollBarCaptureLost,
|
|
2606
|
-
'TextSearch.handleScrollBarClick': handleScrollBarClick,
|
|
2607
|
-
'TextSearch.handleScrollBarMove': handleScrollBarMove,
|
|
2608
|
-
'TextSearch.handleWheel': handleWheel,
|
|
2609
|
-
'TextSearch.loadContent': loadContent,
|
|
2610
|
-
'TextSearch.refresh': refresh,
|
|
2611
|
-
'TextSearch.submit': submit,
|
|
2820
|
+
'TextSearch.render': doRender,
|
|
2821
|
+
'TextSearch.saveState': saveState,
|
|
2822
|
+
// TODO needed?
|
|
2612
2823
|
'TextSearch.textSearch': textSearch
|
|
2613
2824
|
};
|
|
2614
2825
|
|