mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
added jump to line on click preview
This commit is contained in:
@@ -32,6 +32,7 @@ class MarkdownEditor extends React.Component {
|
|||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
this.value = this.refs.code.value
|
this.value = this.refs.code.value
|
||||||
eventEmitter.on('editor:lock', this.lockEditorCode)
|
eventEmitter.on('editor:lock', this.lockEditorCode)
|
||||||
|
eventEmitter.on('editor:focus', this.focusEditor.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate () {
|
componentDidUpdate () {
|
||||||
@@ -47,6 +48,15 @@ class MarkdownEditor extends React.Component {
|
|||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
this.cancelQueue()
|
this.cancelQueue()
|
||||||
eventEmitter.off('editor:lock', this.lockEditorCode)
|
eventEmitter.off('editor:lock', this.lockEditorCode)
|
||||||
|
eventEmitter.off('editor:focus', this.focusEditor.bind(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
focusEditor () {
|
||||||
|
this.setState({
|
||||||
|
status: 'CODE'
|
||||||
|
}, () => {
|
||||||
|
this.refs.code.focus()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
queueRendering (value) {
|
queueRendering (value) {
|
||||||
|
|||||||
@@ -192,6 +192,19 @@ const defaultCodeBlockFontFamily = [
|
|||||||
'source-code-pro',
|
'source-code-pro',
|
||||||
'monospace'
|
'monospace'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// return the line number of the line that used to generate the specified element
|
||||||
|
// return -1 if the line is not found
|
||||||
|
function getSourceLineNumberByElement (element) {
|
||||||
|
let isHasLineNumber = element.dataset.line !== undefined
|
||||||
|
let parent = element
|
||||||
|
while (!isHasLineNumber && parent.parentElement !== null) {
|
||||||
|
parent = parent.parentElement
|
||||||
|
isHasLineNumber = parent.dataset.line !== undefined
|
||||||
|
}
|
||||||
|
return parent.dataset.line !== undefined ? parseInt(parent.dataset.line) : -1
|
||||||
|
}
|
||||||
|
|
||||||
export default class MarkdownPreview extends React.Component {
|
export default class MarkdownPreview extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
@@ -271,6 +284,22 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
if (config.editor.switchPreview === 'RIGHTCLICK' && e.buttons === 2 && config.editor.type === 'SPLIT') {
|
if (config.editor.switchPreview === 'RIGHTCLICK' && e.buttons === 2 && config.editor.type === 'SPLIT') {
|
||||||
eventEmitter.emit('topbar:togglemodebutton', 'CODE')
|
eventEmitter.emit('topbar:togglemodebutton', 'CODE')
|
||||||
}
|
}
|
||||||
|
if (e.ctrlKey) {
|
||||||
|
if (config.editor.type === 'SPLIT') {
|
||||||
|
const clickElement = e.target
|
||||||
|
const lineNumber = getSourceLineNumberByElement(clickElement)
|
||||||
|
if (lineNumber !== -1) {
|
||||||
|
eventEmitter.emit('line:jump', lineNumber)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const clickElement = e.target
|
||||||
|
const lineNumber = getSourceLineNumberByElement(clickElement)
|
||||||
|
if (lineNumber !== -1) {
|
||||||
|
eventEmitter.emit('editor:focus')
|
||||||
|
eventEmitter.emit('line:jump', lineNumber)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (e.target != null) {
|
if (e.target != null) {
|
||||||
switch (e.target.tagName) {
|
switch (e.target.tagName) {
|
||||||
case 'A':
|
case 'A':
|
||||||
|
|||||||
Reference in New Issue
Block a user