Skip to content

Commit 913b7b1

Browse files
committed
HTML cheatsheet VSCode extension-side
Initial VSCode extension cheatsheet processing Initial dom manipulation
1 parent dc611c4 commit 913b7b1

File tree

9 files changed

+150
-6
lines changed

9 files changed

+150
-6
lines changed

cursorless-talon/src/cheatsheet/cheat_sheet.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import math
2+
import tempfile
23
import webbrowser
4+
from pathlib import Path
35

46
from talon import Module, actions, cron, skia, ui
57
from talon.canvas import Canvas
@@ -288,13 +290,20 @@ def draw_value(self, canvas, text):
288290
self.w = max(self.w, rect.width)
289291

290292

293+
cheatsheet_out_dir = Path(tempfile.mkdtemp())
294+
295+
291296
@mod.action_class
292297
class Actions:
293298
def cursorless_cheat_sheet_toggle():
294299
"""Toggle cursorless cheat sheet"""
295-
actions.user.vscode_with_plugin(
296-
"cursorless.showCheatsheet", actions.user.cursorless_cheat_sheet_get_json()
300+
cheatsheet_out_path = cheatsheet_out_dir / "cheatsheet.html"
301+
actions.user.vscode_with_plugin_and_wait(
302+
"cursorless.showCheatsheet",
303+
actions.user.cursorless_cheat_sheet_get_json(),
304+
str(cheatsheet_out_path),
297305
)
306+
webbrowser.open(cheatsheet_out_path.as_uri())
298307

299308
def cursorless_cheat_sheet_get_json():
300309
"""Get cursorless cheat sheet json"""

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@
537537
"dependencies": {
538538
"@types/lodash": "^4.14.168",
539539
"immutability-helper": "^3.1.1",
540-
"lodash": "^4.17.21"
540+
"lodash": "^4.17.21",
541+
"node-html-parser": "^5.3.3"
541542
}
542543
}

src/core/Cheatsheet.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as vscode from "vscode";
2+
import { Graph } from "../typings/Types";
3+
import { readFile, writeFile } from "fs/promises";
4+
import path = require("path");
5+
import parse from "node-html-parser";
6+
7+
type SpokenFormInfo = unknown;
8+
9+
export default class Cheatsheet {
10+
private disposables: vscode.Disposable[] = [];
11+
12+
constructor(private graph: Graph) {
13+
graph.extensionContext.subscriptions.push(this);
14+
}
15+
16+
init() {
17+
this.disposables.push(
18+
vscode.commands.registerCommand(
19+
"cursorless.showCheatsheet",
20+
async (spokenFormInfo: SpokenFormInfo, outputPath: str) => {
21+
const cheatsheetPath = path.join(
22+
this.graph.extensionContext.extensionPath,
23+
"dist",
24+
"assets",
25+
"cheatsheet-local",
26+
"index.html"
27+
);
28+
const cheatsheetContent = (await readFile(cheatsheetPath)).toString();
29+
const root = parse(cheatsheetContent);
30+
root.getElementById(
31+
"cheatsheet-data"
32+
).textContent = `document.cheatsheetData = ${JSON.stringify(
33+
spokenFormInfo
34+
)};`;
35+
36+
await writeFile(outputPath, root.toString());
37+
}
38+
)
39+
);
40+
}
41+
42+
dispose() {
43+
this.disposables.forEach(({ dispose }) => dispose());
44+
}
45+
}

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
@@ -488,6 +489,11 @@ export interface Graph {
488489
* Used for recording test cases
489490
*/
490491
readonly testCaseRecorder: TestCaseRecorder;
492+
493+
/**
494+
* Used to display cheatsheet
495+
*/
496+
readonly cheatsheet: Cheatsheet;
491497
}
492498

