From c9dd9fb9ab3397b221d77302ea4816141420a452 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Fri, 18 Feb 2022 12:55:41 +0100 Subject: [PATCH 01/35] first steps --- apps/remix-ide/src/app.js | 9 +- apps/remix-ide/src/app/files/fileManager.ts | 10 ++- apps/remix-ide/src/app/tabs/search.tsx | 34 +++++++ apps/remix-ide/src/assets/img/Search_Icon.svg | 77 ++++++++++++++++ libs/remix-ui/search/.babelrc | 4 + libs/remix-ui/search/.eslintrc.json | 19 ++++ libs/remix-ui/search/.prettierrc | 5 ++ libs/remix-ui/search/README.md | 7 ++ libs/remix-ui/search/src/index.ts | 1 + .../search/src/lib/components/Exclude.tsx | 0 .../search/src/lib/components/Find.tsx | 17 ++++ .../search/src/lib/components/Include.tsx | 0 .../search/src/lib/components/Replace.tsx | 16 ++++ .../search/src/lib/components/Search.tsx | 25 ++++++ .../lib/components/results/ResultFileName.tsx | 0 .../src/lib/components/results/ResultItem.tsx | 0 .../lib/components/results/ResultSummary.tsx | 0 .../src/lib/components/results/Results.tsx | 81 +++++++++++++++++ .../search/src/lib/context/context.tsx | 88 +++++++++++++++++++ .../search/src/lib/reducers/Reducer.ts | 70 +++++++++++++++ libs/remix-ui/search/tsconfig.json | 19 ++++ libs/remix-ui/search/tsconfig.lib.json | 13 +++ nx.json | 3 + package-lock.json | 70 +++++++-------- tsconfig.base.json | 1 + workspace.json | 15 ++++ 26 files changed, 546 insertions(+), 38 deletions(-) create mode 100644 apps/remix-ide/src/app/tabs/search.tsx create mode 100644 apps/remix-ide/src/assets/img/Search_Icon.svg create mode 100644 libs/remix-ui/search/.babelrc create mode 100644 libs/remix-ui/search/.eslintrc.json create mode 100644 libs/remix-ui/search/.prettierrc create mode 100644 libs/remix-ui/search/README.md create mode 100644 libs/remix-ui/search/src/index.ts create mode 100644 libs/remix-ui/search/src/lib/components/Exclude.tsx create mode 100644 libs/remix-ui/search/src/lib/components/Find.tsx create mode 100644 libs/remix-ui/search/src/lib/components/Include.tsx create mode 100644 libs/remix-ui/search/src/lib/components/Replace.tsx create mode 100644 libs/remix-ui/search/src/lib/components/Search.tsx create mode 100644 libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx create mode 100644 libs/remix-ui/search/src/lib/components/results/ResultItem.tsx create mode 100644 libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx create mode 100644 libs/remix-ui/search/src/lib/components/results/Results.tsx create mode 100644 libs/remix-ui/search/src/lib/context/context.tsx create mode 100644 libs/remix-ui/search/src/lib/reducers/Reducer.ts create mode 100644 libs/remix-ui/search/tsconfig.json create mode 100644 libs/remix-ui/search/tsconfig.lib.json diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index 033c1b1bb0..732ef24c4a 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -30,6 +30,7 @@ const isElectron = require('is-electron') const remixLib = require('@remix-project/remix-lib') import { QueryParams } from '@remix-project/remix-lib' +import { SearchPlugin } from './app/tabs/search' const Storage = remixLib.Storage const RemixDProvider = require('./app/files/remixDProvider') const Config = require('./config') @@ -147,6 +148,9 @@ class AppComponent { // ----------------- Storage plugin --------------------------------- const storagePlugin = new StoragePlugin() + //----- search + const search = new SearchPlugin() + // ----------------- import content service ------------------------ const contentImport = new CompilerImports() @@ -221,7 +225,8 @@ class AppComponent { dGitProvider, storagePlugin, hardhatProvider, - this.walkthroughService + this.walkthroughService, + search ]) // LAYOUT & SYSTEM VIEWS @@ -332,7 +337,7 @@ class AppComponent { await this.appManager.activatePlugin(['settings', 'config']) await this.appManager.activatePlugin(['hiddenPanel', 'pluginManager', 'contextualListener', 'terminal', 'blockchain', 'fetchAndCompile', 'contentImport', 'gistHandler']) await this.appManager.activatePlugin(['settings']) - await this.appManager.activatePlugin(['walkthrough','storage']) + await this.appManager.activatePlugin(['walkthrough','storage', 'search']) this.appManager.on( 'filePanel', diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index d9789f4512..263d583093 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -19,7 +19,7 @@ const profile = { icon: 'assets/img/fileManager.webp', permission: true, version: packageJson.version, - methods: ['closeAllFiles', 'closeFile', 'file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'copyDir', 'rename', 'mkdir', 'readdir', 'remove', 'getCurrentFile', 'getFile', 'getFolder', 'setFile', 'switchFile', 'refresh', 'getProviderOf', 'getProviderByName', 'getPathFromUrl', 'getUrlFromPath', 'saveCurrentFile', 'setBatchFiles'], + methods: ['closeAllFiles', 'closeFile', 'file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'copyDir', 'rename', 'mkdir', 'readdir', 'remove', 'getCurrentFile', 'getFile', 'getFolder', 'setFile', 'switchFile', 'refresh', 'getProviderOf', 'getProviderByName', 'getPathFromUrl', 'getUrlFromPath', 'saveCurrentFile', 'setBatchFiles', 'findInFile'], kind: 'file-system' } const errorMsg = { @@ -396,6 +396,14 @@ class FileManager extends Plugin { } } + + async findInFile(query) { + const browserProvider = this.getProvider('browser') + await browserProvider.copyFolderToJson('/.workspaces/default_workspace', ({ path, content }) => { + console.log(path, content) + }) + } + init() { this._deps = { config: this._components.registry.get('config').api, diff --git a/apps/remix-ide/src/app/tabs/search.tsx b/apps/remix-ide/src/app/tabs/search.tsx new file mode 100644 index 0000000000..267396181a --- /dev/null +++ b/apps/remix-ide/src/app/tabs/search.tsx @@ -0,0 +1,34 @@ +import { ViewPlugin } from '@remixproject/engine-web' +import * as packageJson from '../../../../../package.json' +import React from 'react' // eslint-disable-line +import { PluginViewWrapper } from '@remix-ui/helper' +import { SearchTab } from '@remix-ui/search' +const profile = { + name: 'search', + displayName: 'Search', + methods: [''], + events: [], + icon: 'assets/img/Search_Icon.svg', + description: '', + kind: '', + location: 'sidePanel', + documentation: '', + version: packageJson.version + } + +export class SearchPlugin extends ViewPlugin { + dispatch: React.Dispatch = () => {} + constructor () { + super(profile) + } + + + render() { + return ( +
+ +
+ ); + } + +} \ No newline at end of file diff --git a/apps/remix-ide/src/assets/img/Search_Icon.svg b/apps/remix-ide/src/assets/img/Search_Icon.svg new file mode 100644 index 0000000000..00a6fcde04 --- /dev/null +++ b/apps/remix-ide/src/assets/img/Search_Icon.svg @@ -0,0 +1,77 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/libs/remix-ui/search/.babelrc b/libs/remix-ui/search/.babelrc new file mode 100644 index 0000000000..64a3748691 --- /dev/null +++ b/libs/remix-ui/search/.babelrc @@ -0,0 +1,4 @@ +{ + "presets": ["@nrwl/react/babel"], + "plugins": [] +} \ No newline at end of file diff --git a/libs/remix-ui/search/.eslintrc.json b/libs/remix-ui/search/.eslintrc.json new file mode 100644 index 0000000000..1587c6172a --- /dev/null +++ b/libs/remix-ui/search/.eslintrc.json @@ -0,0 +1,19 @@ +{ + "env": { + "browser": true, + "es6": true + }, + "ignorePatterns": ["!**/*"], + "extends": "../../../.eslintrc.json", + "globals": { + "Atomics": "readonly", + "SharedArrayBuffer": "readonly" + }, + "parserOptions": { + "ecmaVersion": 11, + "sourceType": "module" + }, + "rules": { + "standard/no-callback-literal": "off" + } +} \ No newline at end of file diff --git a/libs/remix-ui/search/.prettierrc b/libs/remix-ui/search/.prettierrc new file mode 100644 index 0000000000..591b168cb7 --- /dev/null +++ b/libs/remix-ui/search/.prettierrc @@ -0,0 +1,5 @@ +{ + "tabWidth": 2, + "singleQuote": true, + "semi": false +} \ No newline at end of file diff --git a/libs/remix-ui/search/README.md b/libs/remix-ui/search/README.md new file mode 100644 index 0000000000..cf9595a10e --- /dev/null +++ b/libs/remix-ui/search/README.md @@ -0,0 +1,7 @@ +# remix-ui-vertical-icons-panel + +React library for RemixIde vertical icons Panel + +## Running unit tests + +Run `nx test remix-ui-vertical-icons-panel` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/remix-ui/search/src/index.ts b/libs/remix-ui/search/src/index.ts new file mode 100644 index 0000000000..8617e2ddff --- /dev/null +++ b/libs/remix-ui/search/src/index.ts @@ -0,0 +1 @@ +export { SearchTab } from './lib/components/Search'; \ No newline at end of file diff --git a/libs/remix-ui/search/src/lib/components/Exclude.tsx b/libs/remix-ui/search/src/lib/components/Exclude.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/remix-ui/search/src/lib/components/Find.tsx b/libs/remix-ui/search/src/lib/components/Find.tsx new file mode 100644 index 0000000000..db8cb94463 --- /dev/null +++ b/libs/remix-ui/search/src/lib/components/Find.tsx @@ -0,0 +1,17 @@ +import React, { useContext, useReducer } from "react" +import { SearchContext } from "../context/context" +import { SearchingInitialState, SearchReducer } from "../reducers/Reducer" + + + +export const Find = props => { + + const { setFind } = useContext(SearchContext) + const change = (e) => { + setFind(e.target.value) + } + + return(<> + + ) +} \ No newline at end of file diff --git a/libs/remix-ui/search/src/lib/components/Include.tsx b/libs/remix-ui/search/src/lib/components/Include.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/remix-ui/search/src/lib/components/Replace.tsx b/libs/remix-ui/search/src/lib/components/Replace.tsx new file mode 100644 index 0000000000..fc60d3d73a --- /dev/null +++ b/libs/remix-ui/search/src/lib/components/Replace.tsx @@ -0,0 +1,16 @@ +import React, { useContext, useEffect } from 'react' +import { SearchContext } from '../context/context' + +export const Replace = props => { + const { state, setReplace } = useContext(SearchContext) + + const change = e => { + setReplace(e.target.value) + } + + return ( + <> + + + ) +} diff --git a/libs/remix-ui/search/src/lib/components/Search.tsx b/libs/remix-ui/search/src/lib/components/Search.tsx new file mode 100644 index 0000000000..e9d2df1097 --- /dev/null +++ b/libs/remix-ui/search/src/lib/components/Search.tsx @@ -0,0 +1,25 @@ +import React, { useContext, useEffect, useReducer } from 'react' +import { SearchContext, SearchProvider } from '../context/context' +import { SearchingInitialState, SearchReducer } from '../reducers/Reducer' +import { Find } from './Find' +import { Replace } from './Replace' +import { Results } from './results/Results' + +export const SearchTab = props => { + +const plugin = props.plugin + +useEffect(() => { + console.log (plugin) +},[]) + +return ( + <> + + + + + + + ) +} diff --git a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/remix-ui/search/src/lib/components/results/Results.tsx b/libs/remix-ui/search/src/lib/components/results/Results.tsx new file mode 100644 index 0000000000..7514c51e98 --- /dev/null +++ b/libs/remix-ui/search/src/lib/components/results/Results.tsx @@ -0,0 +1,81 @@ +import { ViewPlugin } from "@remixproject/engine-web" +import React, { useContext, useEffect } from "react" +import { SearchContext } from "../../context/context" +import { SearchResult } from "../../reducers/Reducer" + +interface ResultsProps { + plugin: ViewPlugin +} + +export const Results = (props: ResultsProps) => { + + const { state, setSearchResults } = useContext(SearchContext) + + const { plugin } = props + + const getDirectory = async (dir) => { + let result = [] + const files = await plugin.call('fileManager', 'readdir', dir) + const fileArray = normalize(files) + for (const fi of fileArray) { + if (fi) { + const type = fi.data.isDirectory + if (type === true) { + result = [ + ...result, + ...(await getDirectory( + `${fi.filename}` + )) + ] + } else { + result = [...result, fi.filename] + } + } + } + return result + } + + const normalize = (filesList) => { + const folders = [] + const files = [] + Object.keys(filesList || {}).forEach(key => { + if (filesList[key].isDirectory) { + folders.push({ + filename: key, + data: filesList[key] + }) + } else { + files.push({ + filename: key, + data: filesList[key] + }) + } + }) + return [...folders, ...files] + } + + useEffect(() => { + if (state.find) { + getDirectory('/').then(res => { + const ob = res.map(file => { + const r:SearchResult = { + filename: file, + lines: [], + path: file, + searchComplete: false + } + return r + }) + console.log(ob) + setSearchResults(ob) + }) + } + },[state.find]) + + + useEffect(() => { + console.log(state.searchResults) + },[state.searchResults]) + + return(<>) +} \ No newline at end of file diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx new file mode 100644 index 0000000000..4b696f948e --- /dev/null +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -0,0 +1,88 @@ +import React from 'react' +import { createContext, useReducer } from 'react' +import { + SearchingInitialState, + SearchReducer, + SearchResult, + SearchState +} from '../reducers/Reducer' + +export interface SearchingStateInterface { + state: SearchState + setFind: (value: string) => void + setReplace: (value: string) => void + setInclude: (value: string) => void, + setExclude: (value: string) => void, + setCaseSensitive: (value: boolean) => void, + setRegex: (value: boolean) => void, + setWholeWord: (value: boolean) => void, + setSearchResults: (value: SearchResult[]) => void, +} + +export const SearchContext = createContext(null) + +export const SearchProvider = ({ + children = [], + reducer = SearchReducer, + initialState = SearchingInitialState +} = {}) => { + const [state, dispatch] = useReducer(reducer, initialState) + + const value = { + state, + setFind: (value: string) => { + dispatch({ + type: 'SET_FIND', + payload: value + }) + }, + setReplace: (value: string) => { + dispatch({ + type: 'SET_REPLACE', + payload: value + }) + }, + setInclude: (value: string) => { + dispatch({ + type: 'SET_INCLUDE', + payload: value + }) + }, + setExclude(value: string) { + dispatch({ + type: 'SET_EXCLUDE', + payload: value + }) + }, + setCaseSensitive(value: boolean) { + dispatch({ + type: 'SET_CASE_SENSITIVE', + payload: value + }) + }, + setWholeWord(value: boolean) { + dispatch({ + type: 'SET_WHOLE_WORD', + payload: value + }) + }, + setRegex(value: boolean) { + dispatch({ + type: 'SET_REGEX', + payload: value + }) + }, + setSearchResults(value: SearchResult[]) { + dispatch({ + type: 'SET_SEARCH_RESULTS', + payload: value + }) + } + } + + return ( + <> + {children} + + ) +} diff --git a/libs/remix-ui/search/src/lib/reducers/Reducer.ts b/libs/remix-ui/search/src/lib/reducers/Reducer.ts new file mode 100644 index 0000000000..e0cc2a4b0c --- /dev/null +++ b/libs/remix-ui/search/src/lib/reducers/Reducer.ts @@ -0,0 +1,70 @@ + +interface Action { + type: string + payload: any +} + +export interface SearchResultLine { + lineNumber: number + text: string +} + +export interface SearchResult { + filename: string, + path: string, + lines: SearchResultLine[], + searchComplete: boolean +} + +export interface SearchState { + find: string, + searchResults: SearchResult[], + replace: string, + include: string, + exclude: string, +} + +export const SearchingInitialState: SearchState = { + find: '', + replace: '', + include: '', + exclude: '', + searchResults: [] +} + +export const SearchReducer = (state: SearchState = SearchingInitialState, action: Action) => { + console.log(state) + switch (action.type) { + case 'SET_FIND': + return { + ...state, + find: action.payload, + } + break; + case 'SET_REPLACE': + return { + ...state, + replace: action.payload, + } + break; + case 'SET_INCLUDE': + return { + ...state, + include: action.payload, + } + break; + case 'SET_EXCLUDE': + return { + ...state, + exclude: action.payload, + } + break; + case 'SET_SEARCH_RESULTS': + return { + ...state, + searchResults: action.payload, + } + break; + default: + } +} \ No newline at end of file diff --git a/libs/remix-ui/search/tsconfig.json b/libs/remix-ui/search/tsconfig.json new file mode 100644 index 0000000000..a7180ef589 --- /dev/null +++ b/libs/remix-ui/search/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "jsx": "react", + "allowJs": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/remix-ui/search/tsconfig.lib.json b/libs/remix-ui/search/tsconfig.lib.json new file mode 100644 index 0000000000..b560bc4dec --- /dev/null +++ b/libs/remix-ui/search/tsconfig.lib.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "types": ["node"] + }, + "files": [ + "../../../node_modules/@nrwl/react/typings/cssmodule.d.ts", + "../../../node_modules/@nrwl/react/typings/image.d.ts" + ], + "exclude": ["**/*.spec.ts", "**/*.spec.tsx"], + "include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"] +} diff --git a/nx.json b/nx.json index 7f7de57643..bbf5b08f6f 100644 --- a/nx.json +++ b/nx.json @@ -139,6 +139,9 @@ "remix-ui-vertical-icons-panel": { "tags": [] }, + "remix-ui-search": { + "tags": [] + }, "remix-ui-home-tab": { "tags": [] }, diff --git a/package-lock.json b/package-lock.json index 18feb9d161..c72f9cbe60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9782,46 +9782,46 @@ "integrity": "sha512-IXf3XA7+XyN7CP9gGh/XB0UxVMlvARGEgGXLubFICsUMGz6Q+DU+i4gGlpOxTjKvXjkJDJC8YdqdKkDj9qZHEQ==" }, "@remixproject/engine": { - "version": "0.3.26", - "resolved": "https://registry.npmjs.org/@remixproject/engine/-/engine-0.3.26.tgz", - "integrity": "sha512-6Rq6aTUyhtXAaoQamAI8ocFSVy2txpGwu1aoYZGrqova/p/tRWn4/+PU713sffyiAQVBCk7C1z/5VKLm7tUYrQ==", + "version": "0.3.28", + "resolved": "https://registry.npmjs.org/@remixproject/engine/-/engine-0.3.28.tgz", + "integrity": "sha512-27SHaCrG3KrPfMa1MYud4tE9xUIJKITEUsql99fhN7x12lOmgGZFjiqIG/WWjCMmT7OMG3vtLayiZrsYkzHCVw==", "requires": { - "@remixproject/plugin-api": "0.3.26", - "@remixproject/plugin-utils": "0.3.26" + "@remixproject/plugin-api": "0.3.28", + "@remixproject/plugin-utils": "0.3.28" } }, "@remixproject/engine-web": { - "version": "0.3.26", - "resolved": "https://registry.npmjs.org/@remixproject/engine-web/-/engine-web-0.3.26.tgz", - "integrity": "sha512-QSW9KVOgHWuRDNqTZIp1jjBeDOXlXQZWYABgljTsC+Nig8EwlyRTfIza9PuCb+MDYT/kID8VgSPXnMrlOtvhjQ==", + "version": "0.3.28", + "resolved": "https://registry.npmjs.org/@remixproject/engine-web/-/engine-web-0.3.28.tgz", + "integrity": "sha512-JTwTuonW+pI7WsSsgGHAzPynGjIdG34VnPrspR9XKBQO4+NX7m3lbNIMUUviyrbqIoGiGtgYd/ry98uLpTHr4g==", "requires": { - "@remixproject/engine": "0.3.26", - "@remixproject/plugin-api": "0.3.26", - "@remixproject/plugin-utils": "0.3.26" + "@remixproject/engine": "0.3.28", + "@remixproject/plugin-api": "0.3.28", + "@remixproject/plugin-utils": "0.3.28" } }, "@remixproject/plugin": { - "version": "0.3.26", - "resolved": "https://registry.npmjs.org/@remixproject/plugin/-/plugin-0.3.26.tgz", - "integrity": "sha512-j0sgl4yDOVJLCuRWOEb/Wo9/fumrWlIpsO0MrtficuhVc1FGhZxKVv8Vdu3x3HgWhXkuhLUMs8VoJ1Ntd9ZkUQ==", + "version": "0.3.28", + "resolved": "https://registry.npmjs.org/@remixproject/plugin/-/plugin-0.3.28.tgz", + "integrity": "sha512-sw+cow3GKAcEacXLvdJwtHHIphPty4KRMZ6tcQHdtx/iCKTMNdw2hribKPnvTO+6mXE+4oAKCrFqeTdVp/rd1w==", "requires": { - "@remixproject/plugin-api": "0.3.26", - "@remixproject/plugin-utils": "0.3.26", + "@remixproject/plugin-api": "0.3.28", + "@remixproject/plugin-utils": "0.3.28", "events": "3.2.0" } }, "@remixproject/plugin-api": { - "version": "0.3.26", - "resolved": "https://registry.npmjs.org/@remixproject/plugin-api/-/plugin-api-0.3.26.tgz", - "integrity": "sha512-6vR9nVF4EfXDHA0r8MrlLyVYRMJMG7J3Y3jzpaAumetW+YpvfJqgE/uhGgm2me2ypDM8vW0POQGhRaGeZTGwFg==", + "version": "0.3.28", + "resolved": "https://registry.npmjs.org/@remixproject/plugin-api/-/plugin-api-0.3.28.tgz", + "integrity": "sha512-tOzVFR504037weEkNHQGZsk+Ebxcu/xnBsVCkJaQaBMb+H/i6YevKQmoR1aGcH+JfQxc8eS8LGC65MaV8zmcWg==", "requires": { - "@remixproject/plugin-utils": "0.3.26" + "@remixproject/plugin-utils": "0.3.28" } }, "@remixproject/plugin-utils": { - "version": "0.3.26", - "resolved": "https://registry.npmjs.org/@remixproject/plugin-utils/-/plugin-utils-0.3.26.tgz", - "integrity": "sha512-K/v+TXYOMV13dLf1LEgiF7CfqbOc105hC/2oapkSoHKSf3WVyWIUDlBsChRQl7osfUs/zT93q2+jNlLofWQUxg==", + "version": "0.3.28", + "resolved": "https://registry.npmjs.org/@remixproject/plugin-utils/-/plugin-utils-0.3.28.tgz", + "integrity": "sha512-5CayTgMqRiOguanTy6kpuRgCmjEFLUu2K4Rs7Zmt+GOzHucmwkDxYQO+3hFv0Jz/M/6yC5wkKYTx8vfPLLdEBQ==", "requires": { "tslib": "2.0.1" }, @@ -9834,13 +9834,13 @@ } }, "@remixproject/plugin-webview": { - "version": "0.3.26", - "resolved": "https://registry.npmjs.org/@remixproject/plugin-webview/-/plugin-webview-0.3.26.tgz", - "integrity": "sha512-hqWaFapUfcAX2Odsj0ANKvLXQbkzZ/xNONMqE0wRxFRYTIhFGZqFzJVzwSD+U4bSehP1JtzkrxwKBqNyjz5GxQ==", + "version": "0.3.28", + "resolved": "https://registry.npmjs.org/@remixproject/plugin-webview/-/plugin-webview-0.3.28.tgz", + "integrity": "sha512-DodSkN0vMSo2DEEoBOWyKxC/ElvBA826vhX+JVGXA8HGS45aavplZIN967hsc+SdzjV1UZfSNKEHttLGwM1BIw==", "requires": { - "@remixproject/plugin": "0.3.26", - "@remixproject/plugin-api": "0.3.26", - "@remixproject/plugin-utils": "0.3.26", + "@remixproject/plugin": "0.3.28", + "@remixproject/plugin-api": "0.3.28", + "@remixproject/plugin-utils": "0.3.28", "axios": "^0.21.1" }, "dependencies": { @@ -9855,13 +9855,13 @@ } }, "@remixproject/plugin-ws": { - "version": "0.3.26", - "resolved": "https://registry.npmjs.org/@remixproject/plugin-ws/-/plugin-ws-0.3.26.tgz", - "integrity": "sha512-Nerd/2vGb96G6B8pGRCRNAGlO97KnJpbFmpa47SYipgjaq5Yj5iCUY+fbQzMWdGW2W4BrUPE+YBZCkq/KlfbGw==", + "version": "0.3.28", + "resolved": "https://registry.npmjs.org/@remixproject/plugin-ws/-/plugin-ws-0.3.28.tgz", + "integrity": "sha512-i3He9t4qvcBQxzshFx66D6drqLlySmV7Cb+NeYtMOYlWxQSJtUakp/Px1Tl3IDFQXDfpXxvDvYhn2w0AWPBOqw==", "requires": { - "@remixproject/plugin": "0.3.26", - "@remixproject/plugin-api": "0.3.26", - "@remixproject/plugin-utils": "0.3.26" + "@remixproject/plugin": "0.3.28", + "@remixproject/plugin-api": "0.3.28", + "@remixproject/plugin-utils": "0.3.28" } }, "@restart/context": { diff --git a/tsconfig.base.json b/tsconfig.base.json index 8105a813ef..d9e148acdb 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -40,6 +40,7 @@ ], "@remix-project/remixd": ["dist/libs/remixd/index.js"], "@remix-ui/tree-view": ["libs/remix-ui/tree-view/src/index.ts"], + "@remix-ui/search": ["libs/remix-ui/search/src/index.ts"], "@remix-ui/debugger-ui": ["libs/remix-ui/debugger-ui/src/index.ts"], "@remix-ui/utils": ["libs/remix-ui/utils/src/index.ts"], "@remix-ui/clipboard": ["libs/remix-ui/clipboard/src/index.ts"], diff --git a/workspace.json b/workspace.json index dc00725dc8..98dcecd3ff 100644 --- a/workspace.json +++ b/workspace.json @@ -1108,6 +1108,21 @@ } } }, + "remix-ui-search": { + "root": "libs/remix-ui/search", + "sourceRoot": "libs/remix-ui/search/src", + "projectType": "library", + "architect": { + "lint": { + "builder": "@nrwl/linter:lint", + "options": { + "linter": "eslint", + "tsConfig": ["libs/remix-ui/search/tsconfig.lib.json"], + "exclude": ["**/node_modules/**", "!libs/remix-ui/search/**/*"] + } + } + } + }, "remix-ui-panel": { "root": "libs/remix-ui/panel", "sourceRoot": "libs/remix-ui/panel/src", From fe21ad5b6496322feea65536f78ca9a9a4401ae7 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 19 Feb 2022 15:38:09 +0100 Subject: [PATCH 02/35] components --- .../search/src/lib/components/Exclude.tsx | 26 +++ .../search/src/lib/components/Find.tsx | 51 ++++-- .../search/src/lib/components/Include.tsx | 22 +++ .../search/src/lib/components/Replace.tsx | 16 +- .../search/src/lib/components/Search.tsx | 18 +-- .../lib/components/results/ResultFileName.tsx | 20 +++ .../src/lib/components/results/ResultItem.tsx | 64 ++++++++ .../lib/components/results/ResultSummary.tsx | 34 ++++ .../src/lib/components/results/Results.tsx | 151 ++++++++++-------- .../lib/components/results/SearchHelper.ts | 45 ++++++ .../search/src/lib/context/context.tsx | 27 +++- .../search/src/lib/reducers/Reducer.ts | 31 +++- libs/remix-ui/search/src/lib/search.css | 26 +++ package.json | 1 + 14 files changed, 426 insertions(+), 106 deletions(-) create mode 100644 libs/remix-ui/search/src/lib/components/results/SearchHelper.ts create mode 100644 libs/remix-ui/search/src/lib/search.css diff --git a/libs/remix-ui/search/src/lib/components/Exclude.tsx b/libs/remix-ui/search/src/lib/components/Exclude.tsx index e69de29bb2..e755f1370e 100644 --- a/libs/remix-ui/search/src/lib/components/Exclude.tsx +++ b/libs/remix-ui/search/src/lib/components/Exclude.tsx @@ -0,0 +1,26 @@ +import React, { useContext, useEffect } from 'react' +import { SearchContext } from '../context/context' + +export const Exclude = props => { + const { setExclude } = useContext(SearchContext) + const change = e => { + const timeOutId = setTimeout(() => setExclude(e.target.value), 500) + return () => clearTimeout(timeOutId) + } + + useEffect(() => { + setExclude('.git/**') + }, []) + + return ( + <> +
+ +
+ + ) +} diff --git a/libs/remix-ui/search/src/lib/components/Find.tsx b/libs/remix-ui/search/src/lib/components/Find.tsx index db8cb94463..ef15cb1c81 100644 --- a/libs/remix-ui/search/src/lib/components/Find.tsx +++ b/libs/remix-ui/search/src/lib/components/Find.tsx @@ -1,17 +1,40 @@ -import React, { useContext, useReducer } from "react" -import { SearchContext } from "../context/context" -import { SearchingInitialState, SearchReducer } from "../reducers/Reducer" - - +import React, { useContext } from 'react' +import { SearchContext } from '../context/context' export const Find = props => { + const { setFind } = useContext(SearchContext) + const change = e => { + const timeOutId = setTimeout(() => setFind(e.target.value), 500) + return () => clearTimeout(timeOutId) + } - const { setFind } = useContext(SearchContext) - const change = (e) => { - setFind(e.target.value) - } - - return(<> - - ) -} \ No newline at end of file + return ( + <> +
+ + {/*
+
+
+
*/} +
+ + ) +} diff --git a/libs/remix-ui/search/src/lib/components/Include.tsx b/libs/remix-ui/search/src/lib/components/Include.tsx index e69de29bb2..bea364a6c9 100644 --- a/libs/remix-ui/search/src/lib/components/Include.tsx +++ b/libs/remix-ui/search/src/lib/components/Include.tsx @@ -0,0 +1,22 @@ +import React, { useContext } from 'react' +import { SearchContext } from '../context/context' + +export const Include = props => { + const { setInclude } = useContext(SearchContext) + const change = e => { + const timeOutId = setTimeout(() => setInclude(e.target.value), 500) + return () => clearTimeout(timeOutId) + } + + return ( + <> +
+ +
+ + ) +} diff --git a/libs/remix-ui/search/src/lib/components/Replace.tsx b/libs/remix-ui/search/src/lib/components/Replace.tsx index fc60d3d73a..28712774ca 100644 --- a/libs/remix-ui/search/src/lib/components/Replace.tsx +++ b/libs/remix-ui/search/src/lib/components/Replace.tsx @@ -1,16 +1,22 @@ -import React, { useContext, useEffect } from 'react' +import React, { useContext } from 'react' import { SearchContext } from '../context/context' export const Replace = props => { - const { state, setReplace } = useContext(SearchContext) - + const { setReplace } = useContext(SearchContext) const change = e => { - setReplace(e.target.value) + const timeOutId = setTimeout(() => setReplace(e.target.value), 500) + return () => clearTimeout(timeOutId) } return ( <> - +
+ +
) } diff --git a/libs/remix-ui/search/src/lib/components/Search.tsx b/libs/remix-ui/search/src/lib/components/Search.tsx index e9d2df1097..913e00eab2 100644 --- a/libs/remix-ui/search/src/lib/components/Search.tsx +++ b/libs/remix-ui/search/src/lib/components/Search.tsx @@ -1,23 +1,21 @@ -import React, { useContext, useEffect, useReducer } from 'react' -import { SearchContext, SearchProvider } from '../context/context' -import { SearchingInitialState, SearchReducer } from '../reducers/Reducer' +import React from 'react' +import { SearchProvider } from '../context/context' import { Find } from './Find' -import { Replace } from './Replace' import { Results } from './results/Results' +import '../search.css' +import { Include } from './Include' +import { Exclude } from './Exclude' export const SearchTab = props => { const plugin = props.plugin -useEffect(() => { - console.log (plugin) -},[]) - return ( <> - + - + + diff --git a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx index e69de29bb2..2d297a078a 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx @@ -0,0 +1,20 @@ +import { ViewPlugin } from '@remixproject/engine-web' +import React, { useContext, useEffect } from 'react' +import { SearchContext } from '../../context/context' +import { SearchResult } from '../../reducers/Reducer' + +interface ResultItemProps { + file: SearchResult +} + +export const ResultFileName = (props: ResultItemProps) => { + return ( +
+
+ + {props.file.filename} + +
+
+ ) +} diff --git a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx index e69de29bb2..54785a714d 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx @@ -0,0 +1,64 @@ +import { ViewPlugin } from '@remixproject/engine-web' +import React, { useContext, useEffect, useState } from 'react' +import { SearchContext } from '../../context/context' +import { SearchResult, SearchResultLine } from '../../reducers/Reducer' +import { ResultFileName } from './ResultFileName' +import { ResultSummary } from './ResultSummary' + +interface ResultItemProps { + file: SearchResult +} + +export const ResultItem = (props: ResultItemProps) => { + const { state, findText } = useContext(SearchContext) + + const [lines, setLines] = useState([]) + const [toggleExpander, setToggleExpander] = useState(false) + + useEffect(() => { + if (!props.file.searchComplete) { + // console.log('searching for: ' + props.file.filename) + } + }, [props.file.searchComplete]) + + const toggleClass = () => { + setToggleExpander(!toggleExpander) + } + + useEffect(() => { + if (!props.file.searchComplete) { + findText(props.file.filename).then(res => { + setLines(res) + }) + } + }, [state.find]) + + return ( + <> + {lines && lines.length ? ( + <> +
+ {' '} + +
+ {!toggleExpander ? ( +
    + {lines.map((line, index) => ( + + ))} +
+ ) : null} + + ) : ( + <> + )} + + ) +} diff --git a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx index e69de29bb2..f86d842212 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx @@ -0,0 +1,34 @@ +import { ViewPlugin } from '@remixproject/engine-web' +import React, { useContext, useEffect, useState } from 'react' +import { SearchContext } from '../../context/context' +import { SearchResult, SearchResultLine, SearchResultLineLine } from '../../reducers/Reducer' +import { ResultFileName } from './ResultFileName' + +interface ResultSummaryProps { + searchResult: SearchResult + line: SearchResultLine +} + +export const ResultSummary = (props: ResultSummaryProps) => { + const { hightLightInPath } = useContext(SearchContext) + const selectLine = async (line: SearchResultLineLine) => { + console.log(line, props.searchResult) + await hightLightInPath(props.searchResult, line) + } + return ( +
  • + {props.line.lines.map((lineItem, index) => ( +
    { + selectLine(lineItem) + }} + key={index} + > + {lineItem.left.substring(lineItem.left.length - 20)} + {lineItem.center} + {lineItem.right.substring(0, 100)} +
    + ))} +
  • + ) +} diff --git a/libs/remix-ui/search/src/lib/components/results/Results.tsx b/libs/remix-ui/search/src/lib/components/results/Results.tsx index 7514c51e98..ca109573fb 100644 --- a/libs/remix-ui/search/src/lib/components/results/Results.tsx +++ b/libs/remix-ui/search/src/lib/components/results/Results.tsx @@ -1,81 +1,98 @@ -import { ViewPlugin } from "@remixproject/engine-web" -import React, { useContext, useEffect } from "react" -import { SearchContext } from "../../context/context" -import { SearchResult } from "../../reducers/Reducer" +import { ViewPlugin } from '@remixproject/engine-web' +import { matches } from 'lodash' +import React, { useContext, useEffect, useState } from 'react' +import { SearchContext } from '../../context/context' +import { SearchResult, SearchResultLine } from '../../reducers/Reducer' +import { ResultItem } from './ResultItem' +import { findLinesInStringWithMatch } from './SearchHelper' +const filePathFilter = require('@jsdevtools/file-path-filter') interface ResultsProps { - plugin: ViewPlugin + plugin: ViewPlugin } export const Results = (props: ResultsProps) => { + const { state, setSearchResults, setFind } = useContext(SearchContext) + const [ alertText, setAlertText ] = useState('') + const { plugin } = props - const { state, setSearchResults } = useContext(SearchContext) - - const { plugin } = props - - const getDirectory = async (dir) => { - let result = [] - const files = await plugin.call('fileManager', 'readdir', dir) - const fileArray = normalize(files) - for (const fi of fileArray) { - if (fi) { - const type = fi.data.isDirectory - if (type === true) { - result = [ - ...result, - ...(await getDirectory( - `${fi.filename}` - )) - ] - } else { - result = [...result, fi.filename] - } - } + const getDirectory = async (dir: string) => { + let result = [] + const files = await plugin.call('fileManager', 'readdir', dir) + const fileArray = normalize(files) + for (const fi of fileArray) { + if (fi) { + const type = fi.data.isDirectory + if (type === true) { + result = [...result, ...(await getDirectory(`${fi.filename}`))] + } else { + result = [...result, fi.filename] } - return result + } } + return result + } - const normalize = (filesList) => { - const folders = [] - const files = [] - Object.keys(filesList || {}).forEach(key => { - if (filesList[key].isDirectory) { - folders.push({ - filename: key, - data: filesList[key] - }) - } else { - files.push({ - filename: key, - data: filesList[key] - }) - } + const normalize = filesList => { + const folders = [] + const files = [] + Object.keys(filesList || {}).forEach(key => { + if (filesList[key].isDirectory) { + folders.push({ + filename: key, + data: filesList[key] + }) + } else { + files.push({ + filename: key, + data: filesList[key] }) - return [...folders, ...files] } + }) + return [...folders, ...files] + } - useEffect(() => { - if (state.find) { - getDirectory('/').then(res => { - const ob = res.map(file => { - const r:SearchResult = { - filename: file, - lines: [], - path: file, - searchComplete: false - } - return r - }) - console.log(ob) - setSearchResults(ob) - }) - } - },[state.find]) + useEffect(() => { + plugin.on('filePanel', 'setWorkspace', () => { + setSearchResults(null) + }) + return () => plugin.off('filePanel', 'setWorkspace') + }, []) + useEffect(() => { + if (state.find) { + (async () => { + const res = await getDirectory('/') + const pathFilter: any = {} + if (state.include) + pathFilter.include = state.include.split(',').map(i => i.trim()) + if (state.exclude) + pathFilter.exclude = state.exclude.split(',').map(i => i.trim()) + const ob = res.filter(filePathFilter(pathFilter)).map(file => { + const r: SearchResult = { + filename: file, + lines: [], + path: file, + searchComplete: false + } + return r + }) + setSearchResults(ob) + })() + } + }, [state.find, state.replace, state.include, state.exclude]) - useEffect(() => { - console.log(state.searchResults) - },[state.searchResults]) - - return(<>) -} \ No newline at end of file + return ( + <> + {alertText ? ( +
    + {alertText} +
    + ) : null} + {state.searchResults && + state.searchResults.map((result, index) => { + return + })} + + ) +} diff --git a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts new file mode 100644 index 0000000000..3e41e418ca --- /dev/null +++ b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts @@ -0,0 +1,45 @@ +import { SearchResultLineLine } from "../../reducers/Reducer" + +export const findLinesInStringWithMatch = (str: string, re: RegExp) => { + return str + .split(/\r?\n/) + .map(function (line, i) { + const matchResult = matchesInString(line, re) + if (matchResult.length) { + return { + lines: splitLines(matchResult, i), + } + } + }) + .filter(Boolean) +} + +const matchesInString = (str: string, re: RegExp) => { + let a: RegExpExecArray + let results:RegExpExecArray[] = []; + while ((a = re.exec(str || '')) !== null) { + results.push(a); + } + return results +} + +const splitLines = (matchResult: RegExpExecArray[], lineNumber: number) => { + return matchResult.map((matchResultPart, i) => { + const result:SearchResultLineLine = { + left: matchResultPart.input.substring(0, matchResultPart.index), + right: matchResultPart.input.substring(matchResultPart.index + matchResultPart[0].length), + center: matchResultPart[0], + position : { + start: { + line: lineNumber, + column: matchResultPart.index, + }, + end: { + line: lineNumber, + column: matchResultPart.index + matchResultPart[0].length, + }, + }, + } + return result + }) +} diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index 4b696f948e..1762d7c367 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -1,9 +1,12 @@ import React from 'react' import { createContext, useReducer } from 'react' +import { findLinesInStringWithMatch } from '../components/results/SearchHelper' import { SearchingInitialState, SearchReducer, SearchResult, + SearchResultLine, + SearchResultLineLine, SearchState } from '../reducers/Reducer' @@ -17,6 +20,8 @@ export interface SearchingStateInterface { setRegex: (value: boolean) => void, setWholeWord: (value: boolean) => void, setSearchResults: (value: SearchResult[]) => void, + findText: (path: string) => Promise, + hightLightInPath: (path:SearchResult, line:SearchResultLineLine) => void, } export const SearchContext = createContext(null) @@ -24,13 +29,15 @@ export const SearchContext = createContext(null) export const SearchProvider = ({ children = [], reducer = SearchReducer, - initialState = SearchingInitialState + initialState = SearchingInitialState, + plugin = undefined } = {}) => { const [state, dispatch] = useReducer(reducer, initialState) const value = { state, setFind: (value: string) => { + console.log('setFind: ' + value) dispatch({ type: 'SET_FIND', payload: value @@ -77,7 +84,23 @@ export const SearchProvider = ({ type: 'SET_SEARCH_RESULTS', payload: value }) - } + }, + findText : async (path: string) => { + if(!plugin) return + try { + if(state.find.length < 3) return + const text = await plugin.call('fileManager', 'readFile', path) + const re = new RegExp(state.find, 'gi') + const result: SearchResultLine[] = findLinesInStringWithMatch(text, re) + // console.log(result, path) + return result + } catch (e) {} + }, + hightLightInPath: async(result: SearchResult, line: SearchResultLineLine) => { + await plugin.call('editor', 'discardHighlight') + await plugin.call('editor', 'highlight', line.position, result.path) + } + } return ( diff --git a/libs/remix-ui/search/src/lib/reducers/Reducer.ts b/libs/remix-ui/search/src/lib/reducers/Reducer.ts index e0cc2a4b0c..c4a6742a08 100644 --- a/libs/remix-ui/search/src/lib/reducers/Reducer.ts +++ b/libs/remix-ui/search/src/lib/reducers/Reducer.ts @@ -4,9 +4,25 @@ interface Action { 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 { - lineNumber: number - text: string + lines: SearchResultLineLine[] } export interface SearchResult { @@ -33,38 +49,37 @@ export const SearchingInitialState: SearchState = { } export const SearchReducer = (state: SearchState = SearchingInitialState, action: Action) => { - console.log(state) switch (action.type) { case 'SET_FIND': return { ...state, find: action.payload, } - break; + case 'SET_REPLACE': return { ...state, replace: action.payload, } - break; + case 'SET_INCLUDE': return { ...state, include: action.payload, } - break; + case 'SET_EXCLUDE': return { ...state, exclude: action.payload, } - break; + case 'SET_SEARCH_RESULTS': return { ...state, searchResults: action.payload, } - break; + default: } } \ No newline at end of file diff --git a/libs/remix-ui/search/src/lib/search.css b/libs/remix-ui/search/src/lib/search.css new file mode 100644 index 0000000000..a7b9326785 --- /dev/null +++ b/libs/remix-ui/search/src/lib/search.css @@ -0,0 +1,26 @@ +.search_result_item_title { + display: flex; + -webkit-user-select: none; /* Safari */ + -moz-user-select: none; /* Firefox */ + -ms-user-select: none; /* IE10+/Edge */ + user-select: none; /* Standard */ + cursor: pointer; +} + +.wrap_summary { + overflow: hidden; + white-space: nowrap; + -webkit-user-select: none; /* Safari */ + -moz-user-select: none; /* Firefox */ + -ms-user-select: none; /* IE10+/Edge */ + user-select: none; /* Standard */ + cursor: pointer; +} + +.find-part { + display: flex; +} + +.controls { + display: flex; +} \ No newline at end of file diff --git a/package.json b/package.json index 3585888453..a38866094a 100644 --- a/package.json +++ b/package.json @@ -171,6 +171,7 @@ "ethers": "^5.4.2", "ethjs-util": "^0.1.6", "express-ws": "^4.0.0", + "file-path-filter": "^3.0.2", "file-saver": "^2.0.5", "form-data": "^4.0.0", "fs-extra": "^3.0.1", From 658cff4810f01ddf260dbd6dd363e3a6220adc48 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sun, 20 Feb 2022 15:13:26 +0100 Subject: [PATCH 03/35] tools ready to test --- .../contracts/app/ethereum/constitution.sol | 2 +- .../search/src/lib/components/Exclude.tsx | 10 +- .../search/src/lib/components/Find.tsx | 62 +++++++----- .../search/src/lib/components/Include.tsx | 1 + .../search/src/lib/components/Replace.tsx | 1 + .../search/src/lib/components/Search.tsx | 6 +- .../lib/components/results/ResultFileName.tsx | 8 +- .../src/lib/components/results/ResultItem.tsx | 40 ++++---- .../lib/components/results/ResultSummary.tsx | 38 +++++--- .../src/lib/components/results/Results.tsx | 78 +-------------- .../lib/components/results/SearchHelper.ts | 65 ++++++++++++- .../search/src/lib/context/context.tsx | 94 ++++++++++++++++--- .../search/src/lib/reducers/Reducer.ts | 77 ++++++--------- libs/remix-ui/search/src/lib/search.css | 62 ++++++++++++ libs/remix-ui/search/src/lib/types/index.ts | 55 +++++++++++ 15 files changed, 396 insertions(+), 203 deletions(-) create mode 100644 libs/remix-ui/search/src/lib/types/index.ts diff --git a/apps/remix-ide/contracts/app/ethereum/constitution.sol b/apps/remix-ide/contracts/app/ethereum/constitution.sol index 8c2c9e0da9..ff36bdb9c8 100644 --- a/apps/remix-ide/contracts/app/ethereum/constitution.sol +++ b/apps/remix-ide/contracts/app/ethereum/constitution.sol @@ -1,4 +1,4 @@ -contract Constitution { + Constitution { function Found(uint8 _numProposals) { proposals.length = _numProposals; diff --git a/libs/remix-ui/search/src/lib/components/Exclude.tsx b/libs/remix-ui/search/src/lib/components/Exclude.tsx index e755f1370e..c836183157 100644 --- a/libs/remix-ui/search/src/lib/components/Exclude.tsx +++ b/libs/remix-ui/search/src/lib/components/Exclude.tsx @@ -1,9 +1,11 @@ -import React, { useContext, useEffect } from 'react' +import React, { useContext, useEffect, useState } from 'react' import { SearchContext } from '../context/context' export const Exclude = props => { - const { setExclude } = useContext(SearchContext) + const { setExclude, state } = useContext(SearchContext) + const [str, setStr] = useState('.git/**/*,.deps/**/*') const change = e => { + setStr(e.target.value) const timeOutId = setTimeout(() => setExclude(e.target.value), 500) return () => clearTimeout(timeOutId) } @@ -15,10 +17,12 @@ export const Exclude = props => { return ( <>
    +
    diff --git a/libs/remix-ui/search/src/lib/components/Find.tsx b/libs/remix-ui/search/src/lib/components/Find.tsx index ef15cb1c81..e1e861b620 100644 --- a/libs/remix-ui/search/src/lib/components/Find.tsx +++ b/libs/remix-ui/search/src/lib/components/Find.tsx @@ -2,38 +2,48 @@ import React, { useContext } from 'react' import { SearchContext } from '../context/context' export const Find = props => { - const { setFind } = useContext(SearchContext) + const { setFind, state, toggleCaseSensitive, toggleMatchWholeWord } = useContext(SearchContext) + let timeOutId: any = null const change = e => { - const timeOutId = setTimeout(() => setFind(e.target.value), 500) - return () => clearTimeout(timeOutId) + clearTimeout(timeOutId) + timeOutId = setTimeout(() => setFind(e.target.value), 500) } return ( <>
    - - {/*
    -
    -
    -
    */} + +
    + +
    +
    { + toggleCaseSensitive() + }} + >
    +
    { + toggleMatchWholeWord() + }} + >
    +
    +
    ) diff --git a/libs/remix-ui/search/src/lib/components/Include.tsx b/libs/remix-ui/search/src/lib/components/Include.tsx index bea364a6c9..a59dd11988 100644 --- a/libs/remix-ui/search/src/lib/components/Include.tsx +++ b/libs/remix-ui/search/src/lib/components/Include.tsx @@ -11,6 +11,7 @@ export const Include = props => { return ( <>
    + { return ( <>
    + { @@ -12,12 +13,15 @@ const plugin = props.plugin return ( <> +
    + - + +
    ) } diff --git a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx index 2d297a078a..8df5162bbe 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx @@ -1,7 +1,5 @@ -import { ViewPlugin } from '@remixproject/engine-web' -import React, { useContext, useEffect } from 'react' -import { SearchContext } from '../../context/context' -import { SearchResult } from '../../reducers/Reducer' +import React from 'react' +import { SearchResult } from '../../types' interface ResultItemProps { file: SearchResult @@ -9,7 +7,7 @@ interface ResultItemProps { export const ResultFileName = (props: ResultItemProps) => { return ( -
    +
    {props.file.filename} diff --git a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx index 54785a714d..baf61ecaca 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx @@ -1,7 +1,6 @@ -import { ViewPlugin } from '@remixproject/engine-web' import React, { useContext, useEffect, useState } from 'react' import { SearchContext } from '../../context/context' -import { SearchResult, SearchResultLine } from '../../reducers/Reducer' +import { SearchResult, SearchResultLine } from '../../types' import { ResultFileName } from './ResultFileName' import { ResultSummary } from './ResultSummary' @@ -11,34 +10,35 @@ interface ResultItemProps { export const ResultItem = (props: ResultItemProps) => { const { state, findText } = useContext(SearchContext) - + const [loading, setLoading] = useState(false) const [lines, setLines] = useState([]) const [toggleExpander, setToggleExpander] = useState(false) useEffect(() => { - if (!props.file.searchComplete) { - // console.log('searching for: ' + props.file.filename) - } - }, [props.file.searchComplete]) + reload() + }, [props.file.timeStamp]) const toggleClass = () => { setToggleExpander(!toggleExpander) } useEffect(() => { - if (!props.file.searchComplete) { - findText(props.file.filename).then(res => { - setLines(res) - }) - } + reload() }, [state.find]) + const reload = () => { + findText(props.file.filename).then(res => { + setLines(res) + setLoading(false) + }) + } + return ( <> {lines && lines.length ? ( <>
    - {' '}
    - {!toggleExpander ? ( -
      + {loading ?
      Loading...
      : null} + {!toggleExpander && !loading ? ( +
      {lines.map((line, index) => ( - + ))} -
    +
    ) : null} ) : ( diff --git a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx index f86d842212..f215e8c50e 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx @@ -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 ( -
  • + <> {props.line.lines.map((lineItem, index) => ( +
    { selectLine(lineItem) }} - key={index} + key={props.searchResult.filename} + className='search_line pb-1' > - {lineItem.left.substring(lineItem.left.length - 20)} - {lineItem.center} - {lineItem.right.substring(0, 100)} +
    {lineItem.left.substring(lineItem.left.length - 20)}
    + {lineItem.center} + {state.replace? {state.replace}:<>} +
    {lineItem.right.substring(0, 100)}
    +
    +
    +
    { + replace(lineItem) + }} className="codicon codicon-find-replace" role="button" aria-label="Replace" aria-disabled="false">
    +
    ))} -
  • + ) } diff --git a/libs/remix-ui/search/src/lib/components/results/Results.tsx b/libs/remix-ui/search/src/lib/components/results/Results.tsx index ca109573fb..32efca1484 100644 --- a/libs/remix-ui/search/src/lib/components/results/Results.tsx +++ b/libs/remix-ui/search/src/lib/components/results/Results.tsx @@ -1,86 +1,12 @@ -import { ViewPlugin } from '@remixproject/engine-web' -import { matches } from 'lodash' import React, { useContext, useEffect, useState } from 'react' import { SearchContext } from '../../context/context' -import { SearchResult, SearchResultLine } from '../../reducers/Reducer' import { ResultItem } from './ResultItem' -import { findLinesInStringWithMatch } from './SearchHelper' -const filePathFilter = require('@jsdevtools/file-path-filter') - interface ResultsProps { - plugin: ViewPlugin } export const Results = (props: ResultsProps) => { - const { state, setSearchResults, setFind } = useContext(SearchContext) - const [ alertText, setAlertText ] = useState('') - const { plugin } = props - - const getDirectory = async (dir: string) => { - let result = [] - const files = await plugin.call('fileManager', 'readdir', dir) - const fileArray = normalize(files) - for (const fi of fileArray) { - if (fi) { - const type = fi.data.isDirectory - if (type === true) { - result = [...result, ...(await getDirectory(`${fi.filename}`))] - } else { - result = [...result, fi.filename] - } - } - } - return result - } - - const normalize = filesList => { - const folders = [] - const files = [] - Object.keys(filesList || {}).forEach(key => { - if (filesList[key].isDirectory) { - folders.push({ - filename: key, - data: filesList[key] - }) - } else { - files.push({ - filename: key, - data: filesList[key] - }) - } - }) - return [...folders, ...files] - } - - useEffect(() => { - plugin.on('filePanel', 'setWorkspace', () => { - setSearchResults(null) - }) - return () => plugin.off('filePanel', 'setWorkspace') - }, []) - - useEffect(() => { - if (state.find) { - (async () => { - const res = await getDirectory('/') - const pathFilter: any = {} - if (state.include) - pathFilter.include = state.include.split(',').map(i => i.trim()) - if (state.exclude) - pathFilter.exclude = state.exclude.split(',').map(i => i.trim()) - const ob = res.filter(filePathFilter(pathFilter)).map(file => { - const r: SearchResult = { - filename: file, - lines: [], - path: file, - searchComplete: false - } - return r - }) - setSearchResults(ob) - })() - } - }, [state.find, state.replace, state.include, state.exclude]) + const { state} = useContext(SearchContext) + const [alertText, setAlertText] = useState('') return ( <> diff --git a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts index 3e41e418ca..8cd3c0fe36 100644 --- a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts +++ b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts @@ -1,4 +1,42 @@ -import { SearchResultLineLine } from "../../reducers/Reducer" +import { EOL } from 'os' +import { SearchResultLineLine } from '../../types' + + +export const getDirectory = async (dir: string, plugin: any) => { + let result = [] + const files = await plugin.call('fileManager', 'readdir', dir) + const fileArray = normalize(files) + for (const fi of fileArray) { + if (fi) { + const type = fi.data.isDirectory + if (type === true) { + result = [...result, ...(await getDirectory(`${fi.filename}`, plugin))] + } else { + result = [...result, fi.filename] + } + } + } + return result + } + + const normalize = filesList => { + const folders = [] + const files = [] + Object.keys(filesList || {}).forEach(key => { + if (filesList[key].isDirectory) { + folders.push({ + filename: key, + data: filesList[key] + }) + } else { + files.push({ + filename: key, + data: filesList[key] + }) + } + }) + return [...folders, ...files] + } export const findLinesInStringWithMatch = (str: string, re: RegExp) => { return str @@ -43,3 +81,28 @@ const splitLines = (matchResult: RegExpExecArray[], lineNumber: number) => { return result }) } + +function getEOL(text) { + const m = text.match(/\r\n|\n/g); + const u = m && m.filter(a => a === '\n').length; + const w = m && m.length - u; + if (u === w) { + return EOL; // use the OS default + } + return u > w ? '\n' : '\r\n'; +} + + +export const replaceTextInLine = (str: string, searchResultLine: SearchResultLineLine, newText: string) => { + return str + .split(/\r?\n/) + .map(function (line, i) { + if (i === searchResultLine.position.start.line) { + return searchResultLine.left + newText + searchResultLine.right + } + return line + }).join(getEOL(str)) +} + + + diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index 1762d7c367..2b03c54df0 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -1,14 +1,11 @@ -import React from 'react' +import React, { useEffect } from 'react' import { createContext, useReducer } from 'react' -import { findLinesInStringWithMatch } from '../components/results/SearchHelper' +import { findLinesInStringWithMatch, getDirectory, replaceTextInLine } from '../components/results/SearchHelper' import { - SearchingInitialState, SearchReducer, - SearchResult, - SearchResultLine, - SearchResultLineLine, - SearchState } from '../reducers/Reducer' +import { SearchState, SearchResult, SearchResultLine, SearchResultLineLine, SearchingInitialState } from '../types' +const filePathFilter = require('@jsdevtools/file-path-filter') export interface SearchingStateInterface { state: SearchState @@ -21,7 +18,11 @@ export interface SearchingStateInterface { setWholeWord: (value: boolean) => void, setSearchResults: (value: SearchResult[]) => void, findText: (path: string) => Promise, - hightLightInPath: (path:SearchResult, line:SearchResultLineLine) => void, + hightLightInPath: (result:SearchResult, line:SearchResultLineLine) => void, + replaceText: (result: SearchResult, line: SearchResultLineLine) => void, + reloadFile: (file:string) => void, + toggleCaseSensitive: () => void, + toggleMatchWholeWord: () => void, } export const SearchContext = createContext(null) @@ -33,11 +34,11 @@ export const SearchProvider = ({ plugin = undefined } = {}) => { const [state, dispatch] = useReducer(reducer, initialState) + let reloadTimeOut: any = null const value = { state, setFind: (value: string) => { - console.log('setFind: ' + value) dispatch({ type: 'SET_FIND', payload: value @@ -85,24 +86,95 @@ export const SearchProvider = ({ payload: value }) }, + reloadFile: async (file:string) => { + dispatch({ + type: 'RELOAD_FILE', + payload: file + }) + }, + toggleCaseSensitive: () => { + dispatch({ + type: 'TOGGLE_CASE_SENSITIVE', + payload: undefined + }) + }, + toggleMatchWholeWord: () => { + dispatch({ + type: 'TOGGLE_MATCH_WHOLE_WORD', + payload: undefined + }) + }, findText : async (path: string) => { if(!plugin) return try { if(state.find.length < 3) return const text = await plugin.call('fileManager', 'readFile', path) - const re = new RegExp(state.find, 'gi') + let flags = 'g' + let find = state.find + if(!state.casesensitive) flags += 'i' + if(state.matchWord) find = `\\b${find}\\b` + const re = new RegExp(find, flags) const result: SearchResultLine[] = findLinesInStringWithMatch(text, re) - // console.log(result, path) return result } catch (e) {} }, hightLightInPath: async(result: SearchResult, line: SearchResultLineLine) => { await plugin.call('editor', 'discardHighlight') await plugin.call('editor', 'highlight', line.position, result.path) + }, + replaceText: async(result: SearchResult, line: SearchResultLineLine) => { + await plugin.call('editor', 'discardHighlight') + await plugin.call('editor', 'highlight', line.position, result.path) + let content = await plugin.call('fileManager', 'readFile', result.path) + await plugin.call('fileManager','setFile', result.path, replaceTextInLine(content, line, state.replace)) } + } + const reloadStateForFile = async (file: string) => { + clearTimeout(reloadTimeOut) + reloadTimeOut = setTimeout(async () => { + await value.reloadFile(file) + }, 1000) } + useEffect(() => { + plugin.on('filePanel', 'setWorkspace', () => { + value.setSearchResults(null) + }) + plugin.on('fileManager', 'fileSaved', async file => { + await reloadStateForFile(file) + }) + return () => { + plugin.off('fileManager', 'fileChanged') + plugin.off('filePanel', 'setWorkspace') + } + }, []) + + useEffect(() => { + if (state.find) { + (async () => { + const res = await getDirectory('/', plugin) + const pathFilter: any = {} + if (state.include) + pathFilter.include = state.include.split(',').map(i => i.trim()) + if (state.exclude) + pathFilter.exclude = state.exclude.split(',').map(i => i.trim()) + const ob = res.filter(filePathFilter(pathFilter)).map(file => { + const r: SearchResult = { + filename: file, + lines: [], + path: file, + timeStamp: Date.now() + } + return r + }) + value.setSearchResults(ob) + })() + } + }, [state.timeStamp]) + + + return ( <> {children} diff --git a/libs/remix-ui/search/src/lib/reducers/Reducer.ts b/libs/remix-ui/search/src/lib/reducers/Reducer.ts index c4a6742a08..907a57b8c8 100644 --- a/libs/remix-ui/search/src/lib/reducers/Reducer.ts +++ b/libs/remix-ui/search/src/lib/reducers/Reducer.ts @@ -1,52 +1,4 @@ - -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[], - searchComplete: boolean -} - -export interface SearchState { - find: string, - searchResults: SearchResult[], - replace: string, - include: string, - exclude: string, -} - -export const SearchingInitialState: SearchState = { - find: '', - replace: '', - include: '', - exclude: '', - searchResults: [] -} +import { Action, SearchingInitialState, SearchState } from "../types" export const SearchReducer = (state: SearchState = SearchingInitialState, action: Action) => { switch (action.type) { @@ -54,6 +6,7 @@ export const SearchReducer = (state: SearchState = SearchingInitialState, action return { ...state, find: action.payload, + timeStamp: Date.now() } case 'SET_REPLACE': @@ -66,12 +19,14 @@ export const SearchReducer = (state: SearchState = SearchingInitialState, action return { ...state, include: action.payload, + timeStamp: Date.now() } case 'SET_EXCLUDE': return { ...state, exclude: action.payload, + timeStamp: Date.now() } case 'SET_SEARCH_RESULTS': @@ -79,7 +34,29 @@ export const SearchReducer = (state: SearchState = SearchingInitialState, action ...state, searchResults: action.payload, } - + case 'TOGGLE_CASE_SENSITIVE': + return { + ...state, + casesensitive: !state.casesensitive, + timeStamp: Date.now() + } + case 'TOGGLE_MATCH_WHOLE_WORD': + return { + ...state, + matchWord: !state.matchWord, + timeStamp: Date.now() + } + case 'RELOAD_FILE': + if (state.searchResults) { + const findFile = state.searchResults.find(file => file.filename === action.payload) + if (findFile) findFile.timeStamp = Date.now() + } + return { + ...state, + } default: + return { + ...state, + } } } \ No newline at end of file diff --git a/libs/remix-ui/search/src/lib/search.css b/libs/remix-ui/search/src/lib/search.css index a7b9326785..089cae82ed 100644 --- a/libs/remix-ui/search/src/lib/search.css +++ b/libs/remix-ui/search/src/lib/search.css @@ -19,8 +19,70 @@ .find-part { display: flex; + flex-direction: column; + padding: 2px; } .controls { display: flex; +} + +.search_tab .search_line_container { + display: flex; + flex-direction: row; + position: relative; +} + +.search_tab .search_line { + width: 100%; + overflow: hidden; + display: flex; +} + +.search_tab .search_control { + flex-grow: 0; + position: absolute; + right: 0px; + top: 0px; +} + +.summary_right { + min-width: 0; + white-space: pre; + text-overflow: ellipsis; + overflow: hidden; +} + +.search_tab .replace_strike { + text-decoration: line-through; +} + +.summary_left { + white-space: pre; +} + +.search_tab mark { + padding: 0; +} + +.search_tab .search_line_container .search_control { + display: none; +} + +.search_tab .search_line_container:hover .search_control { + display: block; +} + +.search_tab .search_line_container:hover .search_line { + width: 93%; +} + +.search-input { + display: flex; + flex-direction: row; + align-items: center; +} + +.search_tab .checked { + background-color: var(--secondary); } \ No newline at end of file diff --git a/libs/remix-ui/search/src/lib/types/index.ts b/libs/remix-ui/search/src/lib/types/index.ts new file mode 100644 index 0000000000..7b558085f5 --- /dev/null +++ b/libs/remix-ui/search/src/lib/types/index.ts @@ -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 +} \ No newline at end of file From e5ebc8926acc7b751ef06730da7ce405d5d8457c Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sun, 20 Feb 2022 15:23:05 +0100 Subject: [PATCH 04/35] fix lint --- libs/remix-ui/search/src/lib/components/results/Results.tsx | 4 +--- .../search/src/lib/components/results/SearchHelper.ts | 2 +- libs/remix-ui/search/src/lib/context/context.tsx | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libs/remix-ui/search/src/lib/components/results/Results.tsx b/libs/remix-ui/search/src/lib/components/results/Results.tsx index 32efca1484..810b2351fd 100644 --- a/libs/remix-ui/search/src/lib/components/results/Results.tsx +++ b/libs/remix-ui/search/src/lib/components/results/Results.tsx @@ -1,10 +1,8 @@ import React, { useContext, useEffect, useState } from 'react' import { SearchContext } from '../../context/context' import { ResultItem } from './ResultItem' -interface ResultsProps { -} -export const Results = (props: ResultsProps) => { +export const Results = () => { const { state} = useContext(SearchContext) const [alertText, setAlertText] = useState('') diff --git a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts index 8cd3c0fe36..88ae6b1de1 100644 --- a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts +++ b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts @@ -54,7 +54,7 @@ export const findLinesInStringWithMatch = (str: string, re: RegExp) => { const matchesInString = (str: string, re: RegExp) => { let a: RegExpExecArray - let results:RegExpExecArray[] = []; + const results:RegExpExecArray[] = []; while ((a = re.exec(str || '')) !== null) { results.push(a); } diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index 2b03c54df0..c3f387857c 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -5,7 +5,7 @@ import { SearchReducer, } from '../reducers/Reducer' import { SearchState, SearchResult, SearchResultLine, SearchResultLineLine, SearchingInitialState } from '../types' -const filePathFilter = require('@jsdevtools/file-path-filter') +import { filePathFilter } from '@jsdevtools/file-path-filter' export interface SearchingStateInterface { state: SearchState @@ -125,7 +125,7 @@ export const SearchProvider = ({ replaceText: async(result: SearchResult, line: SearchResultLineLine) => { await plugin.call('editor', 'discardHighlight') await plugin.call('editor', 'highlight', line.position, result.path) - let content = await plugin.call('fileManager', 'readFile', result.path) + const content = await plugin.call('fileManager', 'readFile', result.path) await plugin.call('fileManager','setFile', result.path, replaceTextInLine(content, line, state.replace)) } } From 554b439d14717b1f4cd187e6d3e263f772a370c4 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sun, 20 Feb 2022 16:09:50 +0100 Subject: [PATCH 05/35] trim left --- .../search/src/lib/components/results/ResultSummary.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx index f215e8c50e..18b76950f6 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx @@ -31,7 +31,7 @@ export const ResultSummary = (props: ResultSummaryProps) => { key={props.searchResult.filename} className='search_line pb-1' > -
    {lineItem.left.substring(lineItem.left.length - 20)}
    +
    {lineItem.left.substring(lineItem.left.length - 20).trimStart()}
    {lineItem.center} {state.replace? {state.replace}:<>}
    {lineItem.right.substring(0, 100)}
    From 6dc72846fa832e22e583689d3785cbb9993e7b6f Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 13:12:06 +0100 Subject: [PATCH 06/35] regex support --- .../search/src/lib/components/Find.tsx | 33 ++++++- .../search/src/lib/components/Search.tsx | 2 +- .../lib/components/results/ResultFileName.tsx | 23 +++-- .../lib/components/results/ResultSummary.tsx | 6 +- .../lib/components/results/SearchHelper.ts | 3 + .../search/src/lib/context/context.tsx | 92 +++++++++++++------ .../search/src/lib/reducers/Reducer.ts | 6 ++ libs/remix-ui/search/src/lib/search.css | 7 ++ libs/remix-ui/search/src/lib/types/index.ts | 2 + 9 files changed, 129 insertions(+), 45 deletions(-) diff --git a/libs/remix-ui/search/src/lib/components/Find.tsx b/libs/remix-ui/search/src/lib/components/Find.tsx index e1e861b620..c8949ec34c 100644 --- a/libs/remix-ui/search/src/lib/components/Find.tsx +++ b/libs/remix-ui/search/src/lib/components/Find.tsx @@ -2,7 +2,13 @@ import React, { useContext } from 'react' import { SearchContext } from '../context/context' export const Find = props => { - const { setFind, state, toggleCaseSensitive, toggleMatchWholeWord } = useContext(SearchContext) + const { + setFind, + state, + toggleCaseSensitive, + toggleMatchWholeWord, + toggleUseRegex + } = useContext(SearchContext) let timeOutId: any = null const change = e => { clearTimeout(timeOutId) @@ -21,11 +27,13 @@ export const Find = props => { >
    { toggleCaseSensitive() @@ -33,7 +41,9 @@ export const Find = props => { >
    { toggleMatchWholeWord() }} >
    +
    { + toggleUseRegex() + }} + >
    diff --git a/libs/remix-ui/search/src/lib/components/Search.tsx b/libs/remix-ui/search/src/lib/components/Search.tsx index 5bddd417c8..05a856832e 100644 --- a/libs/remix-ui/search/src/lib/components/Search.tsx +++ b/libs/remix-ui/search/src/lib/components/Search.tsx @@ -13,7 +13,7 @@ const plugin = props.plugin return ( <> -
    +
    diff --git a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx index 8df5162bbe..45257371e2 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx @@ -1,18 +1,25 @@ -import React from 'react' +import React, { useEffect, useState } from 'react' import { SearchResult } from '../../types' - +import { getPathIcon } from '@remix-ui/helper' interface ResultItemProps { file: SearchResult } export const ResultFileName = (props: ResultItemProps) => { + const [icon, setIcon] = useState('') + + useEffect(() => { + if (props.file && props.file.path) { + setIcon(getPathIcon(props.file.path)) + } + }, [props.file]) + return ( -
    -
    - - {props.file.filename} - + <> + {icon ?
    : null} +
    + {props.file.filename}
    -
    + ) } diff --git a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx index 18b76950f6..7fca1a87ac 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx @@ -17,7 +17,11 @@ export const ResultSummary = (props: ResultSummaryProps) => { const replace = async (line: SearchResultLineLine) => { props.setLoading(true) - await replaceText(props.searchResult, line) + try{ + await replaceText(props.searchResult, line) + }catch(e){ + props.setLoading(false) + } } return ( diff --git a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts index 88ae6b1de1..3daa49f4bf 100644 --- a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts +++ b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts @@ -104,5 +104,8 @@ export const replaceTextInLine = (str: string, searchResultLine: SearchResultLin }).join(getEOL(str)) } +export function escapeRegExp(string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string +} diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index c3f387857c..6ba9ba86c1 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -1,28 +1,38 @@ import React, { useEffect } from 'react' import { createContext, useReducer } from 'react' -import { findLinesInStringWithMatch, getDirectory, replaceTextInLine } from '../components/results/SearchHelper' import { - SearchReducer, -} from '../reducers/Reducer' -import { SearchState, SearchResult, SearchResultLine, SearchResultLineLine, SearchingInitialState } from '../types' + findLinesInStringWithMatch, + getDirectory, + replaceTextInLine +} from '../components/results/SearchHelper' +import { SearchReducer } from '../reducers/Reducer' +import { + SearchState, + SearchResult, + SearchResultLine, + SearchResultLineLine, + SearchingInitialState +} from '../types' import { filePathFilter } from '@jsdevtools/file-path-filter' +import { escapeRegExp } from 'lodash' export interface SearchingStateInterface { state: SearchState setFind: (value: string) => void setReplace: (value: string) => void - setInclude: (value: string) => void, - setExclude: (value: string) => void, - setCaseSensitive: (value: boolean) => void, - setRegex: (value: boolean) => void, - setWholeWord: (value: boolean) => void, - setSearchResults: (value: SearchResult[]) => void, - findText: (path: string) => Promise, - hightLightInPath: (result:SearchResult, line:SearchResultLineLine) => void, - replaceText: (result: SearchResult, line: SearchResultLineLine) => void, - reloadFile: (file:string) => void, - toggleCaseSensitive: () => void, - toggleMatchWholeWord: () => void, + setInclude: (value: string) => void + setExclude: (value: string) => void + setCaseSensitive: (value: boolean) => void + setRegex: (value: boolean) => void + setWholeWord: (value: boolean) => void + setSearchResults: (value: SearchResult[]) => void + findText: (path: string) => Promise + hightLightInPath: (result: SearchResult, line: SearchResultLineLine) => void + replaceText: (result: SearchResult, line: SearchResultLineLine) => void + reloadFile: (file: string) => void + toggleCaseSensitive: () => void + toggleMatchWholeWord: () => void + toggleUseRegex: () => void } export const SearchContext = createContext(null) @@ -86,12 +96,18 @@ export const SearchProvider = ({ payload: value }) }, - reloadFile: async (file:string) => { + reloadFile: async (file: string) => { dispatch({ type: 'RELOAD_FILE', payload: file }) }, + toggleUseRegex: () => { + dispatch({ + type: 'TOGGLE_USE_REGEX', + payload: undefined + }) + }, toggleCaseSensitive: () => { dispatch({ type: 'TOGGLE_CASE_SENSITIVE', @@ -104,29 +120,47 @@ export const SearchProvider = ({ payload: undefined }) }, - findText : async (path: string) => { - if(!plugin) return + findText: async (path: string) => { + if (!plugin) return try { - if(state.find.length < 3) return + if (state.find.length < 3) return const text = await plugin.call('fileManager', 'readFile', path) let flags = 'g' let find = state.find - if(!state.casesensitive) flags += 'i' - if(state.matchWord) find = `\\b${find}\\b` + if (!state.casesensitive) flags += 'i' + if (state.matchWord) find = `\\b${find}\\b` + if (!state.useRegExp) find = escapeRegExp(find) const re = new RegExp(find, flags) const result: SearchResultLine[] = findLinesInStringWithMatch(text, re) return result } catch (e) {} }, - hightLightInPath: async(result: SearchResult, line: SearchResultLineLine) => { + hightLightInPath: async ( + result: SearchResult, + line: SearchResultLineLine + ) => { await plugin.call('editor', 'discardHighlight') await plugin.call('editor', 'highlight', line.position, result.path) }, - replaceText: async(result: SearchResult, line: SearchResultLineLine) => { - await plugin.call('editor', 'discardHighlight') - await plugin.call('editor', 'highlight', line.position, result.path) - const content = await plugin.call('fileManager', 'readFile', result.path) - await plugin.call('fileManager','setFile', result.path, replaceTextInLine(content, line, state.replace)) + replaceText: async (result: SearchResult, line: SearchResultLineLine) => { + try { + await plugin.call('editor', 'discardHighlight') + await plugin.call('editor', 'highlight', line.position, result.path) + const content = await plugin.call( + 'fileManager', + 'readFile', + result.path + ) + + await plugin.call( + 'fileManager', + 'setFile', + result.path, + replaceTextInLine(content, line, state.replace) + ) + } catch (e) { + throw new Error(e) + } } } @@ -173,8 +207,6 @@ export const SearchProvider = ({ } }, [state.timeStamp]) - - return ( <> {children} diff --git a/libs/remix-ui/search/src/lib/reducers/Reducer.ts b/libs/remix-ui/search/src/lib/reducers/Reducer.ts index 907a57b8c8..2738caa95f 100644 --- a/libs/remix-ui/search/src/lib/reducers/Reducer.ts +++ b/libs/remix-ui/search/src/lib/reducers/Reducer.ts @@ -40,6 +40,12 @@ export const SearchReducer = (state: SearchState = SearchingInitialState, action casesensitive: !state.casesensitive, timeStamp: Date.now() } + case 'TOGGLE_USE_REGEX': + return { + ...state, + useRegExp: !state.useRegExp, + timeStamp: Date.now() + } case 'TOGGLE_MATCH_WHOLE_WORD': return { ...state, diff --git a/libs/remix-ui/search/src/lib/search.css b/libs/remix-ui/search/src/lib/search.css index 089cae82ed..4f4dfbd5bb 100644 --- a/libs/remix-ui/search/src/lib/search.css +++ b/libs/remix-ui/search/src/lib/search.css @@ -5,6 +5,7 @@ -ms-user-select: none; /* IE10+/Edge */ user-select: none; /* Standard */ cursor: pointer; + align-items: center; } .wrap_summary { @@ -85,4 +86,10 @@ .search_tab .checked { background-color: var(--secondary); +} + +.search_tab .search_file_name { + text-overflow: ellipsis; + overflow: hidden; + text-transform: uppercase; } \ No newline at end of file diff --git a/libs/remix-ui/search/src/lib/types/index.ts b/libs/remix-ui/search/src/lib/types/index.ts index 7b558085f5..4521bfb658 100644 --- a/libs/remix-ui/search/src/lib/types/index.ts +++ b/libs/remix-ui/search/src/lib/types/index.ts @@ -40,6 +40,7 @@ export interface SearchState { exclude: string, casesensitive: boolean, matchWord: boolean, + useRegExp: boolean, timeStamp: number } @@ -51,5 +52,6 @@ export const SearchingInitialState: SearchState = { searchResults: [], casesensitive: false, matchWord: false, + useRegExp: false, timeStamp: 0 } \ No newline at end of file From 5355f9a8eeb36d546ef550280e991ca53e612a02 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 13:14:02 +0100 Subject: [PATCH 07/35] rm regx from heklper --- libs/remix-ui/search/README.md | 7 ------- .../search/src/lib/components/results/SearchHelper.ts | 3 --- 2 files changed, 10 deletions(-) delete mode 100644 libs/remix-ui/search/README.md diff --git a/libs/remix-ui/search/README.md b/libs/remix-ui/search/README.md deleted file mode 100644 index cf9595a10e..0000000000 --- a/libs/remix-ui/search/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# remix-ui-vertical-icons-panel - -React library for RemixIde vertical icons Panel - -## Running unit tests - -Run `nx test remix-ui-vertical-icons-panel` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts index 3daa49f4bf..88ae6b1de1 100644 --- a/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts +++ b/libs/remix-ui/search/src/lib/components/results/SearchHelper.ts @@ -104,8 +104,5 @@ export const replaceTextInLine = (str: string, searchResultLine: SearchResultLin }).join(getEOL(str)) } -export function escapeRegExp(string) { - return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string -} From ebf5510ca2aeebecdec2e339622b9afb403b87b8 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 13:15:07 +0100 Subject: [PATCH 08/35] Constitution --- apps/remix-ide/contracts/app/ethereum/constitution.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/contracts/app/ethereum/constitution.sol b/apps/remix-ide/contracts/app/ethereum/constitution.sol index ff36bdb9c8..0f60164e97 100644 --- a/apps/remix-ide/contracts/app/ethereum/constitution.sol +++ b/apps/remix-ide/contracts/app/ethereum/constitution.sol @@ -1,4 +1,4 @@ - Constitution { + contract Constitution { function Found(uint8 _numProposals) { proposals.length = _numProposals; From 00557e19f160076aed224335f5cf86deddb21c56 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 13:15:30 +0100 Subject: [PATCH 09/35] white space --- apps/remix-ide/contracts/app/ethereum/constitution.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/contracts/app/ethereum/constitution.sol b/apps/remix-ide/contracts/app/ethereum/constitution.sol index 0f60164e97..8c2c9e0da9 100644 --- a/apps/remix-ide/contracts/app/ethereum/constitution.sol +++ b/apps/remix-ide/contracts/app/ethereum/constitution.sol @@ -1,4 +1,4 @@ - contract Constitution { +contract Constitution { function Found(uint8 _numProposals) { proposals.length = _numProposals; From 35ac6dddb94e6eb7b2fbccf3894b738fb42366c3 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 13:19:46 +0100 Subject: [PATCH 10/35] fix timeouts --- libs/remix-ui/search/src/lib/components/Exclude.tsx | 5 +++-- libs/remix-ui/search/src/lib/components/Include.tsx | 5 +++-- libs/remix-ui/search/src/lib/components/Replace.tsx | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libs/remix-ui/search/src/lib/components/Exclude.tsx b/libs/remix-ui/search/src/lib/components/Exclude.tsx index c836183157..c6bdef48e2 100644 --- a/libs/remix-ui/search/src/lib/components/Exclude.tsx +++ b/libs/remix-ui/search/src/lib/components/Exclude.tsx @@ -4,10 +4,11 @@ import { SearchContext } from '../context/context' export const Exclude = props => { const { setExclude, state } = useContext(SearchContext) const [str, setStr] = useState('.git/**/*,.deps/**/*') + let timeOutId: any = null const change = e => { setStr(e.target.value) - const timeOutId = setTimeout(() => setExclude(e.target.value), 500) - return () => clearTimeout(timeOutId) + clearTimeout(timeOutId) + timeOutId = setTimeout(() => setExclude(e.target.value), 500) } useEffect(() => { diff --git a/libs/remix-ui/search/src/lib/components/Include.tsx b/libs/remix-ui/search/src/lib/components/Include.tsx index a59dd11988..00bf266deb 100644 --- a/libs/remix-ui/search/src/lib/components/Include.tsx +++ b/libs/remix-ui/search/src/lib/components/Include.tsx @@ -3,9 +3,10 @@ import { SearchContext } from '../context/context' export const Include = props => { const { setInclude } = useContext(SearchContext) + let timeOutId: any = null const change = e => { - const timeOutId = setTimeout(() => setInclude(e.target.value), 500) - return () => clearTimeout(timeOutId) + clearTimeout(timeOutId) + timeOutId = setTimeout(() => setInclude(e.target.value), 500) } return ( diff --git a/libs/remix-ui/search/src/lib/components/Replace.tsx b/libs/remix-ui/search/src/lib/components/Replace.tsx index 504261cfa9..33b9ba2539 100644 --- a/libs/remix-ui/search/src/lib/components/Replace.tsx +++ b/libs/remix-ui/search/src/lib/components/Replace.tsx @@ -3,9 +3,10 @@ import { SearchContext } from '../context/context' export const Replace = props => { const { setReplace } = useContext(SearchContext) + let timeOutId: any = null const change = e => { - const timeOutId = setTimeout(() => setReplace(e.target.value), 500) - return () => clearTimeout(timeOutId) + clearTimeout(timeOutId) + timeOutId = setTimeout(() => setReplace(e.target.value), 500) } return ( From 7e309057774f48c0c361c12d3cb5314c00c6bb85 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 13:23:30 +0100 Subject: [PATCH 11/35] move icon --- apps/remix-ide/src/app/components/vertical-icons.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/components/vertical-icons.tsx b/apps/remix-ide/src/app/components/vertical-icons.tsx index bc70fd812c..d8fe5706f8 100644 --- a/apps/remix-ide/src/app/components/vertical-icons.tsx +++ b/apps/remix-ide/src/app/components/vertical-icons.tsx @@ -29,7 +29,7 @@ export class VerticalIcons extends Plugin { } renderComponent () { - const fixedOrder = ['filePanel', 'solidity','udapp', 'debugger', 'solidityStaticAnalysis', 'solidityUnitTesting', 'pluginManager'] + const fixedOrder = ['filePanel', 'search', 'solidity','udapp', 'debugger', 'solidityStaticAnalysis', 'solidityUnitTesting', 'pluginManager'] const divived = Object.values(this.icons).map((value) => { return { ...value, From 70919be2e89b886f87047af3ccc97ba380874ff7 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 13:44:07 +0100 Subject: [PATCH 12/35] rm un --- .../search/src/lib/components/results/Results.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libs/remix-ui/search/src/lib/components/results/Results.tsx b/libs/remix-ui/search/src/lib/components/results/Results.tsx index 810b2351fd..f398a43143 100644 --- a/libs/remix-ui/search/src/lib/components/results/Results.tsx +++ b/libs/remix-ui/search/src/lib/components/results/Results.tsx @@ -3,16 +3,10 @@ import { SearchContext } from '../../context/context' import { ResultItem } from './ResultItem' export const Results = () => { - const { state} = useContext(SearchContext) - const [alertText, setAlertText] = useState('') + const { state } = useContext(SearchContext) return ( <> - {alertText ? ( -
    - {alertText} -
    - ) : null} {state.searchResults && state.searchResults.map((result, index) => { return From 73ed0d81bf0e45db5d1042057894cd6bd18a5350 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 13:56:43 +0100 Subject: [PATCH 13/35] clean up --- libs/remix-ui/search/src/lib/components/results/Results.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/search/src/lib/components/results/Results.tsx b/libs/remix-ui/search/src/lib/components/results/Results.tsx index f398a43143..abb8d8ac1b 100644 --- a/libs/remix-ui/search/src/lib/components/results/Results.tsx +++ b/libs/remix-ui/search/src/lib/components/results/Results.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from 'react' +import React, { useContext } from 'react' import { SearchContext } from '../../context/context' import { ResultItem } from './ResultItem' From 0806aea4b18ecec73834b8f933c504a625d01c4f Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 14:01:19 +0100 Subject: [PATCH 14/35] required --- apps/remix-ide/src/remixAppManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/remixAppManager.js b/apps/remix-ide/src/remixAppManager.js index ce7ea97b27..7598190e3f 100644 --- a/apps/remix-ide/src/remixAppManager.js +++ b/apps/remix-ide/src/remixAppManager.js @@ -7,7 +7,7 @@ const _paq = window._paq = window._paq || [] const requiredModules = [ // services + layout views + system views 'manager', 'config', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme', 'fileManager', 'contentImport', 'blockchain', 'web3Provider', 'scriptRunner', 'fetchAndCompile', 'mainPanel', 'hiddenPanel', 'sidePanel', 'menuicons', - 'filePanel', 'terminal', 'settings', 'pluginManager', 'tabs', 'udapp', 'dGitProvider', 'solidity-logic', 'gistHandler', 'layout', 'notification', 'permissionhandler', 'walkthrough', 'storage'] + 'filePanel', 'terminal', 'settings', 'pluginManager', 'tabs', 'udapp', 'dGitProvider', 'solidity-logic', 'gistHandler', 'layout', 'notification', 'permissionhandler', 'walkthrough', 'storage', 'search'] const dependentModules = ['git', 'hardhat', 'slither'] // module which shouldn't be manually activated (e.g git is activated by remixd) From 21b7036447a5b9b93830d18d297436ef305cf117 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 14:02:36 +0100 Subject: [PATCH 15/35] cleanup --- apps/remix-ide/src/app/tabs/search.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/search.tsx b/apps/remix-ide/src/app/tabs/search.tsx index 267396181a..6914ed0150 100644 --- a/apps/remix-ide/src/app/tabs/search.tsx +++ b/apps/remix-ide/src/app/tabs/search.tsx @@ -1,7 +1,6 @@ import { ViewPlugin } from '@remixproject/engine-web' import * as packageJson from '../../../../../package.json' import React from 'react' // eslint-disable-line -import { PluginViewWrapper } from '@remix-ui/helper' import { SearchTab } from '@remix-ui/search' const profile = { name: 'search', @@ -17,12 +16,11 @@ const profile = { } export class SearchPlugin extends ViewPlugin { - dispatch: React.Dispatch = () => {} + constructor () { super(profile) } - render() { return (
    From 6147ef036919bda06ed3a95120b0d5cdccad593f Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 18:11:08 +0100 Subject: [PATCH 16/35] e2e --- apps/remix-ide-e2e/src/tests/search.test.ts | 103 ++++++++++++++++++ .../search/src/lib/components/Exclude.tsx | 1 + .../search/src/lib/components/Find.tsx | 4 + .../search/src/lib/components/Include.tsx | 6 +- .../search/src/lib/components/Replace.tsx | 1 + .../lib/components/results/ResultSummary.tsx | 4 +- .../src/lib/components/results/Results.tsx | 4 +- .../search/src/lib/context/context.tsx | 2 +- package.json | 3 +- 9 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 apps/remix-ide-e2e/src/tests/search.test.ts diff --git a/apps/remix-ide-e2e/src/tests/search.test.ts b/apps/remix-ide-e2e/src/tests/search.test.ts new file mode 100644 index 0000000000..626778851d --- /dev/null +++ b/apps/remix-ide-e2e/src/tests/search.test.ts @@ -0,0 +1,103 @@ +'use strict' + +import { NightwatchBrowser } from 'nightwatch' +import init from '../helpers/init' + +module.exports = { + + before: function (browser: NightwatchBrowser, done: VoidFunction) { + init(browser, done, 'http://127.0.0.1:8080', true) + }, + 'Should find text': function (browser: NightwatchBrowser) { + browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]') + .click('*[plugin="search"]').waitForElementVisible('*[id="search_input"]') + .setValue('*[id="search_input"]', 'read').pause(1000) + .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/3_BALLOT.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'README.TXT', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'file must') + .waitForElementContainsText('*[data-id="search_results"]', 'be compiled') + .waitForElementContainsText('*[data-id="search_results"]', 'that person al') + .waitForElementContainsText('*[data-id="search_results"]', 'sender.voted') + .waitForElementContainsText('*[data-id="search_results"]', 'read') + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 6) + }) + }, + 'Should find regex': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="search_use_regex"]').click('*[data-id="search_use_regex"]') + .waitForElementVisible('*[id="search_input"]') + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', '^contract').pause(1000) + .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/3_BALLOT.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/2_OWNER.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/1_STORAGE.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'TESTS/4_BALLOT_TEST.SOL', 60000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 4) + }) + }, + 'Should find matchcase': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="search_use_regex"]').click('*[data-id="search_use_regex"]') + .waitForElementVisible('*[data-id="search_case_sensitive"]').click('*[data-id="search_case_sensitive"]') + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 0) + }) + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'Contract').pause(1000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 6) + }) + .waitForElementContainsText('*[data-id="search_results"]', 'SCRIPTS/DEPLOY_ETHERS.JS', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'SCRIPTS/DEPLOY_WEB3.JS', 60000) + }, + 'Should find matchword': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="search_case_sensitive"]').click('*[data-id="search_case_sensitive"]') + .waitForElementVisible('*[data-id="search_whole_word"]').click('*[data-id="search_whole_word"]') + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'contract').pause(1000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 27) + }) + }, + 'Should replace text': function (browser: NightwatchBrowser) { + browser + .setValue('*[id="search_replace"]', 'replacing').pause(1000) + .waitForElementVisible('*[data-id="contracts/2_Owner.sol-30-71"]') + .moveToElement('*[data-id="contracts/2_Owner.sol-30-71"]', 10, 10) + .waitForElementVisible('*[data-id="replace-contracts/2_Owner.sol-30-71"]') + .click('*[data-id="replace-contracts/2_Owner.sol-30-71"]').pause(2000). + getEditorValue((content) => { + browser.assert.ok(content.includes('replacing deployer for a constructor'), 'should replace text ok') + }) + }, + 'Should find text with include': function (browser: NightwatchBrowser) { + browser + .setValue('*[id="search_include"]', 'contracts/**').pause(2000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 4) + }) + }, + 'Should find text with exclude': function (browser: NightwatchBrowser) { + browser + .clearValue('*[id="search_include"]').pause(2000) + .setValue('*[id="search_include"]', '**').pause(2000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 26) + }) + .setValue('*[id="search_exclude"]', ',contracts/**').pause(2000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 22) + }) + }, + 'should clear search': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[id="search_input"]') + .setValue('*[id="search_input"]', 'nodata').pause(1000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 0) + }) + } +} \ No newline at end of file diff --git a/libs/remix-ui/search/src/lib/components/Exclude.tsx b/libs/remix-ui/search/src/lib/components/Exclude.tsx index c6bdef48e2..4de9a0f30a 100644 --- a/libs/remix-ui/search/src/lib/components/Exclude.tsx +++ b/libs/remix-ui/search/src/lib/components/Exclude.tsx @@ -20,6 +20,7 @@ export const Exclude = props => {
    {
    { }} >
    { }} >
    { const { setInclude } = useContext(SearchContext) + const [str, setStr] = useState('') let timeOutId: any = null const change = e => { + setStr(e.target.value) clearTimeout(timeOutId) timeOutId = setTimeout(() => setInclude(e.target.value), 500) } @@ -14,9 +16,11 @@ export const Include = props => {
    diff --git a/libs/remix-ui/search/src/lib/components/Replace.tsx b/libs/remix-ui/search/src/lib/components/Replace.tsx index 33b9ba2539..a6ecf39887 100644 --- a/libs/remix-ui/search/src/lib/components/Replace.tsx +++ b/libs/remix-ui/search/src/lib/components/Replace.tsx @@ -14,6 +14,7 @@ export const Replace = props => {
    { const { hightLightInPath, replaceText, state } = useContext(SearchContext) - const selectLine = async (line: SearchResultLineLine) => { await hightLightInPath(props.searchResult, line) } @@ -32,6 +31,7 @@ export const ResultSummary = (props: ResultSummaryProps) => { onClick={async () => { selectLine(lineItem) }} + data-id={`${props.searchResult.filename}-${lineItem.position.start.line}-${lineItem.position.start.column}`} key={props.searchResult.filename} className='search_line pb-1' > @@ -41,7 +41,7 @@ export const ResultSummary = (props: ResultSummaryProps) => {
    {lineItem.right.substring(0, 100)}
    -
    { +
    { replace(lineItem) }} className="codicon codicon-find-replace" role="button" aria-label="Replace" aria-disabled="false">
    diff --git a/libs/remix-ui/search/src/lib/components/results/Results.tsx b/libs/remix-ui/search/src/lib/components/results/Results.tsx index abb8d8ac1b..9a1b717cca 100644 --- a/libs/remix-ui/search/src/lib/components/results/Results.tsx +++ b/libs/remix-ui/search/src/lib/components/results/Results.tsx @@ -6,11 +6,11 @@ export const Results = () => { const { state } = useContext(SearchContext) return ( - <> +
    {state.searchResults && state.searchResults.map((result, index) => { return })} - +
    ) } diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index 6ba9ba86c1..7ae00dc66e 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -128,8 +128,8 @@ export const SearchProvider = ({ let flags = 'g' let find = state.find if (!state.casesensitive) flags += 'i' - if (state.matchWord) find = `\\b${find}\\b` if (!state.useRegExp) find = escapeRegExp(find) + if (state.matchWord) find = `\\b${find}\\b` const re = new RegExp(find, flags) const result: SearchResultLine[] = findLinesInStringWithMatch(text, re) return result diff --git a/package.json b/package.json index a38866094a..6abfafa406 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "workspace-schematic": "nx workspace-schematic", "dep-graph": "nx dep-graph", "help": "nx help", - "lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd,remix-ui-tree-view,remix-ui-modal-dialog,remix-ui-toaster,remix-ui-helper,remix-ui-debugger-ui,remix-ui-workspace,remix-ui-static-analyser,remix-ui-checkbox,remix-ui-settings,remix-core-plugin,remix-ui-renderer,remix-ui-publish-to-storage,remix-ui-solidity-compiler,solidity-unit-testing,remix-ui-plugin-manager,remix-ui-terminal,remix-ui-editor,remix-ui-app,remix-ui-tabs,remix-ui-panel,remix-ui-run-tab,remix-ui-permission-handler", + "lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd,remix-ui-tree-view,remix-ui-modal-dialog,remix-ui-toaster,remix-ui-helper,remix-ui-debugger-ui,remix-ui-workspace,remix-ui-static-analyser,remix-ui-checkbox,remix-ui-settings,remix-core-plugin,remix-ui-renderer,remix-ui-publish-to-storage,remix-ui-solidity-compiler,solidity-unit-testing,remix-ui-plugin-manager,remix-ui-terminal,remix-ui-editor,remix-ui-app,remix-ui-tabs,remix-ui-panel,remix-ui-run-tab,remix-ui-permission-handler,remix-ui-search", "build:libs": "nx run-many --target=build --parallel=false --with-deps=true --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd", "test:libs": "nx run-many --target=test --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd", "publish:libs": "npm run build:libs && lerna publish --skip-git && npm run bumpVersion:libs", @@ -97,6 +97,7 @@ "nightwatch_local_pluginApi": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/plugin_api_*.js --env=chrome", "nightwatch_local_migrate_filesystem": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/migrateFileSystem.test.js --env=chrome", "nightwatch_local_stress_editor": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/stress.editor.js --env=chromeDesktop", + "nightwatch_local_search": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/search.test.js --env=chromeDesktop", "onchange": "onchange apps/remix-ide/build/app.js -- npm-run-all lint", "remixd": "nx build remixd && chmod +x dist/libs/remixd/src/bin/remixd.js && dist/libs/remixd/src/bin/remixd.js -s ./apps/remix-ide/contracts --remix-ide http://127.0.0.1:8080", "selenium": "selenium-standalone start", From 1ecc4fc2b88818aefcca289caef5353699e90f7f Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 18:12:00 +0100 Subject: [PATCH 17/35] master package --- package-lock.json | 70 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/package-lock.json b/package-lock.json index c72f9cbe60..18feb9d161 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9782,46 +9782,46 @@ "integrity": "sha512-IXf3XA7+XyN7CP9gGh/XB0UxVMlvARGEgGXLubFICsUMGz6Q+DU+i4gGlpOxTjKvXjkJDJC8YdqdKkDj9qZHEQ==" }, "@remixproject/engine": { - "version": "0.3.28", - "resolved": "https://registry.npmjs.org/@remixproject/engine/-/engine-0.3.28.tgz", - "integrity": "sha512-27SHaCrG3KrPfMa1MYud4tE9xUIJKITEUsql99fhN7x12lOmgGZFjiqIG/WWjCMmT7OMG3vtLayiZrsYkzHCVw==", + "version": "0.3.26", + "resolved": "https://registry.npmjs.org/@remixproject/engine/-/engine-0.3.26.tgz", + "integrity": "sha512-6Rq6aTUyhtXAaoQamAI8ocFSVy2txpGwu1aoYZGrqova/p/tRWn4/+PU713sffyiAQVBCk7C1z/5VKLm7tUYrQ==", "requires": { - "@remixproject/plugin-api": "0.3.28", - "@remixproject/plugin-utils": "0.3.28" + "@remixproject/plugin-api": "0.3.26", + "@remixproject/plugin-utils": "0.3.26" } }, "@remixproject/engine-web": { - "version": "0.3.28", - "resolved": "https://registry.npmjs.org/@remixproject/engine-web/-/engine-web-0.3.28.tgz", - "integrity": "sha512-JTwTuonW+pI7WsSsgGHAzPynGjIdG34VnPrspR9XKBQO4+NX7m3lbNIMUUviyrbqIoGiGtgYd/ry98uLpTHr4g==", + "version": "0.3.26", + "resolved": "https://registry.npmjs.org/@remixproject/engine-web/-/engine-web-0.3.26.tgz", + "integrity": "sha512-QSW9KVOgHWuRDNqTZIp1jjBeDOXlXQZWYABgljTsC+Nig8EwlyRTfIza9PuCb+MDYT/kID8VgSPXnMrlOtvhjQ==", "requires": { - "@remixproject/engine": "0.3.28", - "@remixproject/plugin-api": "0.3.28", - "@remixproject/plugin-utils": "0.3.28" + "@remixproject/engine": "0.3.26", + "@remixproject/plugin-api": "0.3.26", + "@remixproject/plugin-utils": "0.3.26" } }, "@remixproject/plugin": { - "version": "0.3.28", - "resolved": "https://registry.npmjs.org/@remixproject/plugin/-/plugin-0.3.28.tgz", - "integrity": "sha512-sw+cow3GKAcEacXLvdJwtHHIphPty4KRMZ6tcQHdtx/iCKTMNdw2hribKPnvTO+6mXE+4oAKCrFqeTdVp/rd1w==", + "version": "0.3.26", + "resolved": "https://registry.npmjs.org/@remixproject/plugin/-/plugin-0.3.26.tgz", + "integrity": "sha512-j0sgl4yDOVJLCuRWOEb/Wo9/fumrWlIpsO0MrtficuhVc1FGhZxKVv8Vdu3x3HgWhXkuhLUMs8VoJ1Ntd9ZkUQ==", "requires": { - "@remixproject/plugin-api": "0.3.28", - "@remixproject/plugin-utils": "0.3.28", + "@remixproject/plugin-api": "0.3.26", + "@remixproject/plugin-utils": "0.3.26", "events": "3.2.0" } }, "@remixproject/plugin-api": { - "version": "0.3.28", - "resolved": "https://registry.npmjs.org/@remixproject/plugin-api/-/plugin-api-0.3.28.tgz", - "integrity": "sha512-tOzVFR504037weEkNHQGZsk+Ebxcu/xnBsVCkJaQaBMb+H/i6YevKQmoR1aGcH+JfQxc8eS8LGC65MaV8zmcWg==", + "version": "0.3.26", + "resolved": "https://registry.npmjs.org/@remixproject/plugin-api/-/plugin-api-0.3.26.tgz", + "integrity": "sha512-6vR9nVF4EfXDHA0r8MrlLyVYRMJMG7J3Y3jzpaAumetW+YpvfJqgE/uhGgm2me2ypDM8vW0POQGhRaGeZTGwFg==", "requires": { - "@remixproject/plugin-utils": "0.3.28" + "@remixproject/plugin-utils": "0.3.26" } }, "@remixproject/plugin-utils": { - "version": "0.3.28", - "resolved": "https://registry.npmjs.org/@remixproject/plugin-utils/-/plugin-utils-0.3.28.tgz", - "integrity": "sha512-5CayTgMqRiOguanTy6kpuRgCmjEFLUu2K4Rs7Zmt+GOzHucmwkDxYQO+3hFv0Jz/M/6yC5wkKYTx8vfPLLdEBQ==", + "version": "0.3.26", + "resolved": "https://registry.npmjs.org/@remixproject/plugin-utils/-/plugin-utils-0.3.26.tgz", + "integrity": "sha512-K/v+TXYOMV13dLf1LEgiF7CfqbOc105hC/2oapkSoHKSf3WVyWIUDlBsChRQl7osfUs/zT93q2+jNlLofWQUxg==", "requires": { "tslib": "2.0.1" }, @@ -9834,13 +9834,13 @@ } }, "@remixproject/plugin-webview": { - "version": "0.3.28", - "resolved": "https://registry.npmjs.org/@remixproject/plugin-webview/-/plugin-webview-0.3.28.tgz", - "integrity": "sha512-DodSkN0vMSo2DEEoBOWyKxC/ElvBA826vhX+JVGXA8HGS45aavplZIN967hsc+SdzjV1UZfSNKEHttLGwM1BIw==", + "version": "0.3.26", + "resolved": "https://registry.npmjs.org/@remixproject/plugin-webview/-/plugin-webview-0.3.26.tgz", + "integrity": "sha512-hqWaFapUfcAX2Odsj0ANKvLXQbkzZ/xNONMqE0wRxFRYTIhFGZqFzJVzwSD+U4bSehP1JtzkrxwKBqNyjz5GxQ==", "requires": { - "@remixproject/plugin": "0.3.28", - "@remixproject/plugin-api": "0.3.28", - "@remixproject/plugin-utils": "0.3.28", + "@remixproject/plugin": "0.3.26", + "@remixproject/plugin-api": "0.3.26", + "@remixproject/plugin-utils": "0.3.26", "axios": "^0.21.1" }, "dependencies": { @@ -9855,13 +9855,13 @@ } }, "@remixproject/plugin-ws": { - "version": "0.3.28", - "resolved": "https://registry.npmjs.org/@remixproject/plugin-ws/-/plugin-ws-0.3.28.tgz", - "integrity": "sha512-i3He9t4qvcBQxzshFx66D6drqLlySmV7Cb+NeYtMOYlWxQSJtUakp/Px1Tl3IDFQXDfpXxvDvYhn2w0AWPBOqw==", + "version": "0.3.26", + "resolved": "https://registry.npmjs.org/@remixproject/plugin-ws/-/plugin-ws-0.3.26.tgz", + "integrity": "sha512-Nerd/2vGb96G6B8pGRCRNAGlO97KnJpbFmpa47SYipgjaq5Yj5iCUY+fbQzMWdGW2W4BrUPE+YBZCkq/KlfbGw==", "requires": { - "@remixproject/plugin": "0.3.28", - "@remixproject/plugin-api": "0.3.28", - "@remixproject/plugin-utils": "0.3.28" + "@remixproject/plugin": "0.3.26", + "@remixproject/plugin-api": "0.3.26", + "@remixproject/plugin-utils": "0.3.26" } }, "@restart/context": { From 00fbf04214050a855a337f4554cd2bf868010daa Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 18:17:57 +0100 Subject: [PATCH 18/35] fix --- libs/remix-ui/search/src/lib/components/Exclude.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/search/src/lib/components/Exclude.tsx b/libs/remix-ui/search/src/lib/components/Exclude.tsx index 4de9a0f30a..962a9cefaf 100644 --- a/libs/remix-ui/search/src/lib/components/Exclude.tsx +++ b/libs/remix-ui/search/src/lib/components/Exclude.tsx @@ -12,7 +12,7 @@ export const Exclude = props => { } useEffect(() => { - setExclude('.git/**') + setExclude(str) }, []) return ( From 3631fbbe4a99fb2730419e4826e9e91a9cd94dfb Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 18:25:34 +0100 Subject: [PATCH 19/35] show title --- .../search/src/lib/components/results/ResultFileName.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx index 45257371e2..60c950e457 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx @@ -17,7 +17,7 @@ export const ResultFileName = (props: ResultItemProps) => { return ( <> {icon ?
    : null} -
    +
    {props.file.filename}
    From de42bcbc97ea64582b0d91a0cd57497f24fb9437 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 18:44:21 +0100 Subject: [PATCH 20/35] path filename --- apps/remix-ide-e2e/src/tests/search.test.ts | 17 ++++++++++------- .../lib/components/results/ResultFileName.tsx | 6 +++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/search.test.ts b/apps/remix-ide-e2e/src/tests/search.test.ts index 626778851d..cfcbe506af 100644 --- a/apps/remix-ide-e2e/src/tests/search.test.ts +++ b/apps/remix-ide-e2e/src/tests/search.test.ts @@ -12,7 +12,8 @@ module.exports = { browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]') .click('*[plugin="search"]').waitForElementVisible('*[id="search_input"]') .setValue('*[id="search_input"]', 'read').pause(1000) - .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/3_BALLOT.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', '3_BALLOT.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'contracts', 60000) .waitForElementContainsText('*[data-id="search_results"]', 'README.TXT', 60000) .waitForElementContainsText('*[data-id="search_results"]', 'file must') .waitForElementContainsText('*[data-id="search_results"]', 'be compiled') @@ -29,10 +30,11 @@ module.exports = { .waitForElementVisible('*[id="search_input"]') .clearValue('*[id="search_input"]') .setValue('*[id="search_input"]', '^contract').pause(1000) - .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/3_BALLOT.SOL', 60000) - .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/2_OWNER.SOL', 60000) - .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/1_STORAGE.SOL', 60000) - .waitForElementContainsText('*[data-id="search_results"]', 'TESTS/4_BALLOT_TEST.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', '3_BALLOT.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', '2_OWNER.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', '1_STORAGE.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', '4_BALLOT_TEST.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'tests', 60000) .elements('css selector','.search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 4) }) @@ -49,8 +51,9 @@ module.exports = { .elements('css selector','.search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 6) }) - .waitForElementContainsText('*[data-id="search_results"]', 'SCRIPTS/DEPLOY_ETHERS.JS', 60000) - .waitForElementContainsText('*[data-id="search_results"]', 'SCRIPTS/DEPLOY_WEB3.JS', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'DEPLOY_ETHERS.JS', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'DEPLOY_WEB3.JS', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'scripts', 60000) }, 'Should find matchword': function (browser: NightwatchBrowser) { browser diff --git a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx index 60c950e457..d4cf2e4304 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState } from 'react' import { SearchResult } from '../../types' import { getPathIcon } from '@remix-ui/helper' +import * as path from 'path' interface ResultItemProps { file: SearchResult } @@ -12,13 +13,16 @@ export const ResultFileName = (props: ResultItemProps) => { if (props.file && props.file.path) { setIcon(getPathIcon(props.file.path)) } + // remove path from string + // const path = props.file.path.split('/').slice(0, -1).join('/') }, [props.file]) return ( <> {icon ?
    : null}
    - {props.file.filename} + {path.basename(props.file.path)} + {path.dirname(props.file.path)}
    ) From 6bc2c5523e3988a390d17f0d7c4356241d037738 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 18:59:26 +0100 Subject: [PATCH 21/35] use refs --- libs/remix-ui/search/src/lib/components/Exclude.tsx | 8 ++++---- libs/remix-ui/search/src/lib/components/Find.tsx | 8 ++++---- libs/remix-ui/search/src/lib/components/Include.tsx | 8 ++++---- libs/remix-ui/search/src/lib/components/Replace.tsx | 8 ++++---- libs/remix-ui/search/src/lib/context/context.tsx | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/libs/remix-ui/search/src/lib/components/Exclude.tsx b/libs/remix-ui/search/src/lib/components/Exclude.tsx index 962a9cefaf..be6f0054fb 100644 --- a/libs/remix-ui/search/src/lib/components/Exclude.tsx +++ b/libs/remix-ui/search/src/lib/components/Exclude.tsx @@ -1,14 +1,14 @@ -import React, { useContext, useEffect, useState } from 'react' +import React, { useContext, useEffect, useRef, useState } from 'react' import { SearchContext } from '../context/context' export const Exclude = props => { const { setExclude, state } = useContext(SearchContext) const [str, setStr] = useState('.git/**/*,.deps/**/*') - let timeOutId: any = null + const timeOutId = useRef(null) const change = e => { setStr(e.target.value) - clearTimeout(timeOutId) - timeOutId = setTimeout(() => setExclude(e.target.value), 500) + clearTimeout(timeOutId.current) + timeOutId.current = setTimeout(() => setExclude(e.target.value), 500) } useEffect(() => { diff --git a/libs/remix-ui/search/src/lib/components/Find.tsx b/libs/remix-ui/search/src/lib/components/Find.tsx index f83cf9c797..d89f797f51 100644 --- a/libs/remix-ui/search/src/lib/components/Find.tsx +++ b/libs/remix-ui/search/src/lib/components/Find.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from 'react' +import React, { useContext, useRef } from 'react' import { SearchContext } from '../context/context' export const Find = props => { @@ -9,10 +9,10 @@ export const Find = props => { toggleMatchWholeWord, toggleUseRegex } = useContext(SearchContext) - let timeOutId: any = null + const timeOutId = useRef(null) const change = e => { - clearTimeout(timeOutId) - timeOutId = setTimeout(() => setFind(e.target.value), 500) + clearTimeout(timeOutId.current) + timeOutId.current = setTimeout(() => setFind(e.target.value), 500) } return ( diff --git a/libs/remix-ui/search/src/lib/components/Include.tsx b/libs/remix-ui/search/src/lib/components/Include.tsx index da3096b4ce..8ade1c963a 100644 --- a/libs/remix-ui/search/src/lib/components/Include.tsx +++ b/libs/remix-ui/search/src/lib/components/Include.tsx @@ -1,14 +1,14 @@ -import React, { useContext, useState } from 'react' +import React, { useContext, useRef, useState } from 'react' import { SearchContext } from '../context/context' export const Include = props => { const { setInclude } = useContext(SearchContext) const [str, setStr] = useState('') - let timeOutId: any = null + const timeOutId = useRef(null) const change = e => { setStr(e.target.value) - clearTimeout(timeOutId) - timeOutId = setTimeout(() => setInclude(e.target.value), 500) + clearTimeout(timeOutId.current) + timeOutId.current = setTimeout(() => setInclude(e.target.value), 500) } return ( diff --git a/libs/remix-ui/search/src/lib/components/Replace.tsx b/libs/remix-ui/search/src/lib/components/Replace.tsx index a6ecf39887..50ddd4e436 100644 --- a/libs/remix-ui/search/src/lib/components/Replace.tsx +++ b/libs/remix-ui/search/src/lib/components/Replace.tsx @@ -1,12 +1,12 @@ -import React, { useContext } from 'react' +import React, { useContext, useRef } from 'react' import { SearchContext } from '../context/context' export const Replace = props => { const { setReplace } = useContext(SearchContext) - let timeOutId: any = null + const timeOutId = useRef(null) const change = e => { - clearTimeout(timeOutId) - timeOutId = setTimeout(() => setReplace(e.target.value), 500) + clearTimeout(timeOutId.current) + timeOutId.current = setTimeout(() => setReplace(e.target.value), 500) } return ( diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index 7ae00dc66e..7d5b13c71e 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react' +import React, { useEffect, useRef } from 'react' import { createContext, useReducer } from 'react' import { findLinesInStringWithMatch, @@ -44,8 +44,8 @@ export const SearchProvider = ({ plugin = undefined } = {}) => { const [state, dispatch] = useReducer(reducer, initialState) - let reloadTimeOut: any = null + const reloadTimeOut = useRef(null) const value = { state, setFind: (value: string) => { @@ -165,8 +165,8 @@ export const SearchProvider = ({ } const reloadStateForFile = async (file: string) => { - clearTimeout(reloadTimeOut) - reloadTimeOut = setTimeout(async () => { + clearTimeout(reloadTimeOut.current) + reloadTimeOut.current = setTimeout(async () => { await value.reloadFile(file) }, 1000) } From 3e512e0e49e5a3d5f741ef42d9ebf8c67046de06 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Mon, 21 Feb 2022 19:18:38 +0100 Subject: [PATCH 22/35] Update ResultFileName.tsx --- .../search/src/lib/components/results/ResultFileName.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx index d4cf2e4304..5d6412af25 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx @@ -13,8 +13,6 @@ export const ResultFileName = (props: ResultItemProps) => { if (props.file && props.file.path) { setIcon(getPathIcon(props.file.path)) } - // remove path from string - // const path = props.file.path.split('/').slice(0, -1).join('/') }, [props.file]) return ( From b9b5d4c6d124468a3490beafa946228accb89342 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 22 Feb 2022 09:23:52 +0100 Subject: [PATCH 23/35] replace without confirming --- .../components/modals/modal-wrapper.tsx | 4 ++- .../src/lib/remix-app/context/provider.tsx | 10 +++--- .../app/src/lib/remix-app/interface/index.ts | 3 +- .../app/src/lib/remix-app/reducer/modals.ts | 3 +- .../modal-dialog/src/lib/types/index.ts | 3 +- .../src/lib/components/OverWriteCheck.tsx | 33 +++++++++++++++++++ .../search/src/lib/components/Search.tsx | 2 ++ .../src/lib/components/results/ResultItem.tsx | 13 ++++++-- .../lib/components/results/ResultSummary.tsx | 12 ++++++- .../search/src/lib/context/context.tsx | 25 +++++++++++--- .../search/src/lib/reducers/Reducer.ts | 17 ++++++++-- libs/remix-ui/search/src/lib/types/index.ts | 7 ++-- 12 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 libs/remix-ui/search/src/lib/components/OverWriteCheck.tsx diff --git a/libs/remix-ui/app/src/lib/remix-app/components/modals/modal-wrapper.tsx b/libs/remix-ui/app/src/lib/remix-app/components/modals/modal-wrapper.tsx index cf5456dc38..12644f5fa7 100644 --- a/libs/remix-ui/app/src/lib/remix-app/components/modals/modal-wrapper.tsx +++ b/libs/remix-ui/app/src/lib/remix-app/components/modals/modal-wrapper.tsx @@ -10,6 +10,7 @@ interface ModalWrapperProps extends ModalDialogProps { const ModalWrapper = (props: ModalWrapperProps) => { const [state, setState] = useState() const ref = useRef() + const data = useRef() const onFinishPrompt = async () => { if (ref.current === undefined) { @@ -21,7 +22,7 @@ const ModalWrapper = (props: ModalWrapperProps) => { } const onOkFn = async () => { - (props.okFn) ? props.okFn() : props.resolve(true) + (props.okFn) ? props.okFn(data.current) : props.resolve(data.current || true) } const onCancelFn = async () => { @@ -37,6 +38,7 @@ const ModalWrapper = (props: ModalWrapperProps) => { } useEffect(() => { + data.current = props.data if (props.modalType) { switch (props.modalType) { case ModalTypes.prompt: diff --git a/libs/remix-ui/app/src/lib/remix-app/context/provider.tsx b/libs/remix-ui/app/src/lib/remix-app/context/provider.tsx index 5d9a3a5815..2aca27c1be 100644 --- a/libs/remix-ui/app/src/lib/remix-app/context/provider.tsx +++ b/libs/remix-ui/app/src/lib/remix-app/context/provider.tsx @@ -15,18 +15,18 @@ export const ModalProvider = ({ children = [], reducer = modalReducer, initialSt }) } - const modal = (data: AppModal) => { - const { id, title, message, okLabel, okFn, cancelLabel, cancelFn, modalType, defaultValue, hideFn } = data + const modal = (modalData: AppModal) => { + const { id, title, message, okLabel, okFn, cancelLabel, cancelFn, modalType, defaultValue, hideFn, data } = modalData return new Promise((resolve, reject) => { dispatch({ type: modalActionTypes.setModal, - payload: { id, title, message, okLabel, okFn, cancelLabel, cancelFn, modalType: modalType || ModalTypes.default, defaultValue: defaultValue, hideFn, resolve, next: onNextFn } + payload: { id, title, message, okLabel, okFn, cancelLabel, cancelFn, modalType: modalType || ModalTypes.default, defaultValue: defaultValue, hideFn, resolve, next: onNextFn, data } }) }) } - const alert = (data: AlertModal) => { - return modal({ id: data.id, title: data.title || 'Alert', message: data.message || data.title, okLabel: 'OK', okFn: (value?:any) => {}, cancelLabel: '', cancelFn: () => {} }) + const alert = (modalData: AlertModal) => { + return modal({ id: modalData.id, title: modalData.title || 'Alert', message: modalData.message || modalData.title, okLabel: 'OK', okFn: (value?:any) => {}, cancelLabel: '', cancelFn: () => {} }) } const handleHideModal = () => { diff --git a/libs/remix-ui/app/src/lib/remix-app/interface/index.ts b/libs/remix-ui/app/src/lib/remix-app/interface/index.ts index af25ce13b9..f31536678e 100644 --- a/libs/remix-ui/app/src/lib/remix-app/interface/index.ts +++ b/libs/remix-ui/app/src/lib/remix-app/interface/index.ts @@ -15,7 +15,8 @@ export interface AppModal { defaultValue?: string hideFn?: () => void, resolve?: (value?:any) => void, - next?: () => void + next?: () => void, + data?: any } export interface AlertModal { diff --git a/libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts b/libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts index 8a1c89ac79..a50a3dbd66 100644 --- a/libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts +++ b/libs/remix-ui/app/src/lib/remix-app/reducer/modals.ts @@ -20,7 +20,8 @@ export const modalReducer = (state: ModalState = ModalInitialState, action: Moda defaultValue: action.payload.defaultValue, hideFn: action.payload.hideFn, resolve: action.payload.resolve, - next: action.payload.next + next: action.payload.next, + data: action.payload.data } const modalList: AppModal[] = state.modals.slice() diff --git a/libs/remix-ui/modal-dialog/src/lib/types/index.ts b/libs/remix-ui/modal-dialog/src/lib/types/index.ts index db473683d1..a8793971d7 100644 --- a/libs/remix-ui/modal-dialog/src/lib/types/index.ts +++ b/libs/remix-ui/modal-dialog/src/lib/types/index.ts @@ -14,5 +14,6 @@ export interface ModalDialogProps { handleHide: (hideState?: boolean) => void, children?: React.ReactNode, resolve?: (value?:any) => void, - next?: () => void + next?: () => void, + data?: any } diff --git a/libs/remix-ui/search/src/lib/components/OverWriteCheck.tsx b/libs/remix-ui/search/src/lib/components/OverWriteCheck.tsx new file mode 100644 index 0000000000..dfe193ca9e --- /dev/null +++ b/libs/remix-ui/search/src/lib/components/OverWriteCheck.tsx @@ -0,0 +1,33 @@ +import React, { useContext, useEffect, useRef, useState } from 'react' +import { SearchContext } from '../context/context' + +export const OverWriteCheck = props => { + const { setReplaceWithoutConfirmation } = useContext(SearchContext) + + const change = e => { + console.log(e.target.checked) + setReplaceWithoutConfirmation(e.target.checked) + } + + return ( + <> +
    +
    + + +
    +
    + + ) +} diff --git a/libs/remix-ui/search/src/lib/components/Search.tsx b/libs/remix-ui/search/src/lib/components/Search.tsx index 05a856832e..3df0d37a4a 100644 --- a/libs/remix-ui/search/src/lib/components/Search.tsx +++ b/libs/remix-ui/search/src/lib/components/Search.tsx @@ -6,6 +6,7 @@ import '../search.css' import { Include } from './Include' import { Exclude } from './Exclude' import { Replace } from './Replace' +import { OverWriteCheck } from './OverWriteCheck' export const SearchTab = props => { @@ -19,6 +20,7 @@ return ( +
    diff --git a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx index baf61ecaca..b9522ed1c1 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from 'react' +import React, { useContext, useEffect, useRef, useState } from 'react' import { SearchContext } from '../../context/context' import { SearchResult, SearchResultLine } from '../../types' import { ResultFileName } from './ResultFileName' @@ -9,15 +9,23 @@ interface ResultItemProps { } export const ResultItem = (props: ResultItemProps) => { - const { state, findText } = useContext(SearchContext) + const { state, findText, disableForceReload } = useContext(SearchContext) const [loading, setLoading] = useState(false) const [lines, setLines] = useState([]) const [toggleExpander, setToggleExpander] = useState(false) + const reloadTimeOut = useRef(null) useEffect(() => { reload() }, [props.file.timeStamp]) + useEffect(() => { + if(props.file.forceReload){ + clearTimeout(reloadTimeOut.current) + reloadTimeOut.current = setTimeout(() => reload(), 1000) + } + }, [props.file.forceReload]) + const toggleClass = () => { setToggleExpander(!toggleExpander) } @@ -30,6 +38,7 @@ export const ResultItem = (props: ResultItemProps) => { findText(props.file.filename).then(res => { setLines(res) setLoading(false) + disableForceReload(props.file.filename) }) } diff --git a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx index e9b468b019..90f03991a7 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx @@ -1,3 +1,4 @@ +import { useDialogDispatchers } from 'libs/remix-ui/app/src/lib/remix-app/context/provider' import React, { useContext } from 'react' import { SearchContext } from '../../context/context' import { SearchResult, SearchResultLine, SearchResultLineLine } from '../../types' @@ -10,11 +11,12 @@ interface ResultSummaryProps { export const ResultSummary = (props: ResultSummaryProps) => { const { hightLightInPath, replaceText, state } = useContext(SearchContext) + const { modal } = useDialogDispatchers() const selectLine = async (line: SearchResultLineLine) => { await hightLightInPath(props.searchResult, line) } - const replace = async (line: SearchResultLineLine) => { + const confirmReplace = async (line: SearchResultLineLine) => { props.setLoading(true) try{ await replaceText(props.searchResult, line) @@ -23,6 +25,14 @@ export const ResultSummary = (props: ResultSummaryProps) => { } } + const replace = async (line: SearchResultLineLine) => { + if(state.replaceWithOutConfirmation){ + confirmReplace(line) + }else{ + modal({ id: 'matomoModal', title: 'Replace', message: `Are you sure you want to replace '${line.center}' by '${state.replace}' in ${props.searchResult.filename}?`, okLabel: 'Yes', okFn: confirmReplace, cancelLabel: 'No', cancelFn: ()=>{}, data: line }) + } + } + return ( <> {props.line.lines.map((lineItem, index) => ( diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index 7d5b13c71e..d4e50f3814 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -33,6 +33,8 @@ export interface SearchingStateInterface { toggleCaseSensitive: () => void toggleMatchWholeWord: () => void toggleUseRegex: () => void + setReplaceWithoutConfirmation: (value: boolean) => void + disableForceReload: (file: string) => void } export const SearchContext = createContext(null) @@ -120,6 +122,18 @@ export const SearchProvider = ({ payload: undefined }) }, + setReplaceWithoutConfirmation: (value: boolean) => { + dispatch({ + type: 'SET_REPLACE_WITHOUT_CONFIRMATION', + payload: value + }) + }, + disableForceReload: (file: string) => { + dispatch({ + type: 'DISABLE_FORCE_RELOAD', + payload: file + }) + }, findText: async (path: string) => { if (!plugin) return try { @@ -165,10 +179,12 @@ export const SearchProvider = ({ } const reloadStateForFile = async (file: string) => { - clearTimeout(reloadTimeOut.current) - reloadTimeOut.current = setTimeout(async () => { + //clearTimeout(reloadTimeOut.current) + console.log('reload file', file) + //reloadTimeOut.current = setTimeout(async () => { + console.log('calling file', file) await value.reloadFile(file) - }, 1000) + //}, 1000) } useEffect(() => { @@ -198,7 +214,8 @@ export const SearchProvider = ({ filename: file, lines: [], path: file, - timeStamp: Date.now() + timeStamp: Date.now(), + forceReload: false } return r }) diff --git a/libs/remix-ui/search/src/lib/reducers/Reducer.ts b/libs/remix-ui/search/src/lib/reducers/Reducer.ts index 2738caa95f..0ead0fac4d 100644 --- a/libs/remix-ui/search/src/lib/reducers/Reducer.ts +++ b/libs/remix-ui/search/src/lib/reducers/Reducer.ts @@ -51,11 +51,24 @@ export const SearchReducer = (state: SearchState = SearchingInitialState, action ...state, matchWord: !state.matchWord, timeStamp: Date.now() - } + } + case 'SET_REPLACE_WITHOUT_CONFIRMATION': + return { + ...state, + replaceWithOutConfirmation: action.payload, + } + case 'DISABLE_FORCE_RELOAD': + if (state.searchResults) { + const findFile = state.searchResults.find(file => file.filename === action.payload) + if (findFile) findFile.forceReload = false + } + return { + ...state, + } case 'RELOAD_FILE': if (state.searchResults) { const findFile = state.searchResults.find(file => file.filename === action.payload) - if (findFile) findFile.timeStamp = Date.now() + if (findFile) findFile.forceReload = true } return { ...state, diff --git a/libs/remix-ui/search/src/lib/types/index.ts b/libs/remix-ui/search/src/lib/types/index.ts index 4521bfb658..7b3d06e1b3 100644 --- a/libs/remix-ui/search/src/lib/types/index.ts +++ b/libs/remix-ui/search/src/lib/types/index.ts @@ -29,7 +29,8 @@ export interface SearchResult { filename: string, path: string, lines: SearchResultLine[], - timeStamp: number + timeStamp: number, + forceReload: boolean } export interface SearchState { @@ -40,8 +41,9 @@ export interface SearchState { exclude: string, casesensitive: boolean, matchWord: boolean, + replaceWithOutConfirmation: boolean, useRegExp: boolean, - timeStamp: number + timeStamp: number, } export const SearchingInitialState: SearchState = { @@ -53,5 +55,6 @@ export const SearchingInitialState: SearchState = { casesensitive: false, matchWord: false, useRegExp: false, + replaceWithOutConfirmation: false, timeStamp: 0 } \ No newline at end of file From 513e670fd0996f08fe5a2cc0d60f64846344a16b Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 22 Feb 2022 09:37:31 +0100 Subject: [PATCH 24/35] update tests --- apps/remix-ide-e2e/src/tests/search.test.ts | 16 ++++++++++++++++ .../search/src/lib/components/OverWriteCheck.tsx | 2 +- .../src/lib/components/results/ResultSummary.tsx | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/search.test.ts b/apps/remix-ide-e2e/src/tests/search.test.ts index cfcbe506af..ea6249adcb 100644 --- a/apps/remix-ide-e2e/src/tests/search.test.ts +++ b/apps/remix-ide-e2e/src/tests/search.test.ts @@ -72,12 +72,28 @@ module.exports = { .moveToElement('*[data-id="contracts/2_Owner.sol-30-71"]', 10, 10) .waitForElementVisible('*[data-id="replace-contracts/2_Owner.sol-30-71"]') .click('*[data-id="replace-contracts/2_Owner.sol-30-71"]').pause(2000). + modalFooterOKClick('confirmreplace').pause(2000). getEditorValue((content) => { browser.assert.ok(content.includes('replacing deployer for a constructor'), 'should replace text ok') }) }, + 'Should replace text without confirmation': function (browser: NightwatchBrowser) { + browser.click('*[data-id="confirm_replace_label"]').pause(500) + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'replacing').pause(1000) + .setValue('*[id="search_replace"]', '2').pause(1000) + .waitForElementVisible('*[data-id="contracts/2_Owner.sol-30-71"]') + .moveToElement('*[data-id="contracts/2_Owner.sol-30-71"]', 10, 10) + .waitForElementVisible('*[data-id="replace-contracts/2_Owner.sol-30-71"]') + .click('*[data-id="replace-contracts/2_Owner.sol-30-71"]').pause(2000). + getEditorValue((content) => { + browser.assert.ok(content.includes('replacing2 deployer for a constructor'), 'should replace text ok') + }) + }, 'Should find text with include': function (browser: NightwatchBrowser) { browser + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'contract').pause(1000) .setValue('*[id="search_include"]', 'contracts/**').pause(2000) .elements('css selector','.search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 4) diff --git a/libs/remix-ui/search/src/lib/components/OverWriteCheck.tsx b/libs/remix-ui/search/src/lib/components/OverWriteCheck.tsx index dfe193ca9e..2c3e0300c1 100644 --- a/libs/remix-ui/search/src/lib/components/OverWriteCheck.tsx +++ b/libs/remix-ui/search/src/lib/components/OverWriteCheck.tsx @@ -21,7 +21,7 @@ export const OverWriteCheck = props => { />
    {loading ?
    Loading...
    : null} {!toggleExpander && !loading ? ( diff --git a/libs/remix-ui/search/src/lib/components/results/Results.tsx b/libs/remix-ui/search/src/lib/components/results/Results.tsx index 9a1b717cca..1c5521cfeb 100644 --- a/libs/remix-ui/search/src/lib/components/results/Results.tsx +++ b/libs/remix-ui/search/src/lib/components/results/Results.tsx @@ -1,16 +1,17 @@ -import React, { useContext } from 'react' +import React, { useContext, useEffect } from 'react' import { SearchContext } from '../../context/context' import { ResultItem } from './ResultItem' export const Results = () => { const { state } = useContext(SearchContext) - return (
    - {state.searchResults && + {state.find ?
    {state.count} results
    : null} + {state.count < state.maxResults && state.searchResults && state.searchResults.map((result, index) => { return })} + {state.find && state.count >= state.maxResults?
    Too many results to display.

    Please narrow your search.
    : null}
    ) } diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index b17d2d9708..1f7dfe9417 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -35,6 +35,7 @@ export interface SearchingStateInterface { toggleUseRegex: () => void setReplaceWithoutConfirmation: (value: boolean) => void disableForceReload: (file: string) => void + updateCount: (count: number) => void } export const SearchContext = createContext(null) @@ -134,6 +135,12 @@ export const SearchProvider = ({ payload: file }) }, + updateCount: (count: number) => { + dispatch({ + type: 'UPDATE_COUNT', + payload: count + }) + }, findText: async (path: string) => { if (!plugin) return try { @@ -214,7 +221,7 @@ export const SearchProvider = ({ lines: [], path: file, timeStamp: Date.now(), - forceReload: false + forceReload: false, } return r }) diff --git a/libs/remix-ui/search/src/lib/reducers/Reducer.ts b/libs/remix-ui/search/src/lib/reducers/Reducer.ts index 0ead0fac4d..e5f0318bc5 100644 --- a/libs/remix-ui/search/src/lib/reducers/Reducer.ts +++ b/libs/remix-ui/search/src/lib/reducers/Reducer.ts @@ -33,6 +33,12 @@ export const SearchReducer = (state: SearchState = SearchingInitialState, action return { ...state, searchResults: action.payload, + count: 0 + } + case 'UPDATE_COUNT': + return { + ...state, + count: state.count + parseInt(action.payload) } case 'TOGGLE_CASE_SENSITIVE': return { diff --git a/libs/remix-ui/search/src/lib/search.css b/libs/remix-ui/search/src/lib/search.css index 4f4dfbd5bb..88f62ab5b2 100644 --- a/libs/remix-ui/search/src/lib/search.css +++ b/libs/remix-ui/search/src/lib/search.css @@ -92,4 +92,15 @@ text-overflow: ellipsis; overflow: hidden; text-transform: uppercase; +} + +.search_tab .result_count { + flex-grow: 1; + text-align: right; + display: flex; + justify-content: flex-end; +} + +.search_tab .result_count_number { + font-size: x-small; } \ No newline at end of file diff --git a/libs/remix-ui/search/src/lib/types/index.ts b/libs/remix-ui/search/src/lib/types/index.ts index 7b3d06e1b3..3d7fe96a32 100644 --- a/libs/remix-ui/search/src/lib/types/index.ts +++ b/libs/remix-ui/search/src/lib/types/index.ts @@ -1,3 +1,4 @@ +import { count } from "console"; export interface Action { type: string @@ -30,7 +31,7 @@ export interface SearchResult { path: string, lines: SearchResultLine[], timeStamp: number, - forceReload: boolean + forceReload: boolean, } export interface SearchState { @@ -44,6 +45,8 @@ export interface SearchState { replaceWithOutConfirmation: boolean, useRegExp: boolean, timeStamp: number, + count: number, + maxResults: number } export const SearchingInitialState: SearchState = { @@ -56,5 +59,7 @@ export const SearchingInitialState: SearchState = { matchWord: false, useRegExp: false, replaceWithOutConfirmation: false, - timeStamp: 0 + timeStamp: 0, + count: 0, + maxResults: 500 } \ No newline at end of file From fe8f8114c854a9103cc06e40bd54c9f79dd981fb Mon Sep 17 00:00:00 2001 From: filip mertens Date: Wed, 23 Feb 2022 11:17:26 +0100 Subject: [PATCH 31/35] counting better --- .../search/src/lib/components/results/ResultItem.tsx | 11 +++++++++-- libs/remix-ui/search/src/lib/context/context.tsx | 7 ++++--- libs/remix-ui/search/src/lib/reducers/Reducer.ts | 12 +++++++++++- libs/remix-ui/search/src/lib/types/index.ts | 1 + 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx index e257c4900a..3534321e7e 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx @@ -18,6 +18,7 @@ export const ResultItem = (props: ResultItemProps) => { const reloadTimeOut = useRef(null) const subscribed = useRef(true) + useEffect(() => { reload() }, [props.file.timeStamp]) @@ -48,7 +49,13 @@ export const ResultItem = (props: ResultItemProps) => { findText(props.file.filename).then(res => { if (subscribed.current) { setLines(res) - if (res) updateCount(res.length) + if (res) { + let count = 0 + res.forEach(line => { + count += line.lines.length + }) + updateCount(count, props.file.filename) + } setLoading(false) disableForceReload(props.file.filename) } @@ -71,7 +78,7 @@ export const ResultItem = (props: ResultItemProps) => {
    - {lines.length} + {props.file.count}
    diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index 1f7dfe9417..0cc748e6d4 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -35,7 +35,7 @@ export interface SearchingStateInterface { toggleUseRegex: () => void setReplaceWithoutConfirmation: (value: boolean) => void disableForceReload: (file: string) => void - updateCount: (count: number) => void + updateCount: (count: number, file: string) => void } export const SearchContext = createContext(null) @@ -135,10 +135,10 @@ export const SearchProvider = ({ payload: file }) }, - updateCount: (count: number) => { + updateCount: (count: number, file: string) => { dispatch({ type: 'UPDATE_COUNT', - payload: count + payload: {count, file} }) }, findText: async (path: string) => { @@ -222,6 +222,7 @@ export const SearchProvider = ({ path: file, timeStamp: Date.now(), forceReload: false, + count: 0 } return r }) diff --git a/libs/remix-ui/search/src/lib/reducers/Reducer.ts b/libs/remix-ui/search/src/lib/reducers/Reducer.ts index e5f0318bc5..0841b2b424 100644 --- a/libs/remix-ui/search/src/lib/reducers/Reducer.ts +++ b/libs/remix-ui/search/src/lib/reducers/Reducer.ts @@ -36,9 +36,19 @@ export const SearchReducer = (state: SearchState = SearchingInitialState, action count: 0 } case 'UPDATE_COUNT': + const findFile = state.searchResults.find(file => file.filename === action.payload.file) + let count = 0 + if (findFile) { + findFile.count = action.payload.count + } + state.searchResults.forEach(file => { + if (file.count) { + count += file.count + } + }) return { ...state, - count: state.count + parseInt(action.payload) + count: count } case 'TOGGLE_CASE_SENSITIVE': return { diff --git a/libs/remix-ui/search/src/lib/types/index.ts b/libs/remix-ui/search/src/lib/types/index.ts index 3d7fe96a32..af76487c51 100644 --- a/libs/remix-ui/search/src/lib/types/index.ts +++ b/libs/remix-ui/search/src/lib/types/index.ts @@ -32,6 +32,7 @@ export interface SearchResult { lines: SearchResultLine[], timeStamp: number, forceReload: boolean, + count: number } export interface SearchState { From a510ba9ab2b3f6e50ffb9c7e2a1a453302a68c7a Mon Sep 17 00:00:00 2001 From: filip mertens Date: Wed, 23 Feb 2022 11:26:40 +0100 Subject: [PATCH 32/35] linting --- .../search/src/lib/reducers/Reducer.ts | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/libs/remix-ui/search/src/lib/reducers/Reducer.ts b/libs/remix-ui/search/src/lib/reducers/Reducer.ts index 0841b2b424..05e9efaecb 100644 --- a/libs/remix-ui/search/src/lib/reducers/Reducer.ts +++ b/libs/remix-ui/search/src/lib/reducers/Reducer.ts @@ -36,19 +36,23 @@ export const SearchReducer = (state: SearchState = SearchingInitialState, action count: 0 } case 'UPDATE_COUNT': - const findFile = state.searchResults.find(file => file.filename === action.payload.file) - let count = 0 - if (findFile) { - findFile.count = action.payload.count - } - state.searchResults.forEach(file => { - if (file.count) { - count += file.count + if (state.searchResults) { + const findFile = state.searchResults.find(file => file.filename === action.payload.file) + let count = 0 + if (findFile) { + findFile.count = action.payload.count } - }) - return { - ...state, - count: count + state.searchResults.forEach(file => { + if (file.count) { + count += file.count + } + }) + return { + ...state, + count: count + } + } else { + return state } case 'TOGGLE_CASE_SENSITIVE': return { @@ -68,7 +72,7 @@ export const SearchReducer = (state: SearchState = SearchingInitialState, action matchWord: !state.matchWord, timeStamp: Date.now() } - case 'SET_REPLACE_WITHOUT_CONFIRMATION': + case 'SET_REPLACE_WITHOUT_CONFIRMATION': return { ...state, replaceWithOutConfirmation: action.payload, From 284e1328fa0a7ec7eb9638dfe6ba6e40b5a6adfd Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 24 Feb 2022 11:03:27 +0100 Subject: [PATCH 33/35] prefix classes --- .../search/src/lib/components/Exclude.tsx | 2 +- .../search/src/lib/components/Find.tsx | 6 +-- .../search/src/lib/components/Include.tsx | 2 +- .../src/lib/components/OverWriteCheck.tsx | 2 +- .../search/src/lib/components/Replace.tsx | 2 +- .../search/src/lib/components/Search.tsx | 2 +- .../lib/components/results/ResultFileName.tsx | 4 +- .../src/lib/components/results/ResultItem.tsx | 8 ++-- .../lib/components/results/ResultSummary.tsx | 14 +++---- .../src/lib/components/results/Results.tsx | 2 +- libs/remix-ui/search/src/lib/search.css | 38 +++++++++---------- 11 files changed, 41 insertions(+), 41 deletions(-) diff --git a/libs/remix-ui/search/src/lib/components/Exclude.tsx b/libs/remix-ui/search/src/lib/components/Exclude.tsx index be6f0054fb..2537a4d36e 100644 --- a/libs/remix-ui/search/src/lib/components/Exclude.tsx +++ b/libs/remix-ui/search/src/lib/components/Exclude.tsx @@ -17,7 +17,7 @@ export const Exclude = props => { return ( <> -
    +
    { return ( <> -
    +
    -
    +
    -
    +
    { return ( <> -
    +
    { return ( <> -
    +
    { return ( <> -
    +
    -
    +
    diff --git a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx index 5d6412af25..303e8da21e 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx @@ -18,9 +18,9 @@ export const ResultFileName = (props: ResultItemProps) => { return ( <> {icon ?
    : null} -
    +
    {path.basename(props.file.path)} - {path.dirname(props.file.path)} + {path.dirname(props.file.path)}
    ) diff --git a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx index 3534321e7e..91bb40b51b 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultItem.tsx @@ -66,7 +66,7 @@ export const ResultItem = (props: ResultItemProps) => { <> {lines && lines.length ? ( <> -
    +
    {' '} -
    -
    +
    +
    {props.file.count}
    {loading ?
    Loading...
    : null} {!toggleExpander && !loading ? ( -
    +
    {lines.map((line, index) => ( { return ( <> {props.line.lines.map((lineItem, index) => ( -
    +
    { selectLine(lineItem) }} data-id={`${props.searchResult.filename}-${lineItem.position.start.line}-${lineItem.position.start.column}`} key={props.searchResult.filename} - className='search_line pb-1' + className='search_plugin_search_line pb-1' > -
    {lineItem.left.substring(lineItem.left.length - 20).trimStart()}
    - {lineItem.center} - {state.replace? {state.replace}:<>} -
    {lineItem.right.substring(0, 100)}
    +
    {lineItem.left.substring(lineItem.left.length - 20).trimStart()}
    + {lineItem.center} + {state.replace? {state.replace}:<>} +
    {lineItem.right.substring(0, 100)}
    -
    +
    { replace(lineItem) }} className="codicon codicon-find-replace" role="button" aria-label="Replace" aria-disabled="false">
    diff --git a/libs/remix-ui/search/src/lib/components/results/Results.tsx b/libs/remix-ui/search/src/lib/components/results/Results.tsx index 1c5521cfeb..b2094d23c9 100644 --- a/libs/remix-ui/search/src/lib/components/results/Results.tsx +++ b/libs/remix-ui/search/src/lib/components/results/Results.tsx @@ -6,7 +6,7 @@ export const Results = () => { const { state } = useContext(SearchContext) return (
    - {state.find ?
    {state.count} results
    : null} + {state.find ?
    {state.count} results
    : null} {state.count < state.maxResults && state.searchResults && state.searchResults.map((result, index) => { return diff --git a/libs/remix-ui/search/src/lib/search.css b/libs/remix-ui/search/src/lib/search.css index 88f62ab5b2..895ce83e7f 100644 --- a/libs/remix-ui/search/src/lib/search.css +++ b/libs/remix-ui/search/src/lib/search.css @@ -1,4 +1,4 @@ -.search_result_item_title { +.search_plugin_search_result_item_title { display: flex; -webkit-user-select: none; /* Safari */ -moz-user-select: none; /* Firefox */ @@ -8,7 +8,7 @@ align-items: center; } -.wrap_summary { +.search_plugin_wrap_summary { overflow: hidden; white-space: nowrap; -webkit-user-select: none; /* Safari */ @@ -18,89 +18,89 @@ cursor: pointer; } -.find-part { +.search_plugin_find-part { display: flex; flex-direction: column; padding: 2px; } -.controls { +.search_plugin_controls { display: flex; } -.search_tab .search_line_container { +.search_plugin_search_tab .search_plugin_search_line_container { display: flex; flex-direction: row; position: relative; } -.search_tab .search_line { +.search_plugin_search_tab .search_plugin_search_line { width: 100%; overflow: hidden; display: flex; } -.search_tab .search_control { +.search_plugin_search_tab .search_plugin_search_control { flex-grow: 0; position: absolute; right: 0px; top: 0px; } -.summary_right { +.search_plugin_summary_right { min-width: 0; white-space: pre; text-overflow: ellipsis; overflow: hidden; } -.search_tab .replace_strike { +.search_plugin_search_tab .search_plugin_replace_strike { text-decoration: line-through; } -.summary_left { +.search_plugin_summary_left { white-space: pre; } -.search_tab mark { +.search_plugin_search_tab mark { padding: 0; } -.search_tab .search_line_container .search_control { +.search_plugin_search_tab .search_plugin_search_line_container .search_plugin_search_control { display: none; } -.search_tab .search_line_container:hover .search_control { +.search_plugin_search_tab .search_plugin_search_line_container:hover .search_plugin_search_control { display: block; } -.search_tab .search_line_container:hover .search_line { +.search_plugin_search_tab .search_plugin_search_line_container:hover .search_plugin_search_line { width: 93%; } -.search-input { +.search_plugin_search-input { display: flex; flex-direction: row; align-items: center; } -.search_tab .checked { +.search_plugin_search_tab .checked { background-color: var(--secondary); } -.search_tab .search_file_name { +.search_plugin_search_tab .search_plugin_search_file_name { text-overflow: ellipsis; overflow: hidden; text-transform: uppercase; } -.search_tab .result_count { +.search_plugin_search_tab .search_plugin_result_count { flex-grow: 1; text-align: right; display: flex; justify-content: flex-end; } -.search_tab .result_count_number { +.search_plugin_search_tab .search_plugin_result_count_number { font-size: x-small; } \ No newline at end of file From 21ad2ea3553066d0667c43a1e9eda4b31d78ac85 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 24 Feb 2022 11:09:52 +0100 Subject: [PATCH 34/35] tests --- apps/remix-ide-e2e/src/tests/search.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/search.test.ts b/apps/remix-ide-e2e/src/tests/search.test.ts index ea6249adcb..19fe83da3c 100644 --- a/apps/remix-ide-e2e/src/tests/search.test.ts +++ b/apps/remix-ide-e2e/src/tests/search.test.ts @@ -20,7 +20,7 @@ module.exports = { .waitForElementContainsText('*[data-id="search_results"]', 'that person al') .waitForElementContainsText('*[data-id="search_results"]', 'sender.voted') .waitForElementContainsText('*[data-id="search_results"]', 'read') - .elements('css selector','.search_line', (res) => { + .elements('css selector','.search_plugin_search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 6) }) }, @@ -35,7 +35,7 @@ module.exports = { .waitForElementContainsText('*[data-id="search_results"]', '1_STORAGE.SOL', 60000) .waitForElementContainsText('*[data-id="search_results"]', '4_BALLOT_TEST.SOL', 60000) .waitForElementContainsText('*[data-id="search_results"]', 'tests', 60000) - .elements('css selector','.search_line', (res) => { + .elements('css selector','.search_plugin_search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 4) }) }, @@ -43,12 +43,12 @@ module.exports = { browser .waitForElementVisible('*[data-id="search_use_regex"]').click('*[data-id="search_use_regex"]') .waitForElementVisible('*[data-id="search_case_sensitive"]').click('*[data-id="search_case_sensitive"]') - .elements('css selector','.search_line', (res) => { + .elements('css selector','.search_plugin_search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 0) }) .clearValue('*[id="search_input"]') .setValue('*[id="search_input"]', 'Contract').pause(1000) - .elements('css selector','.search_line', (res) => { + .elements('css selector','.search_plugin_search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 6) }) .waitForElementContainsText('*[data-id="search_results"]', 'DEPLOY_ETHERS.JS', 60000) @@ -61,7 +61,7 @@ module.exports = { .waitForElementVisible('*[data-id="search_whole_word"]').click('*[data-id="search_whole_word"]') .clearValue('*[id="search_input"]') .setValue('*[id="search_input"]', 'contract').pause(1000) - .elements('css selector','.search_line', (res) => { + .elements('css selector','.search_plugin_search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 27) }) }, @@ -95,7 +95,7 @@ module.exports = { .clearValue('*[id="search_input"]') .setValue('*[id="search_input"]', 'contract').pause(1000) .setValue('*[id="search_include"]', 'contracts/**').pause(2000) - .elements('css selector','.search_line', (res) => { + .elements('css selector','.search_plugin_search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 4) }) }, @@ -103,11 +103,11 @@ module.exports = { browser .clearValue('*[id="search_include"]').pause(2000) .setValue('*[id="search_include"]', '**').pause(2000) - .elements('css selector','.search_line', (res) => { + .elements('css selector','.search_plugin_search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 26) }) .setValue('*[id="search_exclude"]', ',contracts/**').pause(2000) - .elements('css selector','.search_line', (res) => { + .elements('css selector','.search_plugin_search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 22) }) }, @@ -115,7 +115,7 @@ module.exports = { browser .waitForElementVisible('*[id="search_input"]') .setValue('*[id="search_input"]', 'nodata').pause(1000) - .elements('css selector','.search_line', (res) => { + .elements('css selector','.search_plugin_search_line', (res) => { Array.isArray(res.value) && browser.assert.equal(res.value.length, 0) }) } From 53b020744c678266211ac66c394f35bb9f85b4a7 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 1 Mar 2022 14:44:49 +0100 Subject: [PATCH 35/35] udapte var names --- .../remix-ui/search/src/lib/components/Exclude.tsx | 8 ++++---- libs/remix-ui/search/src/lib/components/Find.tsx | 2 +- .../remix-ui/search/src/lib/components/Include.tsx | 6 +++--- libs/remix-ui/search/src/lib/context/context.tsx | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libs/remix-ui/search/src/lib/components/Exclude.tsx b/libs/remix-ui/search/src/lib/components/Exclude.tsx index 2537a4d36e..36d3bdd103 100644 --- a/libs/remix-ui/search/src/lib/components/Exclude.tsx +++ b/libs/remix-ui/search/src/lib/components/Exclude.tsx @@ -3,16 +3,16 @@ import { SearchContext } from '../context/context' export const Exclude = props => { const { setExclude, state } = useContext(SearchContext) - const [str, setStr] = useState('.git/**/*,.deps/**/*') + const [excludeInput, setExcludeInput] = useState('.git/**/*,.deps/**/*') const timeOutId = useRef(null) const change = e => { - setStr(e.target.value) + setExcludeInput(e.target.value) clearTimeout(timeOutId.current) timeOutId.current = setTimeout(() => setExclude(e.target.value), 500) } useEffect(() => { - setExclude(str) + setExclude(excludeInput) }, []) return ( @@ -24,7 +24,7 @@ export const Exclude = props => { placeholder="Exclude ie .git/**/*" className="form-control" onChange={change} - value={str} + value={excludeInput} >
    diff --git a/libs/remix-ui/search/src/lib/components/Find.tsx b/libs/remix-ui/search/src/lib/components/Find.tsx index 032c934a2d..42343fce6e 100644 --- a/libs/remix-ui/search/src/lib/components/Find.tsx +++ b/libs/remix-ui/search/src/lib/components/Find.tsx @@ -1,7 +1,7 @@ import React, { useContext, useRef } from 'react' import { SearchContext } from '../context/context' -export const Find = props => { +export const Find = () => { const { setFind, state, diff --git a/libs/remix-ui/search/src/lib/components/Include.tsx b/libs/remix-ui/search/src/lib/components/Include.tsx index af99e093b6..ab50233885 100644 --- a/libs/remix-ui/search/src/lib/components/Include.tsx +++ b/libs/remix-ui/search/src/lib/components/Include.tsx @@ -3,10 +3,10 @@ import { SearchContext } from '../context/context' export const Include = props => { const { setInclude } = useContext(SearchContext) - const [str, setStr] = useState('') + const [includeInput, setIncludeInput] = useState('') const timeOutId = useRef(null) const change = e => { - setStr(e.target.value) + setIncludeInput(e.target.value) clearTimeout(timeOutId.current) timeOutId.current = setTimeout(() => setInclude(e.target.value), 500) } @@ -20,7 +20,7 @@ export const Include = props => { placeholder="Include ie contracts/**/*.sol" className="form-control" onChange={change} - value={str} + value={includeInput} >
    diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index 0cc748e6d4..e8ce76e287 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -205,17 +205,17 @@ export const SearchProvider = ({ useEffect(() => { if (state.find) { (async () => { - const res = await getDirectory('/', plugin) + const files = await getDirectory('/', plugin) const pathFilter: any = {} if (state.include){ - const inc = state.include.replaceAll(/(? i.trim()) + const includeWithGlobalExpression = state.include.replaceAll(/(? i.trim()) } if (state.exclude){ - const exc = state.exclude.replaceAll(/(? i.trim()) + const excludeWithGlobalExpression = state.exclude.replaceAll(/(? i.trim()) } - const ob = res.filter(filePathFilter(pathFilter)).map(file => { + const filteredFiles = files.filter(filePathFilter(pathFilter)).map(file => { const r: SearchResult = { filename: file, lines: [], @@ -226,7 +226,7 @@ export const SearchProvider = ({ } return r }) - value.setSearchResults(ob) + value.setSearchResults(filteredFiles) })() } }, [state.timeStamp])