diff --git a/client/src/CommandBar/Body/Item.tsx b/client/src/CommandBar/Body/Item.tsx
index ae69efec25..cb1a21b5ac 100644
--- a/client/src/CommandBar/Body/Item.tsx
+++ b/client/src/CommandBar/Body/Item.tsx
@@ -76,23 +76,26 @@ const CommandBarItem = ({
[index, setFocusedIndex],
);
- const handleClick = useCallback(() => {
- if (onClick) {
- onClick();
- if (closeOnClick) {
- setIsVisible(false);
- setChosenStep({ id: CommandBarStepEnum.INITIAL });
+ const handleClick = useCallback(
+ (e: React.MouseEvent | KeyboardEvent) => {
+ if (onClick) {
+ onClick(e);
+ if (closeOnClick) {
+ setIsVisible(false);
+ setChosenStep({ id: CommandBarStepEnum.INITIAL });
+ }
+ } else {
+ setChosenStep({
+ id: id as Exclude<
+ CommandBarStepEnum,
+ CommandBarStepEnum.ADD_TO_STUDIO | CommandBarStepEnum.SEARCH_DOCS
+ >,
+ });
}
- } else {
- setChosenStep({
- id: id as Exclude<
- CommandBarStepEnum,
- CommandBarStepEnum.ADD_TO_STUDIO | CommandBarStepEnum.SEARCH_DOCS
- >,
- });
- }
- updateArrayInStorage(RECENT_COMMANDS_KEY, itemKey);
- }, [id, onClick, closeOnClick, itemKey]);
+ updateArrayInStorage(RECENT_COMMANDS_KEY, itemKey);
+ },
+ [id, onClick, closeOnClick, itemKey],
+ );
const handleKeyEvent = useCallback(
(e: KeyboardEvent) => {
@@ -103,7 +106,7 @@ const CommandBarItem = ({
) {
e.preventDefault();
e.stopPropagation();
- handleClick();
+ handleClick(e);
return;
}
if (focusedIndex === index && shortAction?.action) {
diff --git a/client/src/CommandBar/steps/SeachFiles.tsx b/client/src/CommandBar/steps/SeachFiles.tsx
index a2a59737eb..20fe826fca 100644
--- a/client/src/CommandBar/steps/SeachFiles.tsx
+++ b/client/src/CommandBar/steps/SeachFiles.tsx
@@ -1,4 +1,4 @@
-import {
+import React, {
ChangeEvent,
memo,
useCallback,
@@ -12,7 +12,11 @@ import { Trans, useTranslation } from 'react-i18next';
import Header from '../Header';
import { CommandBarStepEnum, TabTypesEnum } from '../../types/general';
import { CommandBarContext } from '../../context/commandBarContext';
-import { getAutocomplete } from '../../services/api';
+import {
+ getAutocomplete,
+ getCodeStudio,
+ patchCodeStudio,
+} from '../../services/api';
import { FileResItem } from '../../types/api';
import Body from '../Body';
import FileIcon from '../../components/FileIcon';
@@ -34,7 +38,9 @@ const SearchFiles = ({ studioId }: Props) => {
const { setChosenStep, setIsVisible } = useContext(
CommandBarContext.Handlers,
);
- const { project } = useContext(ProjectContext.Current);
+ const { project, refreshCurrentProjectRepos } = useContext(
+ ProjectContext.Current,
+ );
const { openNewTab } = useContext(TabsContext.Handlers);
const { setIsLeftSidebarFocused } = useContext(UIContext.Focus);
const [files, setFiles] = useState<
@@ -65,7 +71,7 @@ const SearchFiles = ({ studioId }: Props) => {
if (project?.id) {
getAutocomplete(
project.id,
- `path:${searchValue}&content=false&page_size=20`,
+ `path:${searchValue}&content=false&file=true&page_size=20`,
).then((respPath) => {
const fileResults = respPath.data
.filter(
@@ -96,41 +102,89 @@ const SearchFiles = ({ studioId }: Props) => {
items: filterOutDuplicates(
files.map((f) => ({ ...f, key: `${f.path}-${f.repo}-${f.branch}` })),
'key',
- ).map(({ path, repo, branch, key }) => ({
- key,
- id: key,
- onClick: () => {
- openNewTab({
- type: TabTypesEnum.FILE,
- path,
- repoRef: repo,
- branch,
- studioId,
- });
- setIsLeftSidebarFocused(false);
- setIsVisible(false);
- setChosenStep({ id: CommandBarStepEnum.INITIAL });
- },
- label: path,
- footerHint: `${splitPath(repo)
- .slice(repo.startsWith('local//') ? -1 : -2)
- .join('/')} ${
- branch ? `/ ${splitPath(branch).pop()} ` : ''
- }/ ${path}`,
- footerBtns: [
- {
- label: studioId ? t('Add file') : t('Open'),
- shortcut: ['entr'],
+ ).map(({ path, repo, branch, key }) => {
+ const addMultipleFilesToStudio = async () => {
+ if (project?.id && studioId) {
+ const studio = await getCodeStudio(project.id, studioId);
+ const patchedFile = studio?.context.find(
+ (f) =>
+ f.path === path && f.repo === repo && f.branch === branch,
+ );
+ if (!patchedFile) {
+ await patchCodeStudio(project.id, studioId, {
+ context: [
+ ...(studio?.context || []),
+ {
+ path,
+ branch: branch,
+ repo,
+ hidden: false,
+ ranges: [],
+ },
+ ],
+ });
+ refreshCurrentProjectRepos();
+ openNewTab({
+ type: TabTypesEnum.FILE,
+ path,
+ repoRef: repo,
+ branch,
+ studioId,
+ isFileInContext: true,
+ initialRanges: [],
+ });
+ }
+ }
+ };
+ return {
+ key,
+ id: key,
+ onClick: async (e: React.MouseEvent | KeyboardEvent) => {
+ if (studioId && e.shiftKey && project?.id) {
+ await addMultipleFilesToStudio();
+ } else {
+ openNewTab({
+ type: TabTypesEnum.FILE,
+ path,
+ repoRef: repo,
+ branch,
+ studioId,
+ });
+ setIsLeftSidebarFocused(false);
+ setIsVisible(false);
+ setChosenStep({ id: CommandBarStepEnum.INITIAL });
+ }
},
- ],
- Icon: (props: { sizeClassName?: string }) => (
-
-
+