493499
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(

third-party-licenses.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"[email protected]","MIT","https://github.com/lukeed/clsx","https://github.com/lukeed/clsx/raw/master/license","website"
77
"[email protected]","MIT","https://github.com/kolodny/immutability-helper","https://github.com/kolodny/immutability-helper/raw/master/LICENSE","cursorless"
88
"[email protected]","MIT","https://github.com/syntax-tree/mdast-util-find-and-replace","https://github.com/syntax-tree/mdast-util-find-and-replace/raw/master/license","website"
9+
"[email protected]","MIT","https://github.com/taoqf/node-fast-html-parser","https://github.com/taoqf/node-fast-html-parser/raw/master/LICENSE","cursorless"
910
"[email protected]","MIT","https://github.com/FormidableLabs/prism-react-renderer","https://github.com/FormidableLabs/prism-react-renderer/raw/master/LICENSE","website"
1011
"[email protected]","MIT","https://github.com/facebook/react","https://github.com/facebook/react/raw/master/LICENSE","website"
1112
"[email protected]","MIT","https://github.com/facebook/react","https://github.com/facebook/react/raw/master/LICENSE","website"
12-
"[email protected]","MIT","https://github.com/syntax-tree/unist-util-visit","https://github.com/syntax-tree/unist-util-visit/raw/master/license","website"
13+
"[email protected]","MIT","https://github.com/syntax-tree/unist-util-visit","https://github.com/syntax-tree/unist-util-visit/raw/master/license","website"

tsconfig.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"module": "commonjs",
44
"target": "es6",
55
"outDir": "out",
6-
"lib": ["es2020"],
6+
"lib": [
7+
"es2020"
8+
],
79
"sourceMap": true,
810
"rootDir": "src",
911
"strict": true /* enable all strict type-checking options */
@@ -12,5 +14,11 @@
1214
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
1315
// "noUnusedParameters": true, /* Report errors on unused parameters. */
1416
},
15-
"exclude": ["node_modules", "src/vendor", ".vscode-test", "data"]
17+
"exclude": [
18+
"cursorless-nx",
19+
"node_modules",
20+
"src/vendor",
21+
".vscode-test",
22+
"data"
23+
]
1624
}

yarn.lock

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ bluebird@~3.4.1:
371371
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.4.7.tgz#f72d760be09b7f76d08ed8fae98b289a8d05fab3"
372372
integrity sha1-9y12C+Cbf3bQjtj66Ysomo0F+rM=
373373

374+
boolbase@^1.0.0:
375+
version "1.0.0"
376+
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
377+
integrity sha1-aN/1++YMUes3cl6p4+0xDcwed24=
378+
374379
brace-expansion@^1.1.7:
375380
version "1.1.11"
376381
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@@ -513,6 +518,22 @@ cross-spawn@^7.0.2:
513518
shebang-command "^2.0.0"
514519
which "^2.0.1"
515520

521+
css-select@^4.2.1:
522+
version "4.3.0"
523+
resolved "https://registry.yarnpkg.com/css-select/-/css-select-4.3.0.tgz#db7129b2846662fd8628cfc496abb2b59e41529b"
524+
integrity sha512-wPpOYtnsVontu2mODhA19JrqWxNsfdatRKd64kmpRbQgh1KtItko5sTnEpPdpSaJszTOhEMlF/RPz28qj4HqhQ==
525+
dependencies:
526+
boolbase "^1.0.0"
527+
css-what "^6.0.1"
528+
domhandler "^4.3.1"
529+
domutils "^2.8.0"
530+
nth-check "^2.0.1"
531+
532+
css-what@^6.0.1:
533+
version "6.1.0"
534+
resolved "https://registry.yarnpkg.com/css-what/-/css-what-6.1.0.tgz#fb5effcf76f1ddea2c81bdfaa4de44e79bac70f4"
535+
integrity sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==
536+
516537
debug@4, debug@^4.1.1, debug@^4.3.2:
517538
version "4.3.4"
518539
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
@@ -569,6 +590,36 @@ doctrine@^3.0.0:
569590
dependencies:
570591
esutils "^2.0.2"
571592

