Bladeren bron

Add a skeleton of a custom insertMatch function

Shane Kilkelly 9 jaren geleden
bovenliggende
commit
7ecadb14f6

+ 20 - 0
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee

@@ -5,6 +5,7 @@ define [
 	"ace/ext-language_tools"
 ], (SuggestionManager, SnippetManager) ->
 	Range = ace.require("ace/range").Range
+	aceSnippetManager = ace.require('ace/snippets').snippetManager
 
 	getLastCommandFragment = (lineUpToCursor) ->
 		if m = lineUpToCursor.match(/(\\[^\\]+)$/)
@@ -154,6 +155,25 @@ define [
 					if this.completions.filterText.match(/^\\begin\{/) and nextChar == "}"
 						editor.session.remove(range)
 
+					if !data?
+						completions = this.completions
+						popup = editor.completer.popup
+						data = popup.getData(popup.getRow())
+						data.completer =
+							insertMatch: (editor, matchData) ->
+								console.log ">> custom insertMatch"
+								console.log ">> data", data
+								ranges = editor.selection.getAllRanges()
+								for range in ranges
+									range.start.column -= completions.filterText.length;
+									editor.session.remove(range);
+								if matchData.snippet
+									console.log ">> snippet"
+									aceSnippetManager.insertSnippet(editor, matchData.snippet);
+								else
+									console.log ">> string", matchData
+									editor.execCommand("insertstring", matchData.value || matchData);
+
 					Autocomplete::_insertMatch.call this, data
 
 				# Overwrite this to set autoInsert = false and set font size