|
1 | 1 | export interface Command { |
2 | 2 | name: string; |
3 | 3 | run: () => string; |
4 | | - cursorOffset?: number; |
| 4 | + // Ex.: |
| 5 | + // [4] == [4, 0] - cursor offset is 4 chars from initial position |
| 6 | + // [7, 2] - cursor offset is 7 chars and 2 next chars selected |
| 7 | + // If omitted, cursor stays in the end of the inserted string |
| 8 | + cursorRange?: number[]; |
5 | 9 | } |
6 | 10 |
|
7 | 11 | export const editorCommands: Command[] = [ |
8 | 12 | { |
9 | | - name: "todo", |
10 | | - run: () => "- [ ] ", |
11 | | - cursorOffset: 6, // Places cursor after "- [ ] " to start typing task |
| 13 | + name: "code", |
| 14 | + run: () => "```js\n\n```", // JS by default as most popular (at least on github) |
| 15 | + cursorRange: [3, 2], |
12 | 16 | }, |
13 | 17 | { |
14 | | - name: "code", |
15 | | - run: () => "```\n\n```", |
16 | | - cursorOffset: 4, // Places cursor on empty line between code fences |
| 18 | + // Template from github, but with summary initially selected for better UX |
| 19 | + name: "details", |
| 20 | + run: () => "<details><summary>Details</summary>\n<p>\n\n\n</p>\n</details>", |
| 21 | + cursorRange: [18, 7], |
| 22 | + }, |
| 23 | + { |
| 24 | + name: "image", |
| 25 | + run: () => "![alt text]()", // No need in URL placeholder |
| 26 | + cursorRange: [2, 8], |
17 | 27 | }, |
18 | 28 | { |
19 | 29 | name: "link", |
20 | | - run: () => "[text](url)", |
21 | | - cursorOffset: 1, // Places cursor after "[" to type link text |
| 30 | + run: () => "[text]()", |
| 31 | + cursorRange: [1, 4], |
22 | 32 | }, |
23 | 33 | { |
24 | 34 | name: "table", |
25 | | - run: () => "| Header | Header |\n| ------ | ------ |\n| Cell | Cell |", |
26 | | - cursorOffset: 1, // Places cursor after first "|" to edit first header |
| 35 | + run: () => "| Column1 | Column2 |\n| ------ | ------ |\n| Cell1 | Cell2 |", |
| 36 | + cursorRange: [2, 7], |
| 37 | + }, |
| 38 | + { |
| 39 | + name: "todo", |
| 40 | + run: () => "- [ ] ", |
| 41 | + }, |
| 42 | + { |
| 43 | + name: "youtube", |
| 44 | + run: () => "[](https://www.youtube.com/watch?v=VIDEO_ID)", |
| 45 | + cursorRange: [3, 8], |
27 | 46 | }, |
28 | 47 | ]; |
0 commit comments