mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
load references keys for autocomplete.
This commit is contained in:
parent
bd0f1c0e29
commit
a48abcab0b
2 changed files with 20 additions and 11 deletions
|
@ -16,7 +16,7 @@ define [
|
|||
constructor: (@$scope, @editor) ->
|
||||
@suggestionManager = new SuggestionManager()
|
||||
|
||||
@monkeyPatchAutocomplete()
|
||||
@monkeyPatchAutocomplete()
|
||||
|
||||
@$scope.$watch "autoComplete", (autocomplete) =>
|
||||
if autocomplete
|
||||
|
@ -37,11 +37,25 @@ define [
|
|||
enableSnippets: true,
|
||||
enableLiveAutocompletion: false
|
||||
})
|
||||
|
||||
|
||||
SnippetCompleter =
|
||||
getCompletions: (editor, session, pos, prefix, callback) ->
|
||||
callback null, Snippets
|
||||
@editor.completers = [@suggestionManager, SnippetCompleter]
|
||||
|
||||
references = @$scope.$root._references
|
||||
ReferencesCompleter =
|
||||
getCompletions: (editor, session, pos, prefix, callback) ->
|
||||
if references.keys
|
||||
result = references.keys.map (key) -> {
|
||||
caption: key,
|
||||
snippet: key,
|
||||
meta: "reference",
|
||||
score: 10000
|
||||
}
|
||||
console.log result
|
||||
callback null, result
|
||||
|
||||
@editor.completers = [ReferencesCompleter, @suggestionManager, SnippetCompleter]
|
||||
|
||||
disable: () ->
|
||||
@editor.setOptions({
|
||||
|
@ -83,7 +97,7 @@ define [
|
|||
# since it will be adding in with the autocomplete of \begin{item}...
|
||||
if this.completions.filterText.match(/^\\begin\{/) and nextChar == "}"
|
||||
editor.session.remove(range)
|
||||
|
||||
|
||||
Autocomplete::_insertMatch.call this, data
|
||||
|
||||
# Overwrite this to set autoInsert = false and set font size
|
||||
|
|
|
@ -3,16 +3,13 @@ define [
|
|||
class ReferencesSearchManager
|
||||
constructor: (@ide, @$scope) ->
|
||||
|
||||
@state =
|
||||
keys: []
|
||||
@$scope.references = @state
|
||||
@$scope.$root._references = @state = keys: []
|
||||
|
||||
@$scope.$on 'document:closed', (e, doc) =>
|
||||
if doc.doc_id
|
||||
entity = @ide.fileTreeManager.findEntityById doc.doc_id
|
||||
if entity?.name?.match /.*\.bib$/
|
||||
@$scope.$emit 'references:changed', entity
|
||||
console.log ">> references changed"
|
||||
@indexReferences doc.doc_id
|
||||
|
||||
indexReferences: (doc_id) ->
|
||||
|
@ -37,7 +34,5 @@ define [
|
|||
_csrf: window.csrfToken
|
||||
},
|
||||
(data) =>
|
||||
console.log ">> got keys"
|
||||
console.log(data)
|
||||
@state.keys = data.keys
|
||||
@$scope.$root._references.keys = data.keys
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue