Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/marks
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2020-06-16 16:28:08 +0300
committerAzul <azul@riseup.net>2020-08-11 16:41:39 +0300
commit8640eaa2ff4264355930d83679fb21939095f32d (patch)
tree4740c734bd744956e28a1683b928a61a5462c0f8 /src/marks
parent59182ba93f808ff3ff64331632747196b6a9302c (diff)
open local links in same tab
When navigating between different text documents one does not expect to open new windows all the time. Next steps: * open in new tab on middle click. Signed-off-by: Azul <azul@riseup.net>
Diffstat (limited to 'src/marks')
-rw-r--r--src/marks/index.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/marks/index.js b/src/marks/index.js
index 3a3d6c5f2..cb8d7b091 100644
--- a/src/marks/index.js
+++ b/src/marks/index.js
@@ -21,6 +21,8 @@
*/
import { Bold, Italic as TipTapItalic, Strike as TipTapStrike, Link as TipTapLink } from 'tiptap-extensions'
+import { Plugin } from 'tiptap'
+import { getMarkAttrs } from 'tiptap-utils'
import { domHref, parseHref } from './../helpers/links'
/**
@@ -102,6 +104,33 @@ class Link extends TipTapLink {
}
}
+ get plugins() {
+ if (!this.options.openOnClick) {
+ return []
+ }
+
+ return [
+ new Plugin({
+ props: {
+ handleClick: (view, pos, event) => {
+ const { schema } = view.state
+ const attrs = getMarkAttrs(view.state, schema.marks.link)
+
+ if (attrs.href && event.target instanceof HTMLAnchorElement) {
+ event.stopPropagation()
+ const htmlHref = event.target.attributes.href.value
+ if (htmlHref.match(/^\?/)) {
+ window.location = htmlHref
+ } else {
+ window.open(attrs.href)
+ }
+ }
+ },
+ },
+ }),
+ ]
+ }
+
}
/** Strike is currently unsupported by prosemirror-markdown */