Skip to content

Commit

Permalink
Move click conditions from default openClick handler to link plugin
Browse files Browse the repository at this point in the history
We only want our custom link handlers (either the default from Text app
or a further customized one, e.g. from Collectives app) to happen if the
first mouse button is used, Ctrl key is not pressed and the link points
to a local link.

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Jul 6, 2022
1 parent 1dc77b4 commit 77a6864
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
37 changes: 17 additions & 20 deletions src/helpers/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,25 @@ const parseHref = function(dom) {

const openLink = function(event, _attrs) {
const linkElement = event.target.closest('a')
event.stopPropagation()
const htmlHref = linkElement.href
if (event.button === 0 && !event.ctrlKey && htmlHref.startsWith(window.location.origin)) {
const query = OC.parseQueryString(htmlHref)
const fragment = OC.parseQueryString(htmlHref.split('#').pop())
if (query.dir && fragment.relPath) {
const filename = fragment.relPath.split('/').pop()
const path = `${query.dir}/${filename}`
document.title = `${filename} - ${OC.theme.title}`
if (window.location.pathname.match(/apps\/files\/$/)) {
// The files app still lacks a popState handler
// to allow for using the back button
// OC.Util.History.pushState('', htmlHref)
}
OCA.Viewer.open({ path })
return
}
if (query.fileId) {
// open the direct file link
window.open(generateUrl(`/f/${query.fileId}`))
return
const query = OC.parseQueryString(htmlHref)
const fragment = OC.parseQueryString(htmlHref.split('#').pop())
if (query.dir && fragment.relPath) {
const filename = fragment.relPath.split('/').pop()
const path = `${query.dir}/${filename}`
document.title = `${filename} - ${OC.theme.title}`
if (window.location.pathname.match(/apps\/files\/$/)) {
// The files app still lacks a popState handler
// to allow for using the back button
// OC.Util.History.pushState('', htmlHref)
}
OCA.Viewer.open({ path })
return
}
if (query.fileId) {
// open the direct file link
window.open(generateUrl(`/f/${query.fileId}`))
return
}
if (!markdownit.validateLink(htmlHref)) {
console.error('Invalid link', htmlHref)
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ const clickHandler = ({ editor, type, onClick }) => {
console.debug(link)
return false
}
return onClick?.(event, link.attrs)

// We use custom onClick handler only for left clicks
if (event.button === 0 && !event.ctrlKey) {
event.stopPropagation()
return onClick?.(event, link.attrs)
}
},
},
})
Expand Down

0 comments on commit 77a6864

Please sign in to comment.