Experimental handling of completion for existing commands

This commit is contained in:
Shane Kilkelly 2017-07-03 15:12:15 +01:00
parent 127d5ded86
commit 415de9e2ec

View file

@ -161,16 +161,38 @@ define [
data = popup.getData(popup.getRow())
data.completer =
insertMatch: (editor, matchData) ->
console.log ">> custom insertMatch"
ranges = editor.selection.getAllRanges()
for range in ranges
range.start.column -= completions.filterText.length;
editor.session.remove(range);
left = _.clone(range)
right = _.clone(range)
left.start.column -= completions.filterText.length;
editor.session.remove(left);
beyondCursorRange = new Range(
right.start.row,
right.start.column,
right.end.row,
99999
)
lineBeyondCursor = editor.getSession().getTextRange(beyondCursorRange)
if lineBeyondCursor
if partialCommandMatch = lineBeyondCursor.match(/^([a-z0-9]+)\{/)
# We've got a partial command after the cursor
commandTail = partialCommandMatch[1]
# remove rest of the partial command
right.end.column += commandTail.length - completions.filterText.length
editor.session.remove(right);
# trim the completion text to just the command, without braces
# example: '\cite{}' -> '\cite'
if matchData.snippet
matchData.snippet = matchData.snippet.replace(/[{\[].*[}\]]/, '')
if matchData.caption
matchData.caption = matchData.caption.replace(/[{\[].*[}\]]/, '')
if matchData.value
matchData.value = matchData.value.replace(/[{\[].*[}\]]/, '')
# finally, insert the match
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