Skip to content

Commit cdc4f68

Browse files
committed
Highlighted text:
more renaming for consistency
1 parent a409d09 commit cdc4f68

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

src/app/components/HighlightedText/index.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,29 @@ export const HighlightedText: FC<HighlightedTextProps> = ({
8989

9090
const pieces: ReactNode[] = []
9191
let processedChars = 0
92-
let processedTasks = 0
92+
let processedMatches = 0
9393

9494
while (processedChars < text.length) {
95-
// Do we still have tasks?
96-
if (processedTasks < sortedMatches.length) {
97-
// Yes, there are more tasks
98-
const task = sortedMatches[processedTasks]
99-
if (task.startPos < processedChars) {
100-
// This task with collude
101-
processedTasks++ // just skip this task
95+
// Do we still have matches to highlight?
96+
if (processedMatches < sortedMatches.length) {
97+
// Yes, there are more matches
98+
const match = sortedMatches[processedMatches]
99+
if (match.startPos < processedChars) {
100+
// This match would collude with something already highlighted
101+
processedMatches++ // just skip this match
102102
} else {
103-
// We use this task
104-
pieces.push(text.substring(processedChars, task.startPos))
105-
const focus = text.substring(task.startPos, task.endPos)
103+
// We want to highlight this match
104+
pieces.push(text.substring(processedChars, match.startPos))
105+
const focus = text.substring(match.startPos, match.endPos)
106106
pieces.push(
107-
<Box key={processedTasks} component="mark" sx={sx}>
107+
<Box key={processedMatches} component="mark" sx={sx}>
108108
{focus}
109109
</Box>,
110110
)
111-
processedChars = task.endPos
111+
processedChars = match.endPos
112112
}
113113
} else {
114-
// No more tasks, just grab the remaining string
114+
// No more matches, just grab the remaining string
115115
pieces.push(text.substring(processedChars))
116116
processedChars = text.length
117117
}

0 commit comments

Comments
 (0)