|
@@ -3,7 +3,6 @@
|
|
* @homepage: https://oldj.net
|
|
* @homepage: https://oldj.net
|
|
*/
|
|
*/
|
|
|
|
|
|
-import { useModel } from '@@/plugin-model/useModel'
|
|
|
|
import {
|
|
import {
|
|
Box,
|
|
Box,
|
|
Button,
|
|
Button,
|
|
@@ -25,11 +24,7 @@ import { PopupMenu } from '@renderer/core/PopupMenu'
|
|
import useOnBroadcast from '@renderer/core/useOnBroadcast'
|
|
import useOnBroadcast from '@renderer/core/useOnBroadcast'
|
|
import { HostsType } from '@root/common/data'
|
|
import { HostsType } from '@root/common/data'
|
|
import events from '@root/common/events'
|
|
import events from '@root/common/events'
|
|
-import {
|
|
|
|
- IFindItem,
|
|
|
|
- IFindPosition,
|
|
|
|
- IFindShowSourceParam,
|
|
|
|
-} from '@root/common/types'
|
|
|
|
|
|
+import { IFindItem, IFindPosition, IFindShowSourceParam } from '@root/common/types'
|
|
import { useDebounce, useDebounceFn } from 'ahooks'
|
|
import { useDebounce, useDebounceFn } from 'ahooks'
|
|
import clsx from 'clsx'
|
|
import clsx from 'clsx'
|
|
import lodash from 'lodash'
|
|
import lodash from 'lodash'
|
|
@@ -42,10 +37,10 @@ import {
|
|
} from 'react-icons/io5'
|
|
} from 'react-icons/io5'
|
|
import { FixedSizeList as List, ListChildComponentProps } from 'react-window'
|
|
import { FixedSizeList as List, ListChildComponentProps } from 'react-window'
|
|
import scrollIntoView from 'smooth-scroll-into-view-if-needed'
|
|
import scrollIntoView from 'smooth-scroll-into-view-if-needed'
|
|
|
|
+import useConfigs from '../models/useConfigs'
|
|
|
|
+import useI18n from '../models/useI18n'
|
|
import styles from './find.less'
|
|
import styles from './find.less'
|
|
|
|
|
|
-interface Props {}
|
|
|
|
-
|
|
|
|
interface IFindPositionShow extends IFindPosition {
|
|
interface IFindPositionShow extends IFindPosition {
|
|
item_id: string
|
|
item_id: string
|
|
item_title: string
|
|
item_title: string
|
|
@@ -55,9 +50,9 @@ interface IFindPositionShow extends IFindPosition {
|
|
is_readonly?: boolean
|
|
is_readonly?: boolean
|
|
}
|
|
}
|
|
|
|
|
|
-const find = (props: Props) => {
|
|
|
|
- const { lang, i18n, setLocale } = useModel('useI18n')
|
|
|
|
- const { configs, loadConfigs } = useModel('useConfigs')
|
|
|
|
|
|
+const find = () => {
|
|
|
|
+ const { lang, i18n, setLocale } = useI18n()
|
|
|
|
+ const { configs, loadConfigs } = useConfigs()
|
|
const { colorMode, setColorMode } = useColorMode()
|
|
const { colorMode, setColorMode } = useColorMode()
|
|
const [keyword, setKeyword] = useState('')
|
|
const [keyword, setKeyword] = useState('')
|
|
const [replace_to, setReplaceTo] = useState('')
|
|
const [replace_to, setReplaceTo] = useState('')
|
|
@@ -231,9 +226,7 @@ const find = (props: Props) => {
|
|
for (let item of find_result) {
|
|
for (let item of find_result) {
|
|
let { item_id, item_type, splitters } = item
|
|
let { item_id, item_type, splitters } = item
|
|
if (item_type !== 'local' || splitters.length === 0) continue
|
|
if (item_type !== 'local' || splitters.length === 0) continue
|
|
- const content = splitters
|
|
|
|
- .map((sp) => `${sp.before}${replace_to}${sp.after}`)
|
|
|
|
- .join('')
|
|
|
|
|
|
+ const content = splitters.map((sp) => `${sp.before}${replace_to}${sp.after}`).join('')
|
|
await actions.setHostsContent(item_id, content)
|
|
await actions.setHostsContent(item_id, content)
|
|
agent.broadcast(events.hosts_refreshed_by_id, item_id)
|
|
agent.broadcast(events.hosts_refreshed_by_id, item_id)
|
|
}
|
|
}
|
|
@@ -256,11 +249,7 @@ const find = (props: Props) => {
|
|
const is_selected = current_result_idx === row_data.index
|
|
const is_selected = current_result_idx === row_data.index
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- if (
|
|
|
|
- el.current &&
|
|
|
|
- is_selected &&
|
|
|
|
- current_result_idx !== last_scroll_result_idx
|
|
|
|
- ) {
|
|
|
|
|
|
+ if (el.current && is_selected && current_result_idx !== last_scroll_result_idx) {
|
|
setlastScrollResultIdx(current_result_idx)
|
|
setlastScrollResultIdx(current_result_idx)
|
|
scrollIntoView(el.current, {
|
|
scrollIntoView(el.current, {
|
|
behavior: 'smooth',
|
|
behavior: 'smooth',
|
|
@@ -288,9 +277,7 @@ const find = (props: Props) => {
|
|
title={lang.to_show_source}
|
|
title={lang.to_show_source}
|
|
>
|
|
>
|
|
<div className={styles.result_content}>
|
|
<div className={styles.result_content}>
|
|
- {data.is_readonly ? (
|
|
|
|
- <span className={styles.read_only}>{lang.read_only}</span>
|
|
|
|
- ) : null}
|
|
|
|
|
|
+ {data.is_readonly ? <span className={styles.read_only}>{lang.read_only}</span> : null}
|
|
<span>{data.before}</span>
|
|
<span>{data.before}</span>
|
|
<span className={styles.highlight}>{data.match}</span>
|
|
<span className={styles.highlight}>{data.match}</span>
|
|
<span>{data.after}</span>
|
|
<span>{data.after}</span>
|
|
@@ -400,16 +387,10 @@ const find = (props: Props) => {
|
|
spacing={4}
|
|
spacing={4}
|
|
// justifyContent="flex-start"
|
|
// justifyContent="flex-start"
|
|
>
|
|
>
|
|
- <Checkbox
|
|
|
|
- checked={is_regexp}
|
|
|
|
- onChange={(e) => setIsRegExp(e.target.checked)}
|
|
|
|
- >
|
|
|
|
|
|
+ <Checkbox checked={is_regexp} onChange={(e) => setIsRegExp(e.target.checked)}>
|
|
{lang.regexp}
|
|
{lang.regexp}
|
|
</Checkbox>
|
|
</Checkbox>
|
|
- <Checkbox
|
|
|
|
- checked={is_ignore_case}
|
|
|
|
- onChange={(e) => setIsIgnoreCase(e.target.checked)}
|
|
|
|
- >
|
|
|
|
|
|
+ <Checkbox checked={is_ignore_case} onChange={(e) => setIsIgnoreCase(e.target.checked)}>
|
|
{lang.ignore_case}
|
|
{lang.ignore_case}
|
|
</Checkbox>
|
|
</Checkbox>
|
|
</HStack>
|
|
</HStack>
|
|
@@ -430,9 +411,7 @@ const find = (props: Props) => {
|
|
>
|
|
>
|
|
<List
|
|
<List
|
|
width={'100%'}
|
|
width={'100%'}
|
|
- height={
|
|
|
|
- ref_result_box.current ? ref_result_box.current.clientHeight : 0
|
|
|
|
- }
|
|
|
|
|
|
+ height={ref_result_box.current ? ref_result_box.current.clientHeight : 0}
|
|
itemCount={find_positions.length}
|
|
itemCount={find_positions.length}
|
|
itemSize={28}
|
|
itemSize={28}
|
|
>
|
|
>
|
|
@@ -451,10 +430,9 @@ const find = (props: Props) => {
|
|
<Spinner />
|
|
<Spinner />
|
|
) : (
|
|
) : (
|
|
<span>
|
|
<span>
|
|
- {i18n.trans(
|
|
|
|
- find_positions.length > 1 ? 'items_found' : 'item_found',
|
|
|
|
- [find_positions.length.toLocaleString()],
|
|
|
|
- )}
|
|
|
|
|
|
+ {i18n.trans(find_positions.length > 1 ? 'items_found' : 'item_found', [
|
|
|
|
+ find_positions.length.toLocaleString(),
|
|
|
|
+ ])}
|
|
</span>
|
|
</span>
|
|
)}
|
|
)}
|
|
<Spacer />
|
|
<Spacer />
|
|
@@ -470,9 +448,7 @@ const find = (props: Props) => {
|
|
size="sm"
|
|
size="sm"
|
|
variant="solid"
|
|
variant="solid"
|
|
colorScheme="blue"
|
|
colorScheme="blue"
|
|
- isDisabled={
|
|
|
|
- is_searching || find_positions.length === 0 || !can_replace
|
|
|
|
- }
|
|
|
|
|
|
+ isDisabled={is_searching || find_positions.length === 0 || !can_replace}
|
|
onClick={replaceOne}
|
|
onClick={replaceOne}
|
|
>
|
|
>
|
|
{lang.replace}
|
|
{lang.replace}
|
|
@@ -499,8 +475,7 @@ const find = (props: Props) => {
|
|
icon={<IoArrowForwardOutline />}
|
|
icon={<IoArrowForwardOutline />}
|
|
onClick={() => {
|
|
onClick={() => {
|
|
let idx = current_result_idx + 1
|
|
let idx = current_result_idx + 1
|
|
- if (idx > find_positions.length - 1)
|
|
|
|
- idx = find_positions.length - 1
|
|
|
|
|
|
+ if (idx > find_positions.length - 1) idx = find_positions.length - 1
|
|
setCurrentResultIdx(idx)
|
|
setCurrentResultIdx(idx)
|
|
}}
|
|
}}
|
|
isDisabled={current_result_idx >= find_positions.length - 1}
|
|
isDisabled={current_result_idx >= find_positions.length - 1}
|