mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 02:36:36 +00:00
address requested changes - tag link & redundant line
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
;(function(mod) {
|
;(function (mod) {
|
||||||
if (typeof exports === 'object' && typeof module === 'object') {
|
if (typeof exports === 'object' && typeof module === 'object') {
|
||||||
// Common JS
|
// Common JS
|
||||||
mod(require('../codemirror/lib/codemirror'))
|
mod(require('../codemirror/lib/codemirror'))
|
||||||
@@ -9,13 +9,13 @@
|
|||||||
// Plain browser env
|
// Plain browser env
|
||||||
mod(CodeMirror)
|
mod(CodeMirror)
|
||||||
}
|
}
|
||||||
})(function(CodeMirror) {
|
})(function (CodeMirror) {
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const shell = require('electron').shell
|
const shell = require('electron').shell
|
||||||
const remote = require('electron').remote
|
const remote = require('electron').remote
|
||||||
const eventEmitter = {
|
const eventEmitter = {
|
||||||
emit: function() {
|
emit: function () {
|
||||||
remote.getCurrentWindow().webContents.send.apply(null, arguments)
|
remote.getCurrentWindow().webContents.send.apply(null, arguments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
const modifier = macOS ? 'metaKey' : 'ctrlKey'
|
const modifier = macOS ? 'metaKey' : 'ctrlKey'
|
||||||
|
|
||||||
class HyperLink {
|
class HyperLink {
|
||||||
constructor(cm) {
|
constructor (cm) {
|
||||||
this.cm = cm
|
this.cm = cm
|
||||||
this.lineDiv = cm.display.lineDiv
|
this.lineDiv = cm.display.lineDiv
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
passive: true
|
passive: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
getUrl(el) {
|
getUrl (el) {
|
||||||
const className = el.className.split(' ')
|
const className = el.className.split(' ')
|
||||||
|
|
||||||
if (className.indexOf('cm-url') !== -1) {
|
if (className.indexOf('cm-url') !== -1) {
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
specialLinkHandler(e, rawHref, linkHash) {
|
specialLinkHandler (e, rawHref, linkHash) {
|
||||||
const isStartWithHash = rawHref[0] === '#'
|
const isStartWithHash = rawHref[0] === '#'
|
||||||
|
|
||||||
const extractIdRegex = /file:\/\/.*main.?\w*.html#/ // file://path/to/main(.development.)html
|
const extractIdRegex = /file:\/\/.*main.?\w*.html#/ // file://path/to/main(.development.)html
|
||||||
@@ -121,14 +121,14 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const regexIsTagLink = /^:tag:#([\w]+)$/
|
const regexIsTagLink = /^:tag:([\w]+)$/
|
||||||
if (regexIsTagLink.test(rawHref)) {
|
if (regexIsTagLink.test(rawHref)) {
|
||||||
const tag = rawHref.match(regexIsTagLink)[1]
|
const tag = rawHref.match(regexIsTagLink)[1]
|
||||||
eventEmitter.emit('dispatch:push', `/tags/${encodeURIComponent(tag)}`)
|
eventEmitter.emit('dispatch:push', `/tags/${encodeURIComponent(tag)}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onMouseDown(e) {
|
onMouseDown (e) {
|
||||||
const { target } = e
|
const { target } = e
|
||||||
if (!e[modifier]) {
|
if (!e[modifier]) {
|
||||||
return
|
return
|
||||||
@@ -142,8 +142,6 @@
|
|||||||
parser.href = rawHref
|
parser.href = rawHref
|
||||||
const { href, hash } = parser
|
const { href, hash } = parser
|
||||||
|
|
||||||
if (!rawHref) return // not checked href because parser will create file://... string for [empty link]()
|
|
||||||
|
|
||||||
const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
|
const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
|
||||||
|
|
||||||
this.specialLinkHandler(target, rawHref, linkHash)
|
this.specialLinkHandler(target, rawHref, linkHash)
|
||||||
@@ -157,7 +155,7 @@
|
|||||||
shell.openExternal(url)
|
shell.openExternal(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onMouseEnter(e) {
|
onMouseEnter (e) {
|
||||||
const { target } = e
|
const { target } = e
|
||||||
|
|
||||||
const url = this.getUrl(target)
|
const url = this.getUrl(target)
|
||||||
@@ -174,7 +172,7 @@
|
|||||||
this.showInfo(target)
|
this.showInfo(target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onMouseLeave(e) {
|
onMouseLeave (e) {
|
||||||
if (this.tooltip.parentElement === this.lineDiv) {
|
if (this.tooltip.parentElement === this.lineDiv) {
|
||||||
e.target.classList.remove(
|
e.target.classList.remove(
|
||||||
'CodeMirror-activeline-background',
|
'CodeMirror-activeline-background',
|
||||||
@@ -184,7 +182,7 @@
|
|||||||
this.lineDiv.removeChild(this.tooltip)
|
this.lineDiv.removeChild(this.tooltip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onMouseMove(e) {
|
onMouseMove (e) {
|
||||||
if (this.tooltip.parentElement === this.lineDiv) {
|
if (this.tooltip.parentElement === this.lineDiv) {
|
||||||
if (e[modifier]) {
|
if (e[modifier]) {
|
||||||
e.target.classList.add('CodeMirror-hyperlink')
|
e.target.classList.add('CodeMirror-hyperlink')
|
||||||
@@ -193,7 +191,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
showInfo(relatedTo) {
|
showInfo (relatedTo) {
|
||||||
const b1 = relatedTo.getBoundingClientRect()
|
const b1 = relatedTo.getBoundingClientRect()
|
||||||
const b2 = this.lineDiv.getBoundingClientRect()
|
const b2 = this.lineDiv.getBoundingClientRect()
|
||||||
const tdiv = this.tooltip
|
const tdiv = this.tooltip
|
||||||
|
|||||||
Reference in New Issue
Block a user