mirror of
https://github.com/VSCodeVim/Vim.git
synced 2024-10-26 12:06:48 +03:00
Support for adding custom digraphs with :dig[raphs]
This commit is contained in:
parent
331676c608
commit
edef39e7c3
@ -1,5 +1,5 @@
|
|||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
export const DefaultDigraphs = new Map<string, [string, number]>([
|
export const DefaultDigraphs = new Map<string, [string, number | number[]]>([
|
||||||
["NU", ["^@", 10]],
|
["NU", ["^@", 10]],
|
||||||
["SH", ["^A", 1]],
|
["SH", ["^A", 1]],
|
||||||
["SX", ["^B", 2]],
|
["SX", ["^B", 2]],
|
||||||
|
@ -12,7 +12,7 @@ import { configuration } from './../../configuration/configuration';
|
|||||||
|
|
||||||
export interface IDigraphsCommandArguments {
|
export interface IDigraphsCommandArguments {
|
||||||
bang: boolean;
|
bang: boolean;
|
||||||
newDigraphs: Array<[string, string, number]>;
|
newDigraph: [string, string, number[]] | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DigraphQuickPickItem extends vscode.QuickPickItem {
|
interface DigraphQuickPickItem extends vscode.QuickPickItem {
|
||||||
@ -22,8 +22,8 @@ interface DigraphQuickPickItem extends vscode.QuickPickItem {
|
|||||||
export class DigraphsCommand extends ExCommand {
|
export class DigraphsCommand extends ExCommand {
|
||||||
public static readonly argParser: Parser<DigraphsCommand> = seq(
|
public static readonly argParser: Parser<DigraphsCommand> = seq(
|
||||||
bangParser,
|
bangParser,
|
||||||
whitespace.then(seq(any, any, whitespace.then(numberParser))).many(),
|
whitespace.then(seq(any, any, whitespace.then(numberParser).atLeast(1))).fallback(undefined),
|
||||||
).map(([bang, newDigraphs]) => new DigraphsCommand({ bang, newDigraphs }));
|
).map(([bang, newDigraph]) => new DigraphsCommand({ bang, newDigraph }));
|
||||||
|
|
||||||
private readonly arguments: IDigraphsCommandArguments;
|
private readonly arguments: IDigraphsCommandArguments;
|
||||||
constructor(args: IDigraphsCommandArguments) {
|
constructor(args: IDigraphsCommandArguments) {
|
||||||
@ -45,17 +45,21 @@ export class DigraphsCommand extends ExCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async execute(vimState: VimState): Promise<void> {
|
async execute(vimState: VimState): Promise<void> {
|
||||||
// TODO: use arguments
|
if (this.arguments.newDigraph) {
|
||||||
|
const digraph = this.arguments.newDigraph[0] + this.arguments.newDigraph[1];
|
||||||
|
const charCodes = this.arguments.newDigraph[2];
|
||||||
|
DefaultDigraphs.set(digraph, [String.fromCharCode(...charCodes), charCodes]);
|
||||||
|
} else {
|
||||||
|
const digraphKeyAndContent = this.makeQuickPicks(
|
||||||
|
Object.entries(configuration.digraphs),
|
||||||
|
).concat(this.makeQuickPicks([...DefaultDigraphs.entries()]));
|
||||||
|
|
||||||
const digraphKeyAndContent = this.makeQuickPicks(Object.entries(configuration.digraphs)).concat(
|
void vscode.window.showQuickPick(digraphKeyAndContent).then(async (val) => {
|
||||||
this.makeQuickPicks([...DefaultDigraphs.entries()]),
|
if (val) {
|
||||||
);
|
const char = String.fromCharCode(...val.charCodes);
|
||||||
|
await TextEditor.insert(vimState.editor, char);
|
||||||
void vscode.window.showQuickPick(digraphKeyAndContent).then(async (val) => {
|
}
|
||||||
if (val) {
|
});
|
||||||
const char = String.fromCharCode(...val.charCodes);
|
}
|
||||||
await TextEditor.insert(vimState.editor, char);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -494,6 +494,14 @@ suite('Mode Insert', () => {
|
|||||||
assertEqualLines(['🚀🚀']);
|
assertEqualLines(['🚀🚀']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
newTest({
|
||||||
|
title: 'Can insert custom digraph made with :dig[raphs]`',
|
||||||
|
start: ['|'],
|
||||||
|
keysPressed: ':dig R! 55357 56960\n' + 'i<C-k>R!',
|
||||||
|
end: ['🚀|'],
|
||||||
|
endMode: Mode.Insert,
|
||||||
|
});
|
||||||
|
|
||||||
suite('<C-a>', () => {
|
suite('<C-a>', () => {
|
||||||
newTest({
|
newTest({
|
||||||
title: 'Basic <C-a> test',
|
title: 'Basic <C-a> test',
|
||||||
|
@ -200,20 +200,14 @@ suite('Ex command parsing', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
suite(':dig[raphs]', () => {
|
suite(':dig[raphs]', () => {
|
||||||
exParseTest(':dig', new DigraphsCommand({ bang: false, newDigraphs: [] }));
|
exParseTest(':dig', new DigraphsCommand({ bang: false, newDigraph: undefined }));
|
||||||
exParseTest(':dig!', new DigraphsCommand({ bang: true, newDigraphs: [] }));
|
exParseTest(':dig!', new DigraphsCommand({ bang: true, newDigraph: undefined }));
|
||||||
|
exParseTest(':dig e: 235', new DigraphsCommand({ bang: false, newDigraph: ['e', ':', [235]] }));
|
||||||
exParseTest(
|
exParseTest(
|
||||||
':dig e: 235',
|
':dig R! 55357 56960',
|
||||||
new DigraphsCommand({ bang: false, newDigraphs: [['e', ':', 235]] }),
|
|
||||||
);
|
|
||||||
exParseTest(
|
|
||||||
':dig e: 235 a: 238',
|
|
||||||
new DigraphsCommand({
|
new DigraphsCommand({
|
||||||
bang: false,
|
bang: false,
|
||||||
newDigraphs: [
|
newDigraph: ['R', '!', [55357, 56960]],
|
||||||
['e', ':', 235],
|
|
||||||
['a', ':', 238],
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user