parent
52c60f3fff
commit
79f80e72b2
@ -1,34 +1,48 @@ |
||||
import { ViewPlugin } from '@remixproject/engine-web' |
||||
import React, { useContext, useEffect, useState } from 'react' |
||||
import React, { useContext } from 'react' |
||||
import { SearchContext } from '../../context/context' |
||||
import { SearchResult, SearchResultLine, SearchResultLineLine } from '../../reducers/Reducer' |
||||
import { ResultFileName } from './ResultFileName' |
||||
import { SearchResult, SearchResultLine, SearchResultLineLine } from '../../types' |
||||
|
||||
interface ResultSummaryProps { |
||||
searchResult: SearchResult |
||||
line: SearchResultLine |
||||
setLoading: (value: boolean) => void |
||||
} |
||||
|
||||
export const ResultSummary = (props: ResultSummaryProps) => { |
||||
const { hightLightInPath } = useContext(SearchContext) |
||||
const { hightLightInPath, replaceText, state } = useContext(SearchContext) |
||||
|
||||
const selectLine = async (line: SearchResultLineLine) => { |
||||
console.log(line, props.searchResult) |
||||
await hightLightInPath(props.searchResult, line) |
||||
} |
||||
|
||||
const replace = async (line: SearchResultLineLine) => { |
||||
props.setLoading(true) |
||||
await replaceText(props.searchResult, line) |
||||
} |
||||
|
||||
return ( |
||||
<li className="p-1 wrap_summary"> |
||||
<> |
||||
{props.line.lines.map((lineItem, index) => ( |
||||
<div className='search_line_container' key={index}> |
||||
<div |
||||
onClick={async () => { |
||||
selectLine(lineItem) |
||||
}} |
||||
key={index} |
||||
key={props.searchResult.filename} |
||||
className='search_line pb-1' |
||||
> |
||||
{lineItem.left.substring(lineItem.left.length - 20)} |
||||
<mark>{lineItem.center}</mark> |
||||
{lineItem.right.substring(0, 100)} |
||||
<div className='summary_left'>{lineItem.left.substring(lineItem.left.length - 20)}</div> |
||||
<mark className={`summary_center ${state.replace? 'replace_strike':''}`}>{lineItem.center}</mark> |
||||
{state.replace? <mark className='replacement'>{state.replace}</mark>:<></>} |
||||
<div className='summary_right'>{lineItem.right.substring(0, 100)}</div> |
||||
</div> |
||||
<div className='search_control'> |
||||
<div title="Replace" onClick={async () => { |
||||
replace(lineItem) |
||||
}} className="codicon codicon-find-replace" role="button" aria-label="Replace" aria-disabled="false"></div> |
||||
</div> |
||||
</div> |
||||
))} |
||||
</li> |
||||
</> |
||||
) |
||||
} |
||||
|
@ -0,0 +1,55 @@ |
||||
|
||||
export interface Action { |
||||
type: string |
||||
payload: any |
||||
} |
||||
|
||||
interface position { |
||||
start: { |
||||
line: number |
||||
column: number |
||||
}, |
||||
end: { |
||||
line: number |
||||
column: number |
||||
} |
||||
} |
||||
|
||||
export interface SearchResultLineLine { |
||||
left: any, |
||||
center: any, |
||||
right: any, |
||||
position: position |
||||
} |
||||
export interface SearchResultLine { |
||||
lines: SearchResultLineLine[] |
||||
} |
||||
|
||||
export interface SearchResult { |
||||
filename: string, |
||||
path: string, |
||||
lines: SearchResultLine[], |
||||
timeStamp: number |
||||
} |
||||
|
||||
export interface SearchState { |
||||
find: string, |
||||
searchResults: SearchResult[], |
||||
replace: string, |
||||
include: string, |
||||
exclude: string, |
||||
casesensitive: boolean, |
||||
matchWord: boolean, |
||||
timeStamp: number |
||||
} |
||||
|
||||
export const SearchingInitialState: SearchState = { |
||||
find: '', |
||||
replace: '', |
||||
include: '', |
||||
exclude: '', |
||||
searchResults: [], |
||||
casesensitive: false, |
||||
matchWord: false, |
||||
timeStamp: 0 |
||||
} |
Loading…
Reference in new issue