atom / bracket-matcher

Jump to brackets
MIT License
142 stars 98 forks source link

Insert bracket pair and position cursor within a transaction #347

Closed smashwilson closed 6 years ago

smashwilson commented 6 years ago

The autocomplete-plus package uses a TextBuffer.onDidChange() handler to trigger the completion dropdown and uses TextEditor.getLastCursor().getBufferPosition() to determine its placement and prefix. Because bracket pair insertion is done with separate .insertText() and .moveLeft() calls, the onDidChange event is fired while the cursor is at the end of the matched pair, and not when it's placed between them:

before

Performing these two calls within a transaction defers the onDidChange event until after the cursor is in its final position:

after

xref atom/autocomplete-plus#954