From 6a8442f568ab4b9b25d3670af8d8edc59c9a6f0f Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 18 May 2021 10:46:08 +0100 Subject: [PATCH] Optimised mode for managing reserved words --- .../remix-ui/file-explorer/src/lib/file-explorer.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx index 4ce0c9cace..57eda46094 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx @@ -97,7 +97,8 @@ export const FileExplorer = (props: FileExplorerProps) => { modals: [], toasterMsg: '', mouseOverElement: null, - showContextMenu: false + showContextMenu: false, + reservedKeywords: [name, 'gist-'] }) const [fileSystem, dispatch] = useReducer(fileSystemReducer, fileSystemInitialState) const editRef = useRef(null) @@ -222,6 +223,11 @@ export const FileExplorer = (props: FileExplorerProps) => { return keyPath.join('/') } + const hasReservedKeyword = (content: string): boolean => { + if (state.reservedKeywords.findIndex(value => content.startsWith(value)) !== -1) return true + else return false + } + const createNewFile = async (newFilePath: string) => { const fileManager = state.fileManager @@ -584,7 +590,7 @@ export const FileExplorer = (props: FileExplorerProps) => { modal('Validation Error', 'Special characters are not allowed', 'OK', () => {}) } else { if (state.focusEdit.isNew) { - if ((content === props.name) || (content.indexOf('gist-') === 0)) { + if (hasReservedKeyword(content)) { removeInputField(parentFolder)(dispatch) modal('Reserved Keyword', `File name contains remix reserved keywords. '${content}'`, { label: 'Close', @@ -595,7 +601,7 @@ export const FileExplorer = (props: FileExplorerProps) => { removeInputField(parentFolder)(dispatch) } } else { - if ((content === props.name) || (content.indexOf('gist-') === 0)) { + if (hasReservedKeyword(content)) { editRef.current.textContent = state.focusEdit.lastEdit modal('Reserved Keyword', `File name contains remix reserved keywords. '${content}'`, { label: 'Close',