File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,7 +68,13 @@ const parseHref = function(dom) {
6868 return ref
6969}
7070
71+ const isLinkToSelfWithHash = function ( href ) {
72+ const locationNoHash = window . location . origin + window . location . pathname + window . location . search
73+ return href ?. startsWith ( '#' ) || href ?. startsWith ( locationNoHash + '#' )
74+ }
75+
7176export {
7277 domHref ,
7378 parseHref ,
79+ isLinkToSelfWithHash ,
7480}
Original file line number Diff line number Diff line change 2121 */
2222
2323import { Node , isNodeActive , getNodeType } from '@tiptap/core'
24- import { domHref , parseHref } from './../helpers/links.js'
24+ import { domHref , parseHref , isLinkToSelfWithHash } from './../helpers/links.js'
2525import { VueNodeViewRenderer } from '@tiptap/vue-2'
2626
2727import Preview from './Preview.vue'
@@ -149,7 +149,7 @@ function previewPossible({ selection }) {
149149 return false
150150 }
151151 const href = extractHref ( $from . parent . firstChild )
152- if ( ! href || href . startsWith ( '#' ) ) {
152+ if ( ! href || isLinkToSelfWithHash ( href ) ) {
153153 return false
154154 }
155155 return true
Original file line number Diff line number Diff line change 2020 *
2121 */
2222
23+ import { isLinkToSelfWithHash } from '../helpers/links.js'
24+
2325/**
2426 * Get the link mark applied at the current selection or next to it.
2527 *
@@ -78,7 +80,7 @@ function linkMark(node) {
7880 return undefined
7981 }
8082 // Don't open link bubble for anchor links
81- if ( linkMark . attrs . href . startsWith ( '#' ) ) {
83+ if ( isLinkToSelfWithHash ( linkMark . attrs . href ) ) {
8284 return undefined
8385 } else {
8486 return linkMark
Original file line number Diff line number Diff line change 2323import { Plugin , PluginKey } from '@tiptap/pm/state'
2424import LinkBubblePluginView from './LinkBubblePluginView.js'
2525import { activeLinkFromSelection } from './linkHelpers.js'
26+ import { isLinkToSelfWithHash } from '../helpers/links.js'
2627
2728// Commands
2829
@@ -167,7 +168,7 @@ export function linkClicking() {
167168 const linkEl = event . target . closest ( 'a' )
168169 if ( event . button === 0 && linkEl ) {
169170 event . preventDefault ( )
170- if ( linkEl . attributes . href ?. value ?. startsWith ( '#' ) ) {
171+ if ( isLinkToSelfWithHash ( linkEl . attributes . href ?. value ) ) {
171172 // Open anchor links directly
172173 location . href = linkEl . attributes . href . value
173174 } else if ( event . ctrlKey || event . metaKey ) {
You can’t perform that action at this time.
0 commit comments