From cbeec6d225691723c4750d7f84122ebb14d662bf Mon Sep 17 00:00:00 2001 From: Ramires Viana <59319979+ramiresviana@users.noreply.github.com> Date: Sun, 27 Jul 2025 08:03:00 -0300 Subject: [PATCH] feat: select item on file list after navigating back (#5329) --- frontend/src/components/prompts/Copy.vue | 4 +- frontend/src/components/prompts/Delete.vue | 11 +++- .../prompts/DiscardEditorChanges.vue | 16 ++--- frontend/src/components/prompts/Move.vue | 5 +- frontend/src/components/prompts/Rename.vue | 6 +- frontend/src/css/base.css | 3 + frontend/src/css/styles.css | 3 + frontend/src/stores/file.ts | 2 + frontend/src/views/Files.vue | 50 ++++++++++------ frontend/src/views/files/Editor.vue | 48 ++++++++------- frontend/src/views/files/FileListing.vue | 58 +++++++++++++------ frontend/src/views/files/Preview.vue | 15 ++--- frontend/tsconfig.tsc.json | 1 + 13 files changed, 143 insertions(+), 79 deletions(-) diff --git a/frontend/src/components/prompts/Copy.vue b/frontend/src/components/prompts/Copy.vue index 43eff671..9b5e4c63 100644 --- a/frontend/src/components/prompts/Copy.vue +++ b/frontend/src/components/prompts/Copy.vue @@ -62,6 +62,7 @@ import FileList from "./FileList.vue"; import { files as api } from "@/api"; import buttons from "@/utils/buttons"; import * as upload from "@/utils/upload"; +import { removePrefix } from "@/api/utils"; export default { name: "copy", @@ -76,7 +77,7 @@ export default { computed: { ...mapState(useFileStore, ["req", "selected"]), ...mapState(useAuthStore, ["user"]), - ...mapWritableState(useFileStore, ["reload"]), + ...mapWritableState(useFileStore, ["reload", "preselect"]), }, methods: { ...mapActions(useLayoutStore, ["showHover", "closeHovers"]), @@ -100,6 +101,7 @@ export default { .copy(items, overwrite, rename) .then(() => { buttons.success("copy"); + this.preselect = removePrefix(items[0].to); if (this.$route.path === this.dest) { this.reload = true; diff --git a/frontend/src/components/prompts/Delete.vue b/frontend/src/components/prompts/Delete.vue index 39fc2511..aa2482ce 100644 --- a/frontend/src/components/prompts/Delete.vue +++ b/frontend/src/components/prompts/Delete.vue @@ -48,16 +48,15 @@ export default { "selectedCount", "req", "selected", - "currentPrompt", ]), - ...mapWritableState(useFileStore, ["reload"]), + ...mapState(useLayoutStore, ["currentPrompt"]), + ...mapWritableState(useFileStore, ["reload", "preselect"]), }, methods: { ...mapActions(useLayoutStore, ["closeHovers"]), submit: async function () { buttons.loading("delete"); - window.sessionStorage.setItem("modified", "true"); try { if (!this.isListing) { await api.remove(this.$route.path); @@ -81,6 +80,12 @@ export default { await Promise.all(promises); buttons.success("delete"); + + const nearbyItem = + this.req.items[Math.max(0, Math.min(this.selected) - 1)]; + + this.preselect = nearbyItem?.path; + this.reload = true; } catch (e) { buttons.done("delete"); diff --git a/frontend/src/components/prompts/DiscardEditorChanges.vue b/frontend/src/components/prompts/DiscardEditorChanges.vue index 69963674..4c1e5faa 100644 --- a/frontend/src/components/prompts/DiscardEditorChanges.vue +++ b/frontend/src/components/prompts/DiscardEditorChanges.vue @@ -17,7 +17,7 @@