diff options
author | Jonas <jonas@freesources.org> | 2022-07-04 20:30:15 +0300 |
---|---|---|
committer | max-nextcloud (Rebase PR Action) <max-nextcloud@users.noreply.github.com> | 2022-07-05 06:50:33 +0300 |
commit | bc7fa678d48a284b221b937a13843ef4c347b6d4 (patch) | |
tree | 5349b7d76549b9ebd4dc6e81a784b6a161385402 | |
parent | 5c93bbe1d874d2d3498abb26ad3cc49c0c1c62ba (diff) |
Move click conditions from default openClick handler to link plugin
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>
-rw-r--r-- | src/helpers/links.js | 37 | ||||
-rw-r--r-- | src/plugins/link.js | 7 |
2 files changed, 23 insertions, 21 deletions
diff --git a/src/helpers/links.js b/src/helpers/links.js index 81df51444..007c9f791 100644 --- a/src/helpers/links.js +++ b/src/helpers/links.js @@ -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) diff --git a/src/plugins/link.js b/src/plugins/link.js index 7b3f7eb49..4002dc0de 100644 --- a/src/plugins/link.js +++ b/src/plugins/link.js @@ -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) + } }, }, }) |