Explorar el Código

load references keys for autocomplete.

Shane Kilkelly hace 10 años
padre
commit
a48abcab0b

+ 18 - 4
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee

@@ -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

+ 2 - 7
services/web/public/coffee/ide/references-search/ReferencesSearchManager.coffee

@@ -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
 			)