diff --git a/src/features/deployment/actions.test.tsx b/src/features/deployment/actions.test.tsx index ae39b5a8b..a8be124ee 100644 --- a/src/features/deployment/actions.test.tsx +++ b/src/features/deployment/actions.test.tsx @@ -46,6 +46,7 @@ vi.mock("@/platform/workflowSettings", () => ({ vi.mock("@/workbench/contributions", () => ({ notifications: () => ({ notify: mocks.notify }), projectViewSelection: () => [], + changesViewSelection: () => [], toolWindowService: vi.fn(), })); vi.mock("@/workbench/inputDialogs", () => ({ chooseItem: mocks.choose })); diff --git a/src/features/deployment/actions.tsx b/src/features/deployment/actions.tsx index 227d90426..f061794f9 100644 --- a/src/features/deployment/actions.tsx +++ b/src/features/deployment/actions.tsx @@ -22,7 +22,12 @@ import { type DeploymentServerValid, } from "@/platform/remoteSettings"; import { workflowSettings } from "@/platform/workflowSettings"; -import { notifications, projectViewSelection, toolWindowService } from "@/workbench/contributions"; +import { + changesViewSelection, + notifications, + projectViewSelection, + toolWindowService, +} from "@/workbench/contributions"; import { chooseItem } from "@/workbench/inputDialogs"; import { confirm } from "@/workbench/messages"; import { defaultGroup, initialSyncChoices, resolveServer, serverLabel, summarizeReport, targetPaths } from "./model"; @@ -37,12 +42,13 @@ const errorText = (e: unknown) => txTemplate(e instanceof Error ? e.message : St const projectRoot = () => useProject.getState().project?.root ?? null; const deployment = () => workflowSettings().deployment; -/** The files an action works on (menu argument, project view selection or the editor's file). */ +/** The files an action works on (menu, Commit selection, Project view or the editor). */ export function actionTargets(arg: unknown): string[] { const editorPath = getContext().editorPath; return targetPaths(arg, { part: useDeployment.getState().part, selection: projectViewSelection(), + changesSelection: changesViewSelection(), editorPath: typeof editorPath === "string" ? editorPath : null, projectRoot: projectRoot(), }); @@ -61,7 +67,7 @@ function notifyNoServers() { function notifyNoTargets() { notifications().notify({ level: "info", - title: "Select files in the Project view or open a file in the editor", + title: "Select files in the Project view, Commit tool window, or open a file in the editor", group: GROUP, key: "deployment.noTarget", }); diff --git a/src/features/deployment/model.test.ts b/src/features/deployment/model.test.ts index dd542a930..bfe573b5d 100644 --- a/src/features/deployment/model.test.ts +++ b/src/features/deployment/model.test.ts @@ -45,6 +45,32 @@ describe("targetPaths", () => { expect(targetPaths(undefined, { ...ctx, part: "editor", selection: [`${ROOT}/src`] })).toEqual([]); }); + it("prefers the Commit / Local Changes selection over Project view and the editor", () => { + const changes = [`${ROOT}/a.php`, `${ROOT}/b.php`]; + expect( + targetPaths(undefined, { + ...ctx, + part: "project", + selection: [`${ROOT}/only-project`], + editorPath: `${ROOT}/editor.php`, + changesSelection: changes, + }), + ).toEqual(changes); + // Menu arg still wins. + expect( + targetPaths({ paths: [`${ROOT}/menu.php`] }, { ...ctx, changesSelection: changes, part: "project" }), + ).toEqual([`${ROOT}/menu.php`]); + // Empty changes selection falls through to Project / editor. + expect( + targetPaths(undefined, { + ...ctx, + part: "project", + selection: [`${ROOT}/proj`], + changesSelection: [], + }), + ).toEqual([`${ROOT}/proj`]); + }); + it("drops paths outside the project and paths inside selected folders", () => { expect(targetPaths([`${ROOT}/src`, `${ROOT}/src/a.php`, "/elsewhere/b", `${ROOT}/srcx`], ctx)).toEqual([ `${ROOT}/src`, diff --git a/src/features/deployment/model.ts b/src/features/deployment/model.ts index ee31ba4b9..636d28770 100644 --- a/src/features/deployment/model.ts +++ b/src/features/deployment/model.ts @@ -16,24 +16,35 @@ export function pathsFromArg(arg: unknown): string[] | null { } /** - * Files an action works on: the paths passed by a menu, else the project view + * Files an action works on: the paths passed by a menu, else the Commit / Local + * Changes selection while that window is focused, else the project view * selection when it had focus last, else the active editor's file. Paths * outside the project are dropped. */ export function targetPaths( arg: unknown, - ctx: { part: FocusedPart; selection: readonly string[]; editorPath: string | null; projectRoot: string | null }, + ctx: { + part: FocusedPart; + selection: readonly string[]; + /** Absolute paths from the Commit/Local Changes tree while it has focus. */ + changesSelection?: readonly string[]; + editorPath: string | null; + projectRoot: string | null; + }, ): string[] { const passed = pathsFromArg(arg); + const changes = ctx.changesSelection?.length ? [...ctx.changesSelection] : null; const picked = passed ? passed - : ctx.part === "project" && ctx.selection.length - ? [...ctx.selection] - : ctx.editorPath - ? [ctx.editorPath] - : ctx.selection.length && ctx.part !== "editor" - ? [...ctx.selection] - : []; + : changes + ? changes + : ctx.part === "project" && ctx.selection.length + ? [...ctx.selection] + : ctx.editorPath + ? [ctx.editorPath] + : ctx.selection.length && ctx.part !== "editor" + ? [...ctx.selection] + : []; const root = ctx.projectRoot; if (!root) return []; const inside = picked.filter((p) => p === root || p.startsWith(`${root}/`)); diff --git a/src/features/vcs/CommitView.tsx b/src/features/vcs/CommitView.tsx index c8c6f989a..89e56df56 100644 --- a/src/features/vcs/CommitView.tsx +++ b/src/features/vcs/CommitView.tsx @@ -109,7 +109,7 @@ import { showChangesDiff, toLogChanges, type LogChange } from "./logChanges"; import { OperationBanner } from "./operations"; import { runOp } from "./ops"; import { ShelfPanel, loadShelves, useShelf } from "./shelf"; -import { refreshNow, repoName, selectRepo, useVcs } from "./store"; +import { existsOnDisk, refreshNow, repoName, selectRepo, useVcs } from "./store"; import { saveVcsSetting } from "./settingsUi"; import styles from "./CommitView.module.css"; @@ -302,7 +302,7 @@ export function listMenu(id: string, active: boolean, files: readonly FileStatus /** Paths Delete… applies to: only when every selected file is unversioned (versioned ones are rolled back). */ /** The selected files that still exist in the working tree (Delete… removes them from disk). */ /** Whether the change leaves the file in the working tree. */ -const onDisk = (f: FileStatus) => f.unstaged !== "deleted" && !(f.staged === "deleted" && !f.unstaged); +const onDisk = existsOnDisk; export function deletableFiles(nodes: ChangeNode[]): string[] { const files = filesOf(nodes); diff --git a/src/features/vcs/index.ts b/src/features/vcs/index.ts index be23a90a8..a756ef441 100644 --- a/src/features/vcs/index.ts +++ b/src/features/vcs/index.ts @@ -7,6 +7,7 @@ import { onWorkflowSettingsChange, workflowSettings } from "@/platform/workflowS import { editorsFor, registerEditorContribution } from "@/editor/api"; import { notifications, + provideChangesViewSelection, registerEditorKind, registerMenuGroup, registerOverlay, @@ -16,7 +17,7 @@ import { import { executeAction, registerActions } from "@/platform/actions"; import { getContext } from "@/platform/context"; import { lazyComponent } from "@/ui"; -import { registerVcsActions } from "./actions"; +import { commitWindowFocused, registerVcsActions } from "./actions"; import { installChangelists } from "./changelists"; import { registerHistoryActions, trackOperationContext } from "./historyActions"; import { registerLogPaneActions } from "./logPaneActions"; @@ -39,7 +40,7 @@ import { SELECTION_HISTORY_KIND, type SelectionHistoryData } from "./selectionHi import { registerLocalHistoryActions } from "./localHistoryActions"; import { MERGE_KIND, type MergeData } from "./mergeKind"; import { registerMergeActions } from "./mergeActions"; -import { baseName } from "./model"; +import { baseName, stripSlash } from "./model"; import { installCommitChecks, installDiagnosticsTracking } from "./commitChecks"; import { installPreparedMessage, useCommit } from "./commitStore"; import { installDraftRevision, provideCommit } from "./commitSelection"; @@ -49,7 +50,7 @@ import { MergeRebaseWidget } from "./MergeRebaseWidget"; import { installFileConfirmations } from "./confirmations"; import { installIncomingCheck } from "./incoming"; import { closeLogTab, installGitLog, selectGitTab, useGitLog } from "./logStore"; -import { installVcsStore, onConflictsAppeared, onConflictsCleared, useVcs } from "./store"; +import { existsOnDisk, installVcsStore, onConflictsAppeared, onConflictsCleared, useVcs } from "./store"; import { installRootSync } from "./rootSync"; import { tx } from "@/platform/i18n"; import { openOnRemoteActions, registerOpenOnRemote } from "./openOnRemote"; @@ -203,6 +204,21 @@ export function activate(): () => void { installPreparedMessage(), installDraftRevision(), provideCommit(), + // Deployment shortcuts (and similar) use this while Commit / Local Changes is focused. + provideChangesViewSelection(() => { + if (!commitWindowFocused()) return []; + // As the context menu: deleted files have nothing to upload. + const deleted = new Set( + useVcs + .getState() + .status.filter((f) => !existsOnDisk(f)) + .map((f) => f.path), + ); + return useCommit + .getState() + .selection.filter((p) => !deleted.has(p)) + .map(stripSlash); + }), installIncomingCheck(), installFileConfirmations(), installDiffEditorHost(), diff --git a/src/features/vcs/store.ts b/src/features/vcs/store.ts index 8dc5b76b5..584f8a891 100644 --- a/src/features/vcs/store.ts +++ b/src/features/vcs/store.ts @@ -145,6 +145,9 @@ export async function focusRepo(root: string): Promise { if (!useVcs.getState().branchesLoaded) await loadBranches(); } +/** Whether the changed file still exists in the working tree (not deleted there). */ +export const existsOnDisk = (f: FileStatus) => f.unstaged !== "deleted" && !(f.staged === "deleted" && !f.unstaged); + export function conflictedFiles(status: readonly FileStatus[] = useVcs.getState().status): FileStatus[] { return status.filter((f) => effectiveKind(f) === "conflicted"); } diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index b730e5c87..45ced14ee 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -855,6 +855,8 @@ "Builds or starts the project's dev container (devcontainer.json) with the Dev Containers CLI and opens the project in it.": "Builds or starts the project's dev container (devcontainer.json) with the Dev Containers CLI and opens the project in it.", "devcontainer up exited with {status}": "devcontainer up exited with {status}", "Select an item to view details": "Select an item to view details", + "Select files in the Project view, Commit tool window, or open a file in the editor": "Select files in the Project view, Commit tool window, or open a file in the editor", + "Nothing to show": "Nothing to show", "IDE-managed Tomcat runtime directory must not overlap Tomcat home or base directory": "IDE-managed Tomcat runtime directory must not overlap Tomcat home or base directory", "Invalid log stream configuration": "Invalid log stream configuration", diff --git a/src/platform/locales/text/es.json b/src/platform/locales/text/es.json index bce9a51e2..9de9fc00e 100644 --- a/src/platform/locales/text/es.json +++ b/src/platform/locales/text/es.json @@ -4363,7 +4363,6 @@ "Edit the deployment servers and options": "Editar los servidores y opciones de despliegue", "Configuration…": "Configuración…", "No deployment server configured": "No hay ningún servidor de despliegue configurado", - "Select files in the Project view or open a file in the editor": "Seleccione archivos en la vista Proyecto o abra un archivo en el editor", "Upload to": "Subir a", "Download from": "Descargar de", "Sync with Deployed to": "Sincronizar con lo desplegado en", @@ -6137,5 +6136,6 @@ "Plugin update available": "Actualización de plugin disponible", "{length} plugin updates available": "{length} actualizaciones de plugins disponibles", "Updated {updated} plugins": "Se actualizaron {updated} plugins", - "This version is signed with a different key than the installed one, and the publisher's earlier key doesn't vouch for it. Only continue if you know the publisher changed keys.": "Esta versión está firmada con una clave diferente a la instalada y la clave anterior del editor no la avala. Continúe solo si sabe que el editor cambió de clave." + "This version is signed with a different key than the installed one, and the publisher's earlier key doesn't vouch for it. Only continue if you know the publisher changed keys.": "Esta versión está firmada con una clave diferente a la instalada y la clave anterior del editor no la avala. Continúe solo si sabe que el editor cambió de clave.", + "Select files in the Project view, Commit tool window, or open a file in the editor": "Seleccione archivos en la vista Proyecto, la ventana de Confirmación, o abra un archivo en el editor" } diff --git a/src/platform/locales/text/fr.json b/src/platform/locales/text/fr.json index e8ee02bfb..21153c4d1 100644 --- a/src/platform/locales/text/fr.json +++ b/src/platform/locales/text/fr.json @@ -4219,7 +4219,6 @@ "Edit the deployment servers and options": "Modifier les serveurs et les options de déploiement", "Configuration…": "Configuration…", "No deployment server configured": "Aucun serveur de déploiement configuré", - "Select files in the Project view or open a file in the editor": "Sélectionnez des fichiers dans la vue Projet ou ouvrez un fichier dans l'éditeur", "Upload to": "Envoyer vers", "Download from": "Télécharger depuis", "Sync with Deployed to": "Synchroniser avec la version déployée sur", @@ -5765,5 +5764,6 @@ "Keep abstract": "Garder abstrait", "Methods pulled up to an interface are declared abstract there.": "Les méthodes remontées dans une interface y sont déclarées abstraites.", "The file changed; open the dialog again": "Le fichier a changé ; rouvrez la boîte de dialogue", - "Replace preview": "Aperçu du remplacement" + "Replace preview": "Aperçu du remplacement", + "Select files in the Project view, Commit tool window, or open a file in the editor": "Sélectionnez des fichiers dans la vue Projet, la fenêtre Commit, ou ouvrez un fichier dans l'éditeur" } diff --git a/src/platform/locales/text/ko.json b/src/platform/locales/text/ko.json index 386e28941..97675b7e8 100644 --- a/src/platform/locales/text/ko.json +++ b/src/platform/locales/text/ko.json @@ -4425,7 +4425,6 @@ "Edit the deployment servers and options": "배포 서버 및 옵션 편집", "Configuration…": "구성…", "No deployment server configured": "구성된 배포 서버가 없습니다", - "Select files in the Project view or open a file in the editor": "프로젝트 뷰에서 파일을 선택하거나 편집기에서 파일을 여세요", "Upload to": "업로드 대상", "Download from": "다운로드 위치", "Sync with Deployed to": "배포된 항목과 동기화", @@ -6248,5 +6247,6 @@ "Empty: where the service mounts the project.": "비워 두면 서비스가 프로젝트를 마운트하는 위치를 사용합니다.", "The project is mounted here; paths and the working directory are mapped into it.": "프로젝트가 여기에 마운트되며, 경로와 작업 디렉터리가 이 위치로 매핑됩니다.", "Published ports": "게시된 포트", - "Run as the image's user, not the project folder's owner (Linux)": "프로젝트 폴더 소유자가 아닌 이미지의 사용자로 실행(Linux)" + "Run as the image's user, not the project folder's owner (Linux)": "프로젝트 폴더 소유자가 아닌 이미지의 사용자로 실행(Linux)", + "Select files in the Project view, Commit tool window, or open a file in the editor": "프로젝트 뷰나 커밋 도구 창에서 파일을 선택하거나 편집기에서 파일을 여세요" } diff --git a/src/platform/locales/text/pl.json b/src/platform/locales/text/pl.json index 86239faee..761694715 100644 --- a/src/platform/locales/text/pl.json +++ b/src/platform/locales/text/pl.json @@ -4316,7 +4316,6 @@ "Edit the deployment servers and options": "Edytuj serwery wdrażania i opcje", "Configuration…": "Konfiguracja…", "No deployment server configured": "Brak skonfigurowanego serwera wdrażania", - "Select files in the Project view or open a file in the editor": "Wybierz pliki w widoku Projektu lub otwórz plik w edytorze", "Upload to": "Prześlij do", "Download from": "Pobierz z", "Sync with Deployed to": "Synchronizuj z wdrożeniem na", @@ -5943,5 +5942,6 @@ "Back to Changed Files": "Powrót do zmienionych plików", "Default (the module's JDK)": "Domyślnie (zestaw JDK modułu)", "Use classpath of module": "Użyj ścieżki klas modułu", - "Find by main class": "Znajdź według klasy głównej" + "Find by main class": "Znajdź według klasy głównej", + "Select files in the Project view, Commit tool window, or open a file in the editor": "Wybierz pliki w widoku Projektu, oknie Commit lub otwórz plik w edytorze" } diff --git a/src/platform/locales/text/pt.json b/src/platform/locales/text/pt.json index 514acfa57..2046f7789 100644 --- a/src/platform/locales/text/pt.json +++ b/src/platform/locales/text/pt.json @@ -4329,7 +4329,6 @@ "Edit the deployment servers and options": "Editar os servidores e opções de implantação", "Configuration…": "Configuração…", "No deployment server configured": "Nenhum servidor de implantação configurado", - "Select files in the Project view or open a file in the editor": "Selecione arquivos na visualização do projeto ou abra um arquivo no editor", "Upload to": "Fazer upload para", "Download from": "Fazer download de", "Sync with Deployed to": "Sincronizar com implantado em", @@ -5957,5 +5956,6 @@ "Back to Changed Files": "Voltar para Arquivos alterados", "Default (the module's JDK)": "Padrão (JDK do módulo)", "Use classpath of module": "Usar classpath do módulo", - "Find by main class": "Localizar por classe principal" + "Find by main class": "Localizar por classe principal", + "Select files in the Project view, Commit tool window, or open a file in the editor": "Selecione arquivos na visualização do projeto, na janela Commit, ou abra um arquivo no editor" } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 6ab004d77..7e63b5c57 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -5219,7 +5219,8 @@ "Edit the deployment servers and options": "编辑部署服务器和选项", "Configuration…": "配置…", "No deployment server configured": "未配置部署服务器", - "Select files in the Project view or open a file in the editor": "请在项目视图中选择文件,或在编辑器中打开文件", + "Select files in the Project view, Commit tool window, or open a file in the editor": "请在项目视图或提交工具窗口中选择文件,或在编辑器中打开文件", + "Upload to": "上传到", "Download from": "下载自", "Sync with Deployed to": "与已部署的同步", diff --git a/src/workbench/contributions.ts b/src/workbench/contributions.ts index d408fd14e..e4f1a2d85 100644 --- a/src/workbench/contributions.ts +++ b/src/workbench/contributions.ts @@ -1464,6 +1464,20 @@ export function provideProjectViewSelection(get: () => string[]): () => void { /** Selected project view paths (absolute); empty without a project view. */ export const projectViewSelection = (): string[] => projectSelection?.() ?? []; +// Commit / Local Changes selection while that tool window has focus. Provided by +// features/vcs so Deployment (and similar) shortcuts see multi-file picks there. +let changesSelection: (() => string[]) | undefined; + +export function provideChangesViewSelection(get: () => string[]): () => void { + changesSelection = get; + return () => { + if (changesSelection === get) changesSelection = undefined; + }; +} + +/** Selected change-tree paths (absolute) while Commit/Local Changes is focused. */ +export const changesViewSelection = (): string[] => changesSelection?.() ?? []; + /** The project view node the user last selected; `dir` decides the icon and popup of the last crumb. */ export interface ProjectViewLead { path: string;