Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remember last directory for linking to files to directories
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux authored and mejo- committed Oct 24, 2022
commit 69d4b5ac9994f67b13e015d164c3dbbbc32920bb
19 changes: 18 additions & 1 deletion src/components/Menu/ActionInsertLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActionInput from '@nextcloud/vue/dist/Components/NcActionInput.js'
import { FilePicker, FilePickerType } from '@nextcloud/dialogs'

import { getMarkAttributes, isActive } from '@tiptap/core'

Expand Down Expand Up @@ -103,6 +104,7 @@ export default {
return {
href: null,
isInputMode: false,
startPath: null,
}
},
computed: {
Expand All @@ -116,15 +118,30 @@ export default {
* Triggered by the "link file" button
*/
linkFile() {
if (this.startPath === null) {
this.startPath = this.$file.relativePath.split('/').slice(0, -1).join('/')
}

const filePicker = new FilePicker(
t('text', 'Select file or folder to link to'),
false, // multiselect
[], // mime filter
true, // modal
FilePickerType.Choose, // type
true, // directories
this.startPath // path
)

filePicker.pick().then((file) => {
const client = OC.Files.getClient()
client.getFileInfo(file).then((_status, fileInfo) => {
const path = optimalPath(this.$file.relativePath, `${fileInfo.path}/${fileInfo.name}`)
const encodedPath = path.split('/').map(encodeURIComponent).join('/') + (fileInfo.type === 'dir' ? '/' : '')
const href = `${encodedPath}?fileId=${fileInfo.id}`
this.setLink(href, fileInfo.name)
this.startPath = fileInfo.path + (fileInfo.type === 'dir' ? `/${fileInfo.name}/` : '')
})
}, false, [], true, 1, startPath, { allowDirectoryChooser: true })
})
},
/**
* Allow user to enter an URL manually
Expand Down