mirror of
https://github.com/overleaf/overleaf.git
synced 2024-09-16 02:52:31 -04:00
0e9771ac09
File outline extras GitOrigin-RevId: c35c4f35dce280c9f44c02b567df9734943d0cb0
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
import './controllers/OutlineController'
|
|
import './components/OutlinePane'
|
|
import './components/OutlineRoot'
|
|
import './components/OutlineList'
|
|
import './components/OutlineItem'
|
|
import parseOutline from './OutlineParser'
|
|
import isValidTeXFile from '../../main/is-valid-tex-file'
|
|
|
|
class OutlineManager {
|
|
constructor(ide, scope) {
|
|
this.ide = ide
|
|
this.scope = scope
|
|
this.shareJsDoc = null
|
|
this.isTexFile = false
|
|
this.outline = []
|
|
|
|
scope.$on('doc:after-opened', () => {
|
|
this.shareJsDoc = scope.editor.shareJsDoc
|
|
this.isTexFile = isValidTeXFile(scope.editor.open_doc_name)
|
|
this.updateOutline()
|
|
this.broadcastChangeEvent()
|
|
})
|
|
|
|
scope.$watch('openFile.name', openFileName => {
|
|
this.isTexFile = isValidTeXFile(openFileName)
|
|
this.updateOutline()
|
|
this.broadcastChangeEvent()
|
|
})
|
|
|
|
scope.$on('doc:changed', () => {
|
|
this.updateOutline()
|
|
this.broadcastChangeEvent()
|
|
})
|
|
}
|
|
|
|
updateOutline() {
|
|
this.outline = []
|
|
if (this.isTexFile) {
|
|
const content = this.ide.editorManager.getCurrentDocValue()
|
|
if (content) {
|
|
this.outline = parseOutline(content)
|
|
}
|
|
}
|
|
}
|
|
|
|
jumpToLine(line) {
|
|
this.ide.editorManager.openDocId(this.shareJsDoc.doc.doc_id, {
|
|
gotoLine: line
|
|
})
|
|
}
|
|
|
|
broadcastChangeEvent() {
|
|
this.scope.$broadcast('outline-manager:outline-changed', {
|
|
isTexFile: this.isTexFile,
|
|
outline: this.outline
|
|
})
|
|
}
|
|
}
|
|
|
|
export default OutlineManager
|