@@ -5,6 +5,11 @@ import { VSCodeButton, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
55import { addHighlighting } from "../../utils/add-highlighting"
66import CopyClipboard from "../common/CopyClipboard"
77
8+ // Define interface to store both original and highlighted versions
9+ interface IHighlightedHaiTask {
10+ original : IHaiTask
11+ highlighted : IHaiTask
12+ }
813interface DetailedViewProps {
914 task : IHaiTask | null
1015 story : IHaiStory | null
@@ -34,17 +39,34 @@ const DetailedView: React.FC<DetailedViewProps> = ({ task, story, onTaskSelect,
3439 } , [ story ] )
3540
3641 // Filter tasks based on the search query and apply highlighting
37- const filteredTasks = useMemo ( ( ) => {
38- if ( ! searchQuery . trim ( ) || ! fuse ) return story ?. tasks || [ ]
42+ const filteredTasks = useMemo < IHighlightedHaiTask [ ] > ( ( ) => {
43+ if ( ! searchQuery . trim ( ) || ! fuse ) {
44+ // If no search query, return all tasks with both original and highlighted pointing to the same object
45+ return ( story ?. tasks || [ ] ) . map ( ( task ) => ( {
46+ original : task ,
47+ highlighted : task ,
48+ } ) )
49+ }
50+
51+ // With search query, apply highlighting to copies while preserving originals
3952 const results = fuse . search ( searchQuery )
4053 return results . map ( ( { item, matches } ) => {
54+ // Store original task
55+ const originalTask = item
56+ // Create copy for highlighting
4157 const highlightedTask = { ...item }
58+
59+ // Apply highlighting to the copy
4260 matches ?. forEach ( ( match ) => {
4361 if ( match . key && match . indices && isTaskField ( match . key ) ) {
4462 highlightedTask [ match . key ] = addHighlighting ( String ( match . value ) , match . indices )
4563 }
4664 } )
47- return highlightedTask
65+
66+ return {
67+ original : originalTask ,
68+ highlighted : highlightedTask ,
69+ }
4870 } )
4971 } , [ searchQuery , fuse , story ] )
5072
@@ -126,7 +148,7 @@ const DetailedView: React.FC<DetailedViewProps> = ({ task, story, onTaskSelect,
126148 < div >
127149 { filteredTasks . map ( ( task ) => (
128150 < div
129- key = { task . id }
151+ key = { task . original . id }
130152 style = { {
131153 display : "flex" ,
132154 alignItems : "center" ,
@@ -162,8 +184,8 @@ const DetailedView: React.FC<DetailedViewProps> = ({ task, story, onTaskSelect,
162184 fontWeight : "bold" ,
163185 color : "var(--vscode-descriptionForeground)" ,
164186 } } >
165- < span dangerouslySetInnerHTML = { { __html : task . id } } />
166- { task . subTaskTicketId && (
187+ < span dangerouslySetInnerHTML = { { __html : task . highlighted . id } } />
188+ { task . highlighted . subTaskTicketId && (
167189 < span
168190 style = { {
169191 fontSize : "12px" ,
@@ -173,7 +195,7 @@ const DetailedView: React.FC<DetailedViewProps> = ({ task, story, onTaskSelect,
173195 textOverflow : "ellipsis" ,
174196 } }
175197 dangerouslySetInnerHTML = { {
176- __html : ` • ${ task . subTaskTicketId } ` ,
198+ __html : ` • ${ task . highlighted . subTaskTicketId } ` ,
177199 } }
178200 />
179201 ) } { " " }
@@ -188,7 +210,7 @@ const DetailedView: React.FC<DetailedViewProps> = ({ task, story, onTaskSelect,
188210 wordBreak : "break-word" ,
189211 overflowWrap : "anywhere" ,
190212 } }
191- dangerouslySetInnerHTML = { { __html : task . list } }
213+ dangerouslySetInnerHTML = { { __html : task . highlighted . list } }
192214 />
193215 </ div >
194216
@@ -205,24 +227,24 @@ const DetailedView: React.FC<DetailedViewProps> = ({ task, story, onTaskSelect,
205227 onClick = { ( ) => {
206228 onTaskSelect ( {
207229 context : `${ story ?. name } : ${ story ?. description } ` ,
208- ...task ,
209- id : `${ story ?. id } -${ task . id } ` ,
230+ ...task . original ,
231+ id : `${ story ?. id } -${ task . original . id } ` ,
210232 } )
211233 } } >
212234 < span className = "codicon codicon-play" style = { { fontSize : 14 , cursor : "pointer" } } />
213235 </ VSCodeButton >
214236 < CopyClipboard
215237 title = "Copy Task"
216238 onCopyContent = { ( ) => {
217- return `Task (${ task . id } ): ${ task . list } \nAcceptance: ${ task . acceptance } \n\nContext:\nStory (${ story ?. id } ): ${ story ?. name } \nStory Acceptance: ${ story ?. description } \n`
239+ return `Task (${ task . original . id } ): ${ task . original . list } \nAcceptance: ${ task . original . acceptance } \n\nContext:\nStory (${ story ?. id } ): ${ story ?. name } \nStory Acceptance: ${ story ?. description } \n`
218240 } }
219241 />
220242 < VSCodeButton
221243 appearance = "icon"
222244 title = "View Task"
223245 onClick = { ( ) => {
224- setSelectedTask ( task )
225- onTaskClick ( task )
246+ setSelectedTask ( task . original )
247+ onTaskClick ( task . original )
226248 } } >
227249 < span className = "codicon codicon-eye" style = { { fontSize : 14 , cursor : "pointer" } } />
228250 </ VSCodeButton >
0 commit comments