feat: remain in the same position when back from a subfolder

This commit is contained in:
niubility000 2024-03-23 18:08:35 +08:00 committed by GitHub
parent 5f64bc711a
commit 08458da31c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 18 deletions

View File

@ -1,9 +1,5 @@
<template> <template>
<div <div id="editor-container" @touchmove.prevent.stop @wheel.prevent.stop>
id="editor-container"
@touchmove.prevent.stop
@wheel.prevent.stop
>
<header-bar> <header-bar>
<action icon="close" :label="$t('buttons.close')" @action="close()" /> <action icon="close" :label="$t('buttons.close')" @action="close()" />
<title>{{ req.name }}</title> <title>{{ req.name }}</title>
@ -28,7 +24,6 @@ import { mapState } from "vuex";
import { files as api } from "@/api"; import { files as api } from "@/api";
import { theme } from "@/utils/constants"; import { theme } from "@/utils/constants";
import buttons from "@/utils/buttons"; import buttons from "@/utils/buttons";
import url from "@/utils/url";
import { version as ace_version } from "ace-builds"; import { version as ace_version } from "ace-builds";
import ace from "ace-builds/src-min-noconflict/ace.js"; import ace from "ace-builds/src-min-noconflict/ace.js";
@ -148,8 +143,7 @@ export default {
this.$store.commit("updateRequest", {}); this.$store.commit("updateRequest", {});
let uri = url.removeLastDir(this.$route.path) + "/"; history.back();
this.$router.push({ path: uri });
}, },
}, },
}; };

View File

@ -383,9 +383,12 @@ export default {
}, },
watch: { watch: {
req: function () { req: function () {
if (window.sessionStorage.getItem("listFrozen") !=="true" && window.sessionStorage.getItem("modified") !=="true"){ if (
window.sessionStorage.getItem("listFrozen") !== "true" &&
window.sessionStorage.getItem("modified") !== "true"
) {
// Reset the show value // Reset the show value
this.showLimit = 50; this.showLimit = this.req.numDirs + this.req.numFiles;
// Ensures that the listing is displayed // Ensures that the listing is displayed
Vue.nextTick(() => { Vue.nextTick(() => {
@ -394,11 +397,21 @@ export default {
// Fill and fit the window with listing items // Fill and fit the window with listing items
this.fillWindow(true); this.fillWindow(true);
if (window.sessionStorage.getItem(this.$route.path)) {
document.documentElement.scrollTop = JSON.parse(
window.sessionStorage.getItem(this.$route.path)
)[0];
if (!this.isMobile)
this.addSelected(
JSON.parse(window.sessionStorage.getItem(this.$route.path))[1]
);
window.sessionStorage.removeItem(this.$route.path);
}
}); });
} }
if (this.req.isDir) { if (this.req.isDir) {
window.sessionStorage.setItem("listFrozen", "false"); window.sessionStorage.setItem("listFrozen", "false");
window.sessionStorage.setItem("modified", "false"); window.sessionStorage.setItem("modified", "false");
} }
}, },
}, },
@ -882,9 +895,13 @@ export default {
const windowHeight = window.innerHeight; const windowHeight = window.innerHeight;
// Quantity of items needed to fill 2x of the window height // Quantity of items needed to fill 2x of the window height
const showQuantity = Math.ceil( const showQuantity = window.sessionStorage.getItem(this.$route.path)
(windowHeight + windowHeight * 2) / this.itemWeight ? Math.ceil(
); (JSON.parse(window.sessionStorage.getItem(this.$route.path))[0] +
windowHeight * 2) /
this.itemWeight
)
: Math.ceil((windowHeight + windowHeight * 2) / this.itemWeight);
// Less items to display than current // Less items to display than current
if (this.showLimit > showQuantity && !fit) return; if (this.showLimit > showQuantity && !fit) return;

View File

@ -1,12 +1,12 @@
<template> <template>
<div <div
id="previewer" id="previewer"
@touchmove.prevent.stop @touchmove.prevent.stop
@wheel.prevent.stop @wheel.prevent.stop
@mousemove="toggleNavigation" @mousemove="toggleNavigation"
@touchstart="toggleNavigation" @touchstart="toggleNavigation"
> >
<header-bar v-if="showNav"> <header-bar v-if="showNav">
<action icon="close" :label="$t('buttons.close')" @action="close()" /> <action icon="close" :label="$t('buttons.close')" @action="close()" />
<title>{{ name }}</title> <title>{{ name }}</title>
<action <action
@ -346,8 +346,7 @@ export default {
close() { close() {
this.$store.commit("updateRequest", {}); this.$store.commit("updateRequest", {});
let uri = url.removeLastDir(this.$route.path) + "/"; history.back();
this.$router.push({ path: uri });
}, },
download() { download() {
window.open(this.downloadUrl); window.open(this.downloadUrl);