@@ -38,34 +38,12 @@ class SimpleCodeSnippet extends React.Component {
3838 constructor ( props ) {
3939 super ( props ) ;
4040
41- this . processProps ( props ) ;
4241 this . state = {
4342 clickedReadMore : false ,
4443 hasHighlightedText : false ,
4544 } ;
4645 }
4746
48- // handles changes during preview
49- componentDidUpdate ( prevProps ) {
50- // Only process props if they actually changed
51- if (
52- prevProps . tokens !== this . props . tokens ||
53- prevProps . linesOfCode !== this . props . linesOfCode ||
54- prevProps . highlight !== this . props . highlight
55- ) {
56- this . processProps ( this . props ) ;
57- // If you need to update state based on props changes, you can do it here
58- // but be careful to avoid infinite loops
59- }
60- }
61-
62- processProps ( { tokens, linesOfCode, highlight } ) {
63- this . linesOfTokens = ! linesOfCode ? splitTokensIntoLines ( tokens ) : linesOfCode ;
64-
65- // highlight is either a single line index/substring or a collection of line indexes and substrings
66- this . highlight = convertToList ( highlight ) ;
67- }
68-
6947 componentDidMount ( ) {
7048 addHighlightedTextListener ( this ) ;
7149 }
@@ -99,14 +77,16 @@ class SimpleCodeSnippet extends React.Component {
9977 render ( ) {
10078 this . hiddenLinesContainerRef = React . createRef ( ) ;
10179 const { clickedReadMore } = this . state ;
102- const { wrap, isPresentation, slideIdx, references } = this . props ;
80+ const { wrap, isPresentation, slideIdx, references, tokens , linesOfCode , highlight } = this . props ;
10381
10482 // slideIdx === 0 means no highlights, 1 - first highlight, etc
10583 const highlightIsVisible = ! isPresentation || slideIdx > 0 ;
10684
107- const linesOfTokens = this . linesOfTokens ;
85+ const linesOfTokens = ! linesOfCode ? splitTokensIntoLines ( tokens ) : linesOfCode ;
86+ const highlightList = convertToList ( highlight ) ;
87+
10888 const visibleLines =
109- this . limitLines ( this . props ) && ! clickedReadMore && ! isPresentation
89+ this . limitLines ( linesOfTokens , this . props ) && ! clickedReadMore && ! isPresentation
11090 ? linesOfTokens . slice ( 0 , this . readMoreVisibleLines ( this . props ) )
11191 : linesOfTokens ;
11292
@@ -115,7 +95,7 @@ class SimpleCodeSnippet extends React.Component {
11595 const linesToRender = this . processLinesToRender ( visibleLines ) ;
11696
11797 const mergedReferences = mergeWithGlobalDocReferences ( references ) ;
118- const isHighlightedByIdx = highlightIsVisible ? linesToRender . map ( ( _ , lineIdx ) => this . isHighlighted ( lineIdx ) ) : [ ] ;
98+ const isHighlightedByIdx = highlightIsVisible ? linesToRender . map ( ( _ , lineIdx ) => this . isHighlighted ( highlightList , lineIdx ) ) : [ ] ;
11999
120100 return (
121101 < pre >
@@ -157,9 +137,11 @@ class SimpleCodeSnippet extends React.Component {
157137
158138 renderReadMore ( ) {
159139 const { clickedReadMore } = this . state ;
160- const { isPresentation } = this . props ;
140+ const { isPresentation, tokens, linesOfCode } = this . props ;
141+
142+ const linesOfTokens = ! linesOfCode ? splitTokensIntoLines ( tokens ) : linesOfCode ;
161143
162- if ( isPresentation || ! this . limitLines ( this . props ) ) {
144+ if ( isPresentation || ! this . limitLines ( linesOfTokens , this . props ) ) {
163145 return null ;
164146 }
165147
@@ -208,20 +190,20 @@ class SimpleCodeSnippet extends React.Component {
208190 ) ;
209191 } ;
210192
211- limitLines ( props ) {
212- return this . linesOfTokens . length >= this . readMoreVisibleLines ( props ) && props . readMore ;
193+ limitLines ( linesOfTokens , props ) {
194+ return linesOfTokens . length >= this . readMoreVisibleLines ( props ) && props . readMore ;
213195 }
214196
215197 readMoreVisibleLines ( props ) {
216198 return props . readMoreVisibleLines || 8 ;
217199 }
218200
219- isHighlighted ( lineIdx ) {
201+ isHighlighted ( highlightList , lineIdx ) {
220202 const { meta, isPresentation, slideIdx, revealLineStop } = this . props ;
221203
222- const highlightSliceIdx = calcHighlightSliceIdx ( this . highlight ) ;
204+ const highlightSliceIdx = calcHighlightSliceIdx ( highlightList ) ;
223205
224- const highlight = ! isPresentation ? this . highlight : this . highlight . slice ( 0 , highlightSliceIdx ) ;
206+ const highlight = ! isPresentation ? highlightList : highlightList . slice ( 0 , highlightSliceIdx ) ;
225207
226208 if ( ! highlight ) {
227209 return false ;
0 commit comments