593+
dom-serializer@^1.0.1:
594+
version "1.4.1"
595+
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-1.4.1.tgz#de5d41b1aea290215dc45a6dae8adcf1d32e2d30"
596+
integrity sha512-VHwB3KfrcOOkelEG2ZOfxqLZdfkil8PtJi4P8N2MMXucZq2yLp75ClViUlOVwyoHEDjYU433Aq+5zWP61+RGag==
597+
dependencies:
598+
domelementtype "^2.0.1"
599+
domhandler "^4.2.0"
600+
entities "^2.0.0"
601+
602+
domelementtype@^2.0.1, domelementtype@^2.2.0:
603+
version "2.3.0"
604+
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-2.3.0.tgz#5c45e8e869952626331d7aab326d01daf65d589d"
605+
integrity sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==
606+
607+
domhandler@^4.2.0, domhandler@^4.3.1:
608+
version "4.3.1"
609+
resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-4.3.1.tgz#8d792033416f59d68bc03a5aa7b018c1ca89279c"
610+
integrity sha512-GrwoxYN+uWlzO8uhUXRl0P+kHE4GtVPfYzVLcUxPL7KNdHKj66vvlhiweIHqYYXWlw+T8iLMp42Lm67ghw4WMQ==
611+
dependencies:
612+
domelementtype "^2.2.0"
613+
614+
domutils@^2.8.0:
615+
version "2.8.0"
616+
resolved "https://registry.yarnpkg.com/domutils/-/domutils-2.8.0.tgz#4437def5db6e2d1f5d6ee859bd95ca7d02048135"
617+
integrity sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==
618+
dependencies:
619+
dom-serializer "^1.0.1"
620+
domelementtype "^2.2.0"
621+
domhandler "^4.2.0"
622+
572623
duplexer2@~0.1.4:
573624
version "0.1.4"
574625
resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1"
@@ -581,6 +632,11 @@ emoji-regex@^8.0.0:
581632
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
582633
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==
583634

635+
entities@^2.0.0:
636+
version "2.2.0"
637+
resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
638+
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==
639+
584640
esbuild@^0.11.12:
585641
version "0.11.23"
586642
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.11.23.tgz#c42534f632e165120671d64db67883634333b4b8"
@@ -1268,6 +1324,14 @@ nise@^5.1.0:
12681324
just-extend "^4.0.2"
12691325
path-to-regexp "^1.7.0"
12701326

1327+
node-html-parser@^5.3.3:
1328+
version "5.3.3"
1329+
resolved "https://registry.yarnpkg.com/node-html-parser/-/node-html-parser-5.3.3.tgz#2845704f3a7331a610e0e551bf5fa02b266341b6"
1330+
integrity sha512-ncg1033CaX9UexbyA7e1N0aAoAYRDiV8jkTvzEnfd1GDvzFdrsXLzR4p4ik8mwLgnaKP/jyUFWDy9q3jvRT2Jw==
1331+
dependencies:
1332+
css-select "^4.2.1"
1333+
he "1.2.0"
1334+
12711335
nopt-defaults@^0.0.1:
12721336
version "0.0.1"
12731337
resolved "https://registry.yarnpkg.com/nopt-defaults/-/nopt-defaults-0.0.1.tgz#f150fcc8882309cbfb76187e12e9bcb20694558b"
@@ -1321,6 +1385,13 @@ npm-license-crawler@^0.2.1:
13211385
nopt-usage "^0.1.0"
13221386
treeify "^1.1.0"
13231387

1388+
nth-check@^2.0.1:
1389+
version "2.0.1"
1390+
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.0.1.tgz#2efe162f5c3da06a28959fbd3db75dbeea9f0fc2"
1391+
integrity sha512-it1vE95zF6dTT9lBsYbxvqh0Soy4SPowchj0UBGj/V6cTPnXXtQOPUbhZ6CmGzAD/rW22LQK6E96pcdJXk4A4w==
1392+
dependencies:
1393+
boolbase "^1.0.0"
1394+
13241395
once@^1.3.0:
13251396
version "1.4.0"
13261397
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"

0 commit comments

Comments
 (0)