diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee index 5606f3e6fa..60164782f7 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee @@ -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