diff --git a/libs/remix-ui/workspace/src/lib/actions/events.ts b/libs/remix-ui/workspace/src/lib/actions/events.ts index 0f9d7ba29f..7ea0b03053 100644 --- a/libs/remix-ui/workspace/src/lib/actions/events.ts +++ b/libs/remix-ui/workspace/src/lib/actions/events.ts @@ -1,7 +1,7 @@ import { extractParentFromKey } from '@remix-ui/helper' import React from 'react' import { action } from '../types' -import { displayNotification, displayPopUp, fileAddedSuccess, fileRemovedSuccess, fileRenamedSuccess, folderAddedSuccess, loadLocalhostError, loadLocalhostRequest, loadLocalhostSuccess, removeContextMenuItem, rootFolderChangedSuccess, setContextMenuItem, setMode, setReadOnlyMode } from './payload' +import { displayNotification, displayPopUp, fileAddedSuccess, fileRemovedSuccess, fileRenamedSuccess, folderAddedSuccess, loadLocalhostError, loadLocalhostRequest, loadLocalhostSuccess, removeContextMenuItem, removeFocus, rootFolderChangedSuccess, setContextMenuItem, setMode, setReadOnlyMode } from './payload' import { addInputField, createWorkspace, deleteWorkspace, fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile } from './workspace' const LOCALHOST = ' - connect to localhost - ' @@ -45,6 +45,10 @@ export const listenOnPluginEvents = (filePanelPlugin) => { plugin.on('fileManager', 'rootFolderChanged', async (path: string) => { rootFolderChanged(path) }) + + plugin.on('fileManager', 'fileClosed', async (file: string) => { + dispatch(removeFocus(file)) + }) } export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Dispatch) => { diff --git a/libs/remix-ui/workspace/src/lib/actions/payload.ts b/libs/remix-ui/workspace/src/lib/actions/payload.ts index ee59ac24a3..a0ed0850cb 100644 --- a/libs/remix-ui/workspace/src/lib/actions/payload.ts +++ b/libs/remix-ui/workspace/src/lib/actions/payload.ts @@ -187,6 +187,13 @@ export const focusElement = (elements: { key: string, type: 'file' | 'folder' | } } +export const removeFocus = (name: string) => { + return { + type: 'REMOVE_FOCUS_ELEMENT', + payload: name + } +} + export const setContextMenuItem = (item: action) => { return { type: 'SET_CONTEXT_MENU_ITEM', diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index ef769f5c5b..a41365224b 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -497,6 +497,15 @@ export const browserReducer = (state = browserInitialState, action: Action) => { } } + case 'REMOVE_FOCUS_ELEMENT': { + const payload: string = action.payload + + return { + ...state, + focusElement: state.focusElement.filter(element => element.key !== payload) + } + } + case 'SET_CONTEXT_MENU_ITEM': { const payload = action.payload as action