From 01c6d19c0f6c04c19d30bd6b74baf4a3e23f22b8 Mon Sep 17 00:00:00 2001 From: purocean Date: Mon, 26 Aug 2019 12:47:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/QuickOpen.vue | 22 ++++++++++------------ frontend/src/store/app.js | 8 ++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/QuickOpen.vue b/frontend/src/components/QuickOpen.vue index 609d6c24..ebb3a2b3 100644 --- a/frontend/src/components/QuickOpen.vue +++ b/frontend/src/components/QuickOpen.vue @@ -63,9 +63,11 @@ export default { } }, 500) }, - mounted () { + async mounted () { this.$refs.input.focus() this.updateDataSource() + await this.$store.dispatch('app/fetchMarkedFiles') + this.updateDataSource() }, methods: { travelFiles (tree) { @@ -136,12 +138,7 @@ export default { if (this.currentTab === 'file') { this.list = this.files } else if (this.currentTab === 'marked') { - this.list = null - file.markedFiles().then(result => { - if (this.currentTab === 'marked') { - this.list = result.map(x => ({ ...x, name: file.basename(x.path) })) - } - }) + this.list = this.markedFiles } else if (this.currentTab === 'search') { this.list = null this.searchWithDebounce(this.searchText.trim(), data => { @@ -150,18 +147,16 @@ export default { } }) } - - this.$nextTick(this.highlightText(this.searchText.trim())) }, updateSelected (item = null) { - if (this.list === null) { + if (this.dataList === null) { return } if (item) { this.selected = item } else { - this.selected = this.list.length > 0 ? this.list[0] : null + this.selected = this.dataList.length > 0 ? this.dataList[0] : null } this.$nextTick(() => { @@ -227,6 +222,9 @@ export default { searchText () { this.updateDataSource() }, + dataList () { + this.$nextTick(() => this.highlightText(this.searchText.trim())) + }, currentTab () { this.list = null this.$refs.input.focus() @@ -234,7 +232,7 @@ export default { } }, computed: { - ...mapState('app', ['currentRepo', 'recentOpenTime', 'tree']), + ...mapState('app', ['currentRepo', 'recentOpenTime', 'tree', 'markedFiles']), files () { return this.travelFiles(this.tree || []) }, diff --git a/frontend/src/store/app.js b/frontend/src/store/app.js index b4131a84..833b4a63 100644 --- a/frontend/src/store/app.js +++ b/frontend/src/store/app.js @@ -52,8 +52,12 @@ export default { line: 0, column: 0 }, + markedFiles: [], }, mutations: { + setMarkedFiles (state, files) { + state.markedFiles = files + }, setPasswordHash (state, { file, passwordHash }) { if (file && passwordHash) { state.passwordHash = { ...state.passwordHash, [`${file.repo}|${file.path}`]: passwordHash } @@ -108,6 +112,10 @@ export default { getters: { }, actions: { + async fetchMarkedFiles ({ commit }) { + const files = (await file.markedFiles()).map(x => ({ ...x, name: file.basename(x.path) })) + commit('setMarkedFiles', files) + }, async fetchRepositories ({ commit }) { const data = await file.fetchRepositories() commit('setRepositories', data)