Merge pull request #1872 from overleaf/hb-autocomplete-braces

Autocomplete braces bugfixes

GitOrigin-RevId: 9b3af30b71b85cf95288b0388c9af7792b87ca80
This commit is contained in:
Simon Detheridge
2019-06-20 11:30:44 +00:00
committed by sharelatex
parent 350e2ac38f
commit 1e14f75e08
@@ -274,21 +274,21 @@ define([
monkeyPatchAutocomplete() {
const { Autocomplete } = ace.require('ace/autocomplete')
const Util = ace.require('ace/autocomplete/util')
const { editor } = this
if (Autocomplete.prototype._insertMatch == null) {
// Only override this once since it's global but we may create multiple
// autocomplete handlers
Autocomplete.prototype._insertMatch = Autocomplete.prototype.insertMatch
Autocomplete.prototype.insertMatch = function(data) {
const { editor } = this
const pos = editor.getCursorPosition()
let range = new Range(pos.row, pos.column, pos.row, pos.column + 1)
const nextChar = editor.session.getTextRange(range)
// If we are in \begin{it|}, then we need to remove the trailing }
// since it will be adding in with the autocomplete of \begin{item}...
if (
/^\\\w+(\[[\w\\,= ]*\])?{/.test(this.completions.filterText) &&
/^\\\w+(\[[\w\\,=. ]*\])?{/.test(this.completions.filterText) &&
nextChar === '}'
) {
editor.session.remove(range)