parent
286b02a845
commit
658cff4810
@ -1,34 +1,48 @@ |
|||||||
import { ViewPlugin } from '@remixproject/engine-web' |
import React, { useContext } from 'react' |
||||||
import React, { useContext, useEffect, useState } from 'react' |
|
||||||
import { SearchContext } from '../../context/context' |
import { SearchContext } from '../../context/context' |
||||||
import { SearchResult, SearchResultLine, SearchResultLineLine } from '../../reducers/Reducer' |
import { SearchResult, SearchResultLine, SearchResultLineLine } from '../../types' |
||||||
import { ResultFileName } from './ResultFileName' |
|
||||||
|
|
||||||
interface ResultSummaryProps { |
interface ResultSummaryProps { |
||||||
searchResult: SearchResult |
searchResult: SearchResult |
||||||
line: SearchResultLine |
line: SearchResultLine |
||||||
|
setLoading: (value: boolean) => void |
||||||
} |
} |
||||||
|
|
||||||
export const ResultSummary = (props: ResultSummaryProps) => { |
export const ResultSummary = (props: ResultSummaryProps) => { |
||||||
const { hightLightInPath } = useContext(SearchContext) |
const { hightLightInPath, replaceText, state } = useContext(SearchContext) |
||||||
|
|
||||||
const selectLine = async (line: SearchResultLineLine) => { |
const selectLine = async (line: SearchResultLineLine) => { |
||||||
console.log(line, props.searchResult) |
|
||||||
await hightLightInPath(props.searchResult, line) |
await hightLightInPath(props.searchResult, line) |
||||||
} |
} |
||||||
|
|
||||||
|
const replace = async (line: SearchResultLineLine) => { |
||||||
|
props.setLoading(true) |
||||||
|
await replaceText(props.searchResult, line) |
||||||
|
} |
||||||
|
|
||||||
return ( |
return ( |
||||||
<li className="p-1 wrap_summary"> |
<> |
||||||
{props.line.lines.map((lineItem, index) => ( |
{props.line.lines.map((lineItem, index) => ( |
||||||
|
<div className='search_line_container' key={index}> |
||||||
<div |
<div |
||||||
onClick={async () => { |
onClick={async () => { |
||||||
selectLine(lineItem) |
selectLine(lineItem) |
||||||
}} |
}} |
||||||
key={index} |
key={props.searchResult.filename} |
||||||
|
className='search_line pb-1' |
||||||
> |
> |
||||||
{lineItem.left.substring(lineItem.left.length - 20)} |
<div className='summary_left'>{lineItem.left.substring(lineItem.left.length - 20)}</div> |
||||||
<mark>{lineItem.center}</mark> |
<mark className={`summary_center ${state.replace? 'replace_strike':''}`}>{lineItem.center}</mark> |
||||||
{lineItem.right.substring(0, 100)} |
{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> |
</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