@@ -38,7 +38,7 @@ export class CodePanelComponent implements OnChanges{
3838 @Input ( ) showLineNumbers : boolean = true ;
3939 @Input ( ) loadFailed : boolean = false ;
4040 @Input ( ) codeLineSearchText : string | undefined ;
41- @Input ( ) codeLineNavigationDirection : number | undefined ;
41+ @Input ( ) codeLineSearchInfo : CodeLineSearchInfo | undefined = undefined ;
4242
4343 @Output ( ) hasActiveConversationEmitter : EventEmitter < boolean > = new EventEmitter < boolean > ( ) ;
4444 @Output ( ) codeLineSearchInfoEmitter : EventEmitter < CodeLineSearchInfo > = new EventEmitter < CodeLineSearchInfo > ( ) ;
@@ -56,8 +56,6 @@ export class CodePanelComponent implements OnChanges{
5656
5757 searchMatchedRowInfo : Map < string , RegExpMatchArray [ ] > = new Map < string , RegExpMatchArray [ ] > ( ) ;
5858 codeLineSearchMatchInfo : DoublyLinkedList < CodeLineSearchMatch > | undefined = undefined ;
59- currentCodeLineSearchMatch : DoublyLinkedListNode < CodeLineSearchMatch > | undefined = undefined ;
60- codeLineSearchInfo : CodeLineSearchInfo | undefined = undefined ;
6159
6260 destroy$ = new Subject < void > ( ) ;
6361
@@ -103,11 +101,8 @@ export class CodePanelComponent implements OnChanges{
103101 await this . searchCodePanelRowData ( this . codeLineSearchText ! ) ;
104102 }
105103
106- if ( changes [ 'codeLineNavigationDirection' ] ) {
107- this . navigateToCodeLineWithSearchMatch (
108- changes [ 'codeLineNavigationDirection' ] . previousValue ,
109- changes [ 'codeLineNavigationDirection' ] . currentValue
110- ) ;
104+ if ( changes [ 'codeLineSearchInfo' ] && changes [ 'codeLineSearchInfo' ] . currentValue != changes [ 'codeLineSearchInfo' ] . previousValue ) {
105+ this . navigateToCodeLineWithSearchMatch ( ) ;
111106 }
112107 }
113108
@@ -702,7 +697,6 @@ export class CodePanelComponent implements OnChanges{
702697 if ( ! searchText || searchText . length === 0 ) {
703698 this . clearSearchMatchHighlights ( ) ;
704699 this . codeLineSearchMatchInfo = undefined ;
705- this . currentCodeLineSearchMatch = undefined ;
706700 this . codeLineSearchInfo = undefined ;
707701 this . codeLineSearchInfoEmitter . emit ( this . codeLineSearchInfo ) ;
708702 return ;
@@ -726,34 +720,24 @@ export class CodePanelComponent implements OnChanges{
726720 }
727721 }
728722 } ) ;
729-
730- let currentMatch = 0 ;
731- let totalMatchCount = 0 ;
732723
733724 if ( hasMatch ) {
734- this . currentCodeLineSearchMatch = this . codeLineSearchMatchInfo . head ;
725+ this . codeLineSearchInfo = new CodeLineSearchInfo ( this . codeLineSearchMatchInfo . head , this . codeLineSearchMatchInfo . length ) ;
735726
736- if ( this . currentCodeLineSearchMatch ?. value . rowIndex ! < this . codePanelRowSource ?. adapter ?. firstVisible . $index ! ||
737- this . currentCodeLineSearchMatch ?. value . rowIndex ! > this . codePanelRowSource ?. adapter ?. lastVisible . $index ! ) {
727+ if ( this . codeLineSearchInfo . currentMatch ?. value . rowIndex ! < this . codePanelRowSource ?. adapter ?. firstVisible . $index ! ||
728+ this . codeLineSearchInfo . currentMatch ?. value . rowIndex ! > this . codePanelRowSource ?. adapter ?. lastVisible . $index ! ) {
738729 // Scroll first match into view
739- await this . scrollToNode ( this . currentCodeLineSearchMatch ! . value . nodeIdHashed , undefined , false , false ) ;
730+ await this . scrollToNode ( this . codeLineSearchInfo . currentMatch ! . value . nodeIdHashed , undefined , false , false ) ;
740731 await this . codePanelRowSource ?. adapter ?. relax ( ) ;
741732 }
742733
743- currentMatch = this . currentCodeLineSearchMatch ! . index + 1 ;
744- totalMatchCount = this . codeLineSearchMatchInfo . length ;
745734 this . highlightSearchMatches ( ) ;
746735 this . highlightActiveSearchMatch ( ) ;
747736 } else {
748737 this . clearSearchMatchHighlights ( ) ;
749738 this . codeLineSearchMatchInfo = undefined ;
750- this . currentCodeLineSearchMatch = undefined ;
739+ this . codeLineSearchInfo = undefined ;
751740 }
752-
753- this . codeLineSearchInfo = {
754- currentMatch : currentMatch ,
755- totalMatchCount : totalMatchCount
756- } ;
757741 this . codeLineSearchInfoEmitter . emit ( this . codeLineSearchInfo ) ;
758742 }
759743
@@ -833,9 +817,9 @@ export class CodePanelComponent implements OnChanges{
833817 }
834818
835819 private highlightActiveSearchMatch ( scrollIntoView : boolean = true ) {
836- if ( this . currentCodeLineSearchMatch ) {
837- const nodeIdHashed = this . currentCodeLineSearchMatch . value . nodeIdHashed ;
838- const matchId = this . currentCodeLineSearchMatch . value . matchId ;
820+ if ( this . codeLineSearchInfo ?. currentMatch ) {
821+ const nodeIdHashed = this . codeLineSearchInfo ?. currentMatch . value . nodeIdHashed ;
822+ const matchId = this . codeLineSearchInfo ?. currentMatch . value . matchId ;
839823
840824 const activeMatch = this . elementRef . nativeElement . querySelector ( '.codeline-search-match-highlight.active' ) ;
841825 if ( activeMatch ) {
@@ -860,31 +844,16 @@ export class CodePanelComponent implements OnChanges{
860844 /**
861845 * Navigates to the next or previous code line that contains a search match but is outside the viewport
862846 */
863- private navigateToCodeLineWithSearchMatch ( previousPosition : number , newPosition : number ) {
864- if ( this . currentCodeLineSearchMatch ) {
847+ private navigateToCodeLineWithSearchMatch ( ) {
848+ if ( this . codeLineSearchInfo ?. currentMatch ) {
865849 const firstVisibleIndex = this . codePanelRowSource ?. adapter ?. firstVisible . $index ! ;
866850 const lastVisibleIndex = this . codePanelRowSource ?. adapter ?. lastVisible . $index ! ;
867- let currentMatch = this . codeLineSearchInfo ?. currentMatch ! ;
868-
869- if ( ! previousPosition || newPosition > previousPosition ) {
870- this . currentCodeLineSearchMatch = this . currentCodeLineSearchMatch ?. next ! ;
871- currentMatch ++ ;
872- } else if ( newPosition < previousPosition ) {
873- this . currentCodeLineSearchMatch = this . currentCodeLineSearchMatch ?. prev ! ;
874- currentMatch -- ;
875- }
876851
877- if ( this . currentCodeLineSearchMatch && ( this . currentCodeLineSearchMatch . value . rowIndex < firstVisibleIndex || this . currentCodeLineSearchMatch . value . rowIndex > lastVisibleIndex ) ) {
878- this . scrollToNode ( this . currentCodeLineSearchMatch . value . nodeIdHashed , undefined , false , false ) ;
852+ if ( this . codeLineSearchInfo ?. currentMatch && ( this . codeLineSearchInfo ?. currentMatch . value . rowIndex < firstVisibleIndex || this . codeLineSearchInfo ?. currentMatch . value . rowIndex > lastVisibleIndex ) ) {
853+ this . scrollToNode ( this . codeLineSearchInfo ?. currentMatch . value . nodeIdHashed , undefined , false , false ) ;
879854 this . codePanelRowSource ?. adapter ?. relax ( ) ;
880855 }
881-
882856 this . highlightActiveSearchMatch ( ) ;
883- this . codeLineSearchInfo = {
884- currentMatch : currentMatch ,
885- totalMatchCount : this . codeLineSearchInfo ?. totalMatchCount
886- } ;
887- this . codeLineSearchInfoEmitter . emit ( this . codeLineSearchInfo ) ;
888857 }
889858 }
890859
@@ -963,7 +932,7 @@ export class CodePanelComponent implements OnChanges{
963932 const viewport = this . elementRef . nativeElement . ownerDocument . getElementById ( 'viewport' ) ;
964933 if ( viewport ) {
965934 viewport . addEventListener ( 'scroll' , ( event ) => {
966- if ( this . currentCodeLineSearchMatch ) {
935+ if ( this . codeLineSearchInfo ?. currentMatch ) {
967936 this . highlightSearchMatches ( ) ;
968937 this . highlightActiveSearchMatch ( false ) ;
969938 }
0 commit comments