Why do you perform the replacement in two steps ?
I think that line 1014 could be:
> this.$.ace.replaceRange(range, config);
instead of
> this.$.ace.replaceRange(range, "");

In that case, code from line 1016 to 1018 should be removed.