diff --git a/src/assets/ts/definitions/basics.ts b/src/assets/ts/definitions/basics.ts index c774e1ae..bc2be69d 100644 --- a/src/assets/ts/definitions/basics.ts +++ b/src/assets/ts/definitions/basics.ts @@ -434,6 +434,7 @@ keyDefinitions.registerAction(new Action( 'delete-char-after', 'Delete character after the cursor (i.e. del key)', async function({ session }) { + await session.applyHookAsync('deleteCharAfter', {}, {}); await session.delCharsAfterCursor(1); }, )); @@ -454,6 +455,7 @@ keyDefinitions.registerAction(new Action( 'delete-char-before', 'Delete previous character (i.e. backspace key)', async function({ session }) { + await session.applyHookAsync('deleteCharBefore', {}, {}); await session.deleteAtCursor(); }, )); diff --git a/src/plugins/bracket_completion/index.ts b/src/plugins/bracket_completion/index.ts index 2d777045..f1f61ef2 100644 --- a/src/plugins/bracket_completion/index.ts +++ b/src/plugins/bracket_completion/index.ts @@ -5,7 +5,7 @@ const completions: { [key: string]: Char } = {'(': ')', '{': '}', '[': ']', '"': registerPlugin({ name: 'Bracket Completion', - version: 1, + version: 2, author: 'Victor Tao', description: ` Auto completes ${Object.keys(completions).join(', ')} in insert mode @@ -17,6 +17,24 @@ registerPlugin({ await api.session.cursor.left(); } }); + api.registerHook('session', 'deleteCharAfter', async (_struct, {}) => { + const col = api.session.cursor.col; + const line = await api.session.curLine(); + if (col + 1 < line.length && line[col] in completions) { + if (line[col + 1] === completions[line[col]]) { + await api.session.delCharsAfterCursor(1); + } + } + }); + api.registerHook('session', 'deleteCharBefore', async (_struct, {}) => { + const col = api.session.cursor.col; + const line = await api.session.curLine(); + if (col > 0 && line[col - 1] in completions) { + if (line[col] === completions[line[col - 1]]) { + await api.session.delCharsAfterCursor(1); + } + } + }); }, (api => api.deregisterAll()), );