1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Merge pull request #2819 from ZeroX-DG/feature/edit-from-preview

[Feature] Edit from preview
This commit is contained in:
Junyoung Choi
2019-03-21 01:23:11 +09:00
committed by GitHub
3 changed files with 42 additions and 0 deletions

View File

@@ -192,6 +192,19 @@ const defaultCodeBlockFontFamily = [
'source-code-pro',
'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 {
constructor (props) {
super(props)
@@ -272,6 +285,22 @@ export default class MarkdownPreview extends React.Component {
if (config.editor.switchPreview === 'RIGHTCLICK' && e.buttons === 2 && config.editor.type === 'SPLIT') {
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) {
switch (e.target.tagName) {
case 'A':