Skip to content

Commit d11b904

Browse files
committed
Reimplement cheatsheet using html
Fixes #618
1 parent 2f0fada commit d11b904

File tree

8 files changed

+98
-16
lines changed

8 files changed

+98
-16
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
1313
"typescript.tsc.autoDetect": "off",
14+
"python.formatting.provider": "black",
1415
"cSpell.words": [
1516
"Autoformatting",
1617
"camelize",

cursorless-talon/src/cheatsheet/cheat_sheet.py

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
from talon import Module, ui, skia, actions, cron
2-
from talon.canvas import Canvas
3-
import webbrowser
1+
import json
42
import math
3+
import webbrowser
4+
from pathlib import Path
55

6-
from .sections.actions import get_actions
7-
from .sections.scopes import get_scopes
8-
from .sections.compound_targets import get_compound_targets
6+
from talon import Module, actions, cron, skia, ui
7+
from talon.canvas import Canvas
98

109
from .get_list import get_list, get_lists
10+
from .sections.actions import get_actions
11+
from .sections.compound_targets import get_compound_targets
12+
from .sections.scopes import get_scopes
1113

1214
mod = Module()
1315
mod.mode("cursorless_cheat_sheet", "Mode for showing cursorless cheat sheet gui")
@@ -294,14 +296,50 @@ def draw_value(self, canvas, text):
294296
class Actions:
295297
def cursorless_cheat_sheet_toggle():
296298
"""Toggle cursorless cheat sheet"""
297-
global cheat_sheet
298-
if cheat_sheet:
299-
actions.mode.disable("user.cursorless_cheat_sheet")
300-
cheat_sheet.close()
301-
cheat_sheet = None
302-
else:
303-
cheat_sheet = CheatSheet()
304-
actions.mode.enable("user.cursorless_cheat_sheet")
299+
actions.user.vscode_with_plugin(
300+
"cursorless.showCheatsheet", actions.user.cursorless_cheat_sheet_get_json()
301+
)
302+
303+
def cursorless_cheat_sheet_get_json():
304+
"""Get cursorless cheat sheet json"""
305+
return {
306+
"sections": [
307+
{
308+
"name": "Actions",
309+
"items": get_actions(),
310+
},
311+
{
312+
"name": "Scopes",
313+
"items": get_scopes(),
314+
},
315+
{
316+
"name": "Paired delimiters",
317+
"items": get_lists(
318+
[
319+
"wrapper_only_paired_delimiter",
320+
"wrapper_selectable_paired_delimiter",
321+
"selectable_only_paired_delimiter",
322+
]
323+
),
324+
},
325+
{
326+
"name": "Special marks",
327+
"items": get_list("special_mark"),
328+
},
329+
{
330+
"name": "Positions",
331+
"items": get_list("position"),
332+
},
333+
{
334+
"name": "Colors",
335+
"items": get_list("hat_color"),
336+
},
337+
{
338+
"name": "Shapes",
339+
"items": get_list("hat_shape"),
340+
},
341+
]
342+
}
305343

306344
def cursorless_open_instructions():
307345
"""Open web page with cursorless instructions"""

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
{
6464
"command": "cursorless.resumeRecording",
6565
"title": "Cursorless: Resume test case recording"
66+
},
67+
{
68+
"command": "cursorless.showCheatsheet",
69+
"title": "Cursorless: Resume test case recording"
6670
}
6771
],
6872
"colors": [
@@ -532,4 +536,4 @@
532536
"immutability-helper": "^3.1.1",
533537
"lodash": "^4.17.21"
534538
}
535-
}
539+
}

src/core/Cheatsheet.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as vscode from "vscode";
2+
import { Graph } from "../typings/Types";
3+
4+
type SpokenFormInfo = any;
5+
6+
export default class Cheatsheet {
7+
private disposables: vscode.Disposable[] = [];
8+
9+
constructor(graph: Graph) {
10+
graph.extensionContext.subscriptions.push(this);
11+
}
12+
13+
init() {
14+
this.disposables.push(
15+
vscode.commands.registerCommand(
16+
"cursorless.showCheatsheet",
17+
(spokenFormInfo: SpokenFormInfo) => {
18+
console.log(
19+
`spokenFormInfo: ${JSON.stringify(spokenFormInfo, undefined, 2)}`
20+
);
21+
}
22+
)
23+
);
24+
}
25+
26+
dispose() {
27+
this.disposables.forEach(({ dispose }) => dispose());
28+
}
29+
}

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export async function activate(context: vscode.ExtensionContext) {
3030
await graph.decorations.init();
3131
graph.hatTokenMap.init();
3232
graph.testCaseRecorder.init();
33+
graph.cheatsheet.init();
3334

3435
const thatMark = new ThatMark();
3536
const sourceMark = new ThatMark();

src/typings/Types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { CommandServerApi } from "../util/getExtensionApi";
1313
import { ReadOnlyHatMap } from "../core/IndividualHatMap";
1414
import Debug from "../core/Debug";
1515
import { TestCaseRecorder } from "../testUtil/TestCaseRecorder";
16+
import Cheatsheet from "../core/Cheatsheet";
1617

1718
/**
1819
* A token within a text editor, including the current display line of the token
@@ -487,6 +488,11 @@ export interface Graph {
487488
* Used for recording test cases
488489
*/
489490
readonly testCaseRecorder: TestCaseRecorder;
491+
492+
/**
493+
* Used to display cheatsheet
494+
*/
495+
readonly cheatsheet: Cheatsheet;
490496
}
491497

492498
export type NodeMatcherValue = {

src/util/graphFactories.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Decorations from "../core/Decorations";
99
import FontMeasurements from "../core/FontMeasurements";
1010
import Debug from "../core/Debug";
1111
import { TestCaseRecorder } from "../testUtil/TestCaseRecorder";
12+
import Cheatsheet from "../core/Cheatsheet";
1213

1314
type ConstructorMap<T> = {
1415
[P in keyof T]: new (t: T) => T[P];
@@ -24,6 +25,7 @@ const graphConstructors: Partial<ConstructorMap<Graph>> = {
2425
rangeUpdater: RangeUpdater,
2526
debug: Debug,
2627
testCaseRecorder: TestCaseRecorder,
28+
cheatsheet: Cheatsheet,
2729
};
2830

2931
const graphFactories: Partial<FactoryMap<Graph>> = Object.fromEntries(

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"node_modules",
1919
"src/vendor",
2020
".vscode-test",
21-
"data"
21+
"data",
22+
"cheatsheet"
2223
]
2324
}

0 commit comments

Comments
 (0)