Skip to content

Commit 6a3f665

Browse files
committed
HighlightedText: improve variable names
1 parent 6429ed5 commit 6a3f665

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

src/app/components/HighlightedText/index.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import { MatchInfo, findTextMatches, NO_MATCH, NormalizerOptions, PositiveMatchInfo } from './text-matching'
2+
import { findTextMatches, NormalizerOptions, PositiveMatchInfo } from './text-matching'
33
import { FC, ReactNode } from 'react'
44
import { SxProps } from '@mui/material/styles'
55
import Box from '@mui/material/Box'
@@ -56,7 +56,7 @@ interface HighlightedTextProps {
5656
* If not given, we will just search for the pattern.
5757
* If given, this will be executed, and the pattern will not even be considered.
5858
*/
59-
parts?: MatchInfo[]
59+
partsToHighlight?: PositiveMatchInfo[]
6060

6161
/**
6262
* Options for highlighting (case sensitivity, styling, etc.)
@@ -72,21 +72,18 @@ interface HighlightedTextProps {
7272
export const HighlightedText: FC<HighlightedTextProps> = ({
7373
text,
7474
pattern = NoHighlights,
75-
parts,
75+
partsToHighlight,
7676
options = defaultHighlight,
7777
}) => {
7878
const { sx = defaultHighlightStyle, findOptions = {} } = options
7979

8080
// Have we been told what to highlight exactly? If not, look for the pattern
81-
const tasks = parts ?? findTextMatches(text, pattern, findOptions)
82-
83-
// Get the real matches
84-
const realTasks = tasks.filter((task): task is PositiveMatchInfo => task !== NO_MATCH)
81+
const matches = partsToHighlight ?? findTextMatches(text, pattern, findOptions)
8582

8683
if (text === undefined) return undefined // Nothing to display
87-
if (!realTasks.length) return text // We don't have to highlight anything
84+
if (!matches.length) return text // We don't have to highlight anything
8885

89-
const sortedTasks = realTasks.sort((a, b) =>
86+
const sortedMatches = matches.sort((a, b) =>
9087
a.startPos > b.startPos ? 1 : a.startPos < b.startPos ? -1 : 0,
9188
)
9289

@@ -96,9 +93,9 @@ export const HighlightedText: FC<HighlightedTextProps> = ({
9693

9794
while (processedChars < text.length) {
9895
// Do we still have tasks?
99-
if (processedTasks < sortedTasks.length) {
96+
if (processedTasks < sortedMatches.length) {
10097
// Yes, there are more tasks
101-
const task = sortedTasks[processedTasks]
98+
const task = sortedMatches[processedTasks]
10299
if (task.startPos < processedChars) {
103100
// This task with collude
104101
processedTasks++ // just skip this task

0 commit comments

Comments
 (0)