Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/assets/ts/definitions/basics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
));
Expand All @@ -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();
},
));
Expand Down
20 changes: 19 additions & 1 deletion src/plugins/bracket_completion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()),
);