mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Merge pull request #2494 from intercloud/feat/link-to-a-line
feat(editor): add ability to jump to line
This commit is contained in:
@@ -57,6 +57,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
this.searchHandler = (e, msg) => this.handleSearch(msg)
|
this.searchHandler = (e, msg) => this.handleSearch(msg)
|
||||||
this.searchState = null
|
this.searchState = null
|
||||||
|
this.scrollToLineHandeler = this.scrollToLine.bind(this)
|
||||||
|
|
||||||
this.formatTable = () => this.handleFormatTable()
|
this.formatTable = () => this.handleFormatTable()
|
||||||
this.editorActivityHandler = () => this.handleEditorActivity()
|
this.editorActivityHandler = () => this.handleEditorActivity()
|
||||||
@@ -125,6 +126,7 @@ export default class CodeEditor extends React.Component {
|
|||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const { rulers, enableRulers } = this.props
|
const { rulers, enableRulers } = this.props
|
||||||
const expandSnippet = this.expandSnippet.bind(this)
|
const expandSnippet = this.expandSnippet.bind(this)
|
||||||
|
eventEmitter.on('line:jump', this.scrollToLineHandeler)
|
||||||
|
|
||||||
const defaultSnippet = [
|
const defaultSnippet = [
|
||||||
{
|
{
|
||||||
@@ -475,7 +477,13 @@ export default class CodeEditor extends React.Component {
|
|||||||
|
|
||||||
moveCursorTo (row, col) {}
|
moveCursorTo (row, col) {}
|
||||||
|
|
||||||
scrollToLine (num) {}
|
scrollToLine (event, num) {
|
||||||
|
const cursor = {
|
||||||
|
line: num,
|
||||||
|
ch: 1
|
||||||
|
}
|
||||||
|
this.editor.setCursor(cursor)
|
||||||
|
}
|
||||||
|
|
||||||
focus () {
|
focus () {
|
||||||
this.editor.focus()
|
this.editor.focus()
|
||||||
|
|||||||
@@ -866,6 +866,15 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const regexIsLine = /^:line:[0-9]/
|
||||||
|
if (regexIsLine.test(linkHash)) {
|
||||||
|
const numberPattern = /\d+/g
|
||||||
|
|
||||||
|
const lineNumber = parseInt(linkHash.match(numberPattern)[0])
|
||||||
|
eventEmitter.emit('line:jump', lineNumber)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// this will match the old link format storage.key-note.key
|
// this will match the old link format storage.key-note.key
|
||||||
// e.g.
|
// e.g.
|
||||||
// 877f99c3268608328037-1c211eb7dcb463de6490
|
// 877f99c3268608328037-1c211eb7dcb463de6490
|
||||||
|
|||||||
Reference in New Issue
Block a user