Skip to content

Commit 4d5939a

Browse files
AWolf81Rokt33r
authored andcommitted
address requested changes - tag link & redundant line
1 parent 2695f62 commit 4d5939a

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

extra_scripts/codemirror/addon/hyperlink/hyperlink.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;(function(mod) {
1+
;(function (mod) {
22
if (typeof exports === 'object' && typeof module === 'object') {
33
// Common JS
44
mod(require('../codemirror/lib/codemirror'))
@@ -9,13 +9,13 @@
99
// Plain browser env
1010
mod(CodeMirror)
1111
}
12-
})(function(CodeMirror) {
12+
})(function (CodeMirror) {
1313
'use strict'
1414

1515
const shell = require('electron').shell
1616
const remote = require('electron').remote
1717
const eventEmitter = {
18-
emit: function() {
18+
emit: function () {
1919
remote.getCurrentWindow().webContents.send.apply(null, arguments)
2020
}
2121
}
@@ -25,7 +25,7 @@
2525
const modifier = macOS ? 'metaKey' : 'ctrlKey'
2626

2727
class HyperLink {
28-
constructor(cm) {
28+
constructor (cm) {
2929
this.cm = cm
3030
this.lineDiv = cm.display.lineDiv
3131

@@ -61,7 +61,7 @@
6161
passive: true
6262
})
6363
}
64-
getUrl(el) {
64+
getUrl (el) {
6565
const className = el.className.split(' ')
6666

6767
if (className.indexOf('cm-url') !== -1) {
@@ -74,7 +74,7 @@
7474

7575
return null
7676
}
77-
specialLinkHandler(e, rawHref, linkHash) {
77+
specialLinkHandler (e, rawHref, linkHash) {
7878
const isStartWithHash = rawHref[0] === '#'
7979

8080
const extractIdRegex = /file:\/\/.*main.?\w*.html#/ // file://path/to/main(.development.)html
@@ -121,14 +121,14 @@
121121
return
122122
}
123123

124-
const regexIsTagLink = /^:tag:#([\w]+)$/
124+
const regexIsTagLink = /^:tag:([\w]+)$/
125125
if (regexIsTagLink.test(rawHref)) {
126126
const tag = rawHref.match(regexIsTagLink)[1]
127127
eventEmitter.emit('dispatch:push', `/tags/${encodeURIComponent(tag)}`)
128128
return
129129
}
130130
}
131-
onMouseDown(e) {
131+
onMouseDown (e) {
132132
const { target } = e
133133
if (!e[modifier]) {
134134
return
@@ -142,8 +142,6 @@
142142
parser.href = rawHref
143143
const { href, hash } = parser
144144

145-
if (!rawHref) return // not checked href because parser will create file://... string for [empty link]()
146-
147145
const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
148146

149147
this.specialLinkHandler(target, rawHref, linkHash)
@@ -157,7 +155,7 @@
157155
shell.openExternal(url)
158156
}
159157
}
160-
onMouseEnter(e) {
158+
onMouseEnter (e) {
161159
const { target } = e
162160

163161
const url = this.getUrl(target)
@@ -174,7 +172,7 @@
174172
this.showInfo(target)
175173
}
176174
}
177-
onMouseLeave(e) {
175+
onMouseLeave (e) {
178176
if (this.tooltip.parentElement === this.lineDiv) {
179177
e.target.classList.remove(
180178
'CodeMirror-activeline-background',
@@ -184,7 +182,7 @@
184182
this.lineDiv.removeChild(this.tooltip)
185183
}
186184
}
187-
onMouseMove(e) {
185+
onMouseMove (e) {
188186
if (this.tooltip.parentElement === this.lineDiv) {
189187
if (e[modifier]) {
190188
e.target.classList.add('CodeMirror-hyperlink')
@@ -193,7 +191,7 @@
193191
}
194192
}
195193
}
196-
showInfo(relatedTo) {
194+
showInfo (relatedTo) {
197195
const b1 = relatedTo.getBoundingClientRect()
198196
const b2 = this.lineDiv.getBoundingClientRect()
199197
const tdiv = this.tooltip

0 commit comments

Comments
 (0)