Skip to content

Commit 528cdbb

Browse files
committed
open links with cmd + click
1 parent ed42e6c commit 528cdbb

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed

packages/editor/lib/plugins/cleanup.js

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function overlap(a, b) {
1414
return a.from <= b.to && a.to >= b.from
1515
}
1616

17+
// TODO: this plugin is getting big, in terms of responsibility, break it down
1718
export const cleanupPlugin = ViewPlugin.define(
1819
(view) => {
1920
let _data = createDecorations(view)
@@ -39,7 +40,6 @@ export const cleanupPlugin = ViewPlugin.define(
3940
const { decorations, selection } = v
4041
return decorations.update({
4142
filter: (_from, _to, deco) => {
42-
// console.log({ reveal: deco.spec.revealRange })
4343
const revealRange = deco.spec.revealRange
4444
if (revealRange) {
4545
return !overlap(revealRange, selection)
@@ -49,27 +49,21 @@ export const cleanupPlugin = ViewPlugin.define(
4949
})
5050
},
5151
eventHandlers: {
52+
// cmd+click to open links
5253
mousedown(e, view) {
5354
const pos = view.posAtCoords(e)
5455
if (!pos) return
56+
if (!e.metaKey) return
5557
this.decorations.between(pos, pos, (_from, _to, deco) => {
56-
if ('tagName' in deco && deco.tagName === 'a' && 'attrs' in deco) {
58+
const { tagName, attributes } = deco.spec
59+
if (tagName === 'a' && attributes) {
5760
e.preventDefault()
58-
window.open(deco.attrs?.href, '_blank')
61+
// TODO: is it possible to make it a real link?
62+
// I guess that'd be difficult because it's a fucking editor
63+
window.open(deco.spec.attributes.href, '_blank')
5964
return false
6065
}
61-
// console.log({ from, to, deco })
62-
// if (deco.spec.revealRange) {
63-
// view.dispatch({
64-
// selection: {
65-
// anchor: deco.spec.revealRange.from,
66-
// head: deco.spec.revealRange.to,
67-
// },
68-
// })
69-
// }
7066
})
71-
// this.posAtCoords({ x: e.clientX, y: e.clientY })
72-
// this.decorations.
7367
},
7468
},
7569
}
@@ -112,21 +106,6 @@ function createDecorations(view, decorations = Decoration.none) {
112106

113107
if (node.name === 'link') {
114108
linkRange = { from: node.from, to: node.to }
115-
decorations = decorations.update({
116-
add: [
117-
// TODO: get the real url
118-
Decoration.mark({
119-
tagName: 'a',
120-
attributes: { class: 'cm-link', href: 'https://google.com' },
121-
}).range(node.from, node.to),
122-
// mark is not working
123-
// https://discuss.codemirror.net/t/decorated-a-tags-nor-treated-as-links-by-browser/3664
124-
// Decoration.widget({
125-
// widget: new LinkWidget('https://google.com'),
126-
// side: 1,
127-
// }).range(node.to),
128-
],
129-
})
130109
}
131110

132111
if (node.name === 'url') {

packages/lezer/lib/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import { Parser, NodeSet } from '@lezer/common'
1313
import { parseContext } from './context.js'
14-
export * as props from './props.js'
1514
import { nodeSet } from './nodes.js'
1615
export { tags } from './nodes.js'
1716

0 commit comments

Comments
 (0)