|
1 |
| -;(function(mod) { |
| 1 | +;(function (mod) { |
2 | 2 | if (typeof exports === 'object' && typeof module === 'object') {
|
3 | 3 | // Common JS
|
4 | 4 | mod(require('../codemirror/lib/codemirror'))
|
|
9 | 9 | // Plain browser env
|
10 | 10 | mod(CodeMirror)
|
11 | 11 | }
|
12 |
| -})(function(CodeMirror) { |
| 12 | +})(function (CodeMirror) { |
13 | 13 | 'use strict'
|
14 | 14 |
|
15 | 15 | const shell = require('electron').shell
|
16 | 16 | const remote = require('electron').remote
|
17 | 17 | const eventEmitter = {
|
18 |
| - emit: function() { |
| 18 | + emit: function () { |
19 | 19 | remote.getCurrentWindow().webContents.send.apply(null, arguments)
|
20 | 20 | }
|
21 | 21 | }
|
|
25 | 25 | const modifier = macOS ? 'metaKey' : 'ctrlKey'
|
26 | 26 |
|
27 | 27 | class HyperLink {
|
28 |
| - constructor(cm) { |
| 28 | + constructor (cm) { |
29 | 29 | this.cm = cm
|
30 | 30 | this.lineDiv = cm.display.lineDiv
|
31 | 31 |
|
|
61 | 61 | passive: true
|
62 | 62 | })
|
63 | 63 | }
|
64 |
| - getUrl(el) { |
| 64 | + getUrl (el) { |
65 | 65 | const className = el.className.split(' ')
|
66 | 66 |
|
67 | 67 | if (className.indexOf('cm-url') !== -1) {
|
|
74 | 74 |
|
75 | 75 | return null
|
76 | 76 | }
|
77 |
| - specialLinkHandler(e, rawHref, linkHash) { |
| 77 | + specialLinkHandler (e, rawHref, linkHash) { |
78 | 78 | const isStartWithHash = rawHref[0] === '#'
|
79 | 79 |
|
80 | 80 | const extractIdRegex = /file:\/\/.*main.?\w*.html#/ // file://path/to/main(.development.)html
|
|
121 | 121 | return
|
122 | 122 | }
|
123 | 123 |
|
124 |
| - const regexIsTagLink = /^:tag:#([\w]+)$/ |
| 124 | + const regexIsTagLink = /^:tag:([\w]+)$/ |
125 | 125 | if (regexIsTagLink.test(rawHref)) {
|
126 | 126 | const tag = rawHref.match(regexIsTagLink)[1]
|
127 | 127 | eventEmitter.emit('dispatch:push', `/tags/${encodeURIComponent(tag)}`)
|
128 | 128 | return
|
129 | 129 | }
|
130 | 130 | }
|
131 |
| - onMouseDown(e) { |
| 131 | + onMouseDown (e) { |
132 | 132 | const { target } = e
|
133 | 133 | if (!e[modifier]) {
|
134 | 134 | return
|
|
142 | 142 | parser.href = rawHref
|
143 | 143 | const { href, hash } = parser
|
144 | 144 |
|
145 |
| - if (!rawHref) return // not checked href because parser will create file://... string for [empty link]() |
146 |
| - |
147 | 145 | const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
|
148 | 146 |
|
149 | 147 | this.specialLinkHandler(target, rawHref, linkHash)
|
|
157 | 155 | shell.openExternal(url)
|
158 | 156 | }
|
159 | 157 | }
|
160 |
| - onMouseEnter(e) { |
| 158 | + onMouseEnter (e) { |
161 | 159 | const { target } = e
|
162 | 160 |
|
163 | 161 | const url = this.getUrl(target)
|
|
174 | 172 | this.showInfo(target)
|
175 | 173 | }
|
176 | 174 | }
|
177 |
| - onMouseLeave(e) { |
| 175 | + onMouseLeave (e) { |
178 | 176 | if (this.tooltip.parentElement === this.lineDiv) {
|
179 | 177 | e.target.classList.remove(
|
180 | 178 | 'CodeMirror-activeline-background',
|
|
184 | 182 | this.lineDiv.removeChild(this.tooltip)
|
185 | 183 | }
|
186 | 184 | }
|
187 |
| - onMouseMove(e) { |
| 185 | + onMouseMove (e) { |
188 | 186 | if (this.tooltip.parentElement === this.lineDiv) {
|
189 | 187 | if (e[modifier]) {
|
190 | 188 | e.target.classList.add('CodeMirror-hyperlink')
|
|
193 | 191 | }
|
194 | 192 | }
|
195 | 193 | }
|
196 |
| - showInfo(relatedTo) { |
| 194 | + showInfo (relatedTo) { |
197 | 195 | const b1 = relatedTo.getBoundingClientRect()
|
198 | 196 | const b2 = this.lineDiv.getBoundingClientRect()
|
199 | 197 | const tdiv = this.tooltip
|
|
0 commit comments