-
Notifications
You must be signed in to change notification settings - Fork 58
/
modes.ts
68 lines (61 loc) · 3.91 KB
/
modes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import type { InputOr } from ".";
import { Context, prompt, toMode } from "../api";
/**
* Set modes.
*/
declare module "./modes";
/**
* Set Dance mode.
*
* #### Variants
*
* | Title | Identifier | Keybinding | Command |
* | ------------------ | ------------ | ---------------------------------------------------- | ----------------------------------------------------------- |
* | Set mode to Normal | `set.normal` | `escape` (kakoune: insert), `escape` (helix: select) | `[".modes.set", { mode: "normal" }], ["hideSuggestWidget"]` |
* | Set mode to Insert | `set.insert` | | `[".modes.set", { mode: "insert" }]` |
* | Set mode to Select | `set.select` | | `[".modes.set", { mode: "select" }]` |
*
* Other variants are provided to switch to insert mode:
*
* | Title | Identifier | Keybinding | Commands |
* | -------------------- | ------------------ | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
* | Insert before | `insert.before` | `i` (kakoune: normal) | `[".selections.faceBackward", { record: false }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "start", record: false, empty: true, ... }]` |
* | Insert after | `insert.after` | `a` (kakoune: normal) | `[".selections.faceForward" , { record: false }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "end" , record: false, empty: true, ... }]` |
* | Insert at line start | `insert.lineStart` | `s-i` (kakoune: normal) | `[".select.lineStart", { shift: "jump", skipBlank: true }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "start", record: false, empty: true, ... }]` |
* | Insert at line end | `insert.lineEnd` | `s-a` (kakoune: normal) | `[".select.lineEnd" , { shift: "jump" }], [".modes.set", { mode: "insert", +mode }], [".selections.reduce", { where: "end" , record: false, empty: true, ... }]` |
*
* @noreplay
*/
export async function set(_: Context, modeOr: InputOr<"mode", string>) {
await toMode(await modeOr(() => prompt(validateModeName())));
}
/**
* Set Dance mode temporarily.
*
* #### Variants
*
* | Title | Identifier | Keybindings | Commands |
* | --------------------- | ------------------------ | ----------------------- | ------------------------------------------------ |
* | Temporary Normal mode | `set.temporarily.normal` | `c-v` (kakoune: insert) | `[".modes.set.temporarily", { mode: "normal" }]` |
* | Temporary Insert mode | `set.temporarily.insert` | `c-v` (kakoune: normal) | `[".modes.set.temporarily", { mode: "insert" }]` |
*
* @noreplay
*/
export async function set_temporarily(_: Context, modeOr: InputOr<"mode", string>, repetitions: number) {
await toMode(await modeOr(() => prompt(validateModeName())), repetitions);
}
const modeHistory: string[] = [];
function validateModeName(ctx = Context.WithoutActiveEditor.current) {
const modes = ctx.extension.modes;
return {
prompt: "Mode name",
validateInput(value) {
if (modes.get(value) !== undefined) {
return;
}
return `mode ${JSON.stringify(value)} does not exist`;
},
placeHolder: [...modes.userModes()].map((m) => m.name).sort().join(", "),
history: modeHistory,
} as prompt.Options;
}