Skip to content

Commit 14e6c58

Browse files
Added iteration scope to markdown sections (#2770)
Fixes #879 ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
1 parent 33e5368 commit 14e6c58

File tree

7 files changed

+140
-0
lines changed

7 files changed

+140
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
languageId: markdown
2+
command:
3+
version: 7
4+
spokenForm: change every section
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: everyScope
11+
scopeType: {type: section}
12+
usePrePhraseSnapshot: false
13+
initialState:
14+
documentContents: |-
15+
# h1
16+
Aaa
17+
18+
## h2.1
19+
Bbb
20+
21+
## h2.2
22+
Ccc
23+
selections:
24+
- anchor: {line: 3, character: 0}
25+
active: {line: 3, character: 0}
26+
marks: {}
27+
finalState:
28+
documentContents: |+
29+
# h1
30+
Aaa
31+
32+
33+
34+
selections:
35+
- anchor: {line: 3, character: 0}
36+
active: {line: 3, character: 0}
37+
- anchor: {line: 5, character: 0}
38+
active: {line: 5, character: 0}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# h1.1
2+
Aaa
3+
4+
# h1.2
5+
Bbb
6+
---
7+
8+
[#1 Range] =
9+
[#1 Domain] = 0:0-4:3
10+
>------
11+
0| # h1.1
12+
1| Aaa
13+
2|
14+
3| # h1.2
15+
4| Bbb
16+
---<
17+
18+
19+
[#2 Range] =
20+
[#2 Domain] = 1:0-1:3
21+
>---<
22+
1| Aaa
23+
24+
25+
[#3 Range] =
26+
[#3 Domain] = 4:0-4:3
27+
>---<
28+
4| Bbb
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# h1
2+
Aaa
3+
4+
## h2.1
5+
Bbb
6+
7+
## h2.2
8+
Ccc
9+
---
10+
11+
[#1 Range] =
12+
[#1 Domain] = 0:0-7:3
13+
>----
14+
0| # h1
15+
1| Aaa
16+
2|
17+
3| ## h2.1
18+
4| Bbb
19+
5|
20+
6| ## h2.2
21+
7| Ccc
22+
---<
23+
24+
25+
[#2 Range] =
26+
[#2 Domain] = 1:0-7:3
27+
>---
28+
1| Aaa
29+
2|
30+
3| ## h2.1
31+
4| Bbb
32+
5|
33+
6| ## h2.2
34+
7| Ccc
35+
---<
36+
37+
38+
[#3 Range] =
39+
[#3 Domain] = 4:0-4:3
40+
>---<
41+
4| Bbb
42+
43+
44+
[#4 Range] =
45+
[#4 Domain] = 7:0-7:3
46+
>---<
47+
7| Ccc

packages/common/src/scopeSupportFacets/markdown.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel;
77
export const markdownScopeSupport: LanguageScopeSupportFacetMap = {
88
"comment.line": supported,
99
"comment.block": supported,
10+
1011
section: supported,
12+
"section.iteration.document": supported,
13+
"section.iteration.parent": supported,
14+
1115
notebookCell: supported,
1216
"collectionItem.unenclosed": supported,
1317
};

packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ export const scopeSupportFacetInfos: Record<
4242
description: "A document section",
4343
scopeType: "section",
4444
},
45+
"section.iteration.document": {
46+
description:
47+
"Iteration scope for a document section. This is the entire document.",
48+
scopeType: "section",
49+
isIteration: true,
50+
},
51+
"section.iteration.parent": {
52+
description:
53+
"Iteration scope for a document section. This is the parent section.",
54+
scopeType: "section",
55+
isIteration: true,
56+
},
4557

4658
list: {
4759
description: "A list/array",

packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const scopeSupportFacets = [
1313
"environment",
1414

1515
"section",
16+
"section.iteration.document",
17+
"section.iteration.parent",
1618

1719
"list",
1820
"map",

queries/markdown.scm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,12 @@
130130
) @sectionLevelSix @_.removal
131131
(#trim-end! @sectionLevelSix)
132132
)
133+
134+
(document) @section.iteration
135+
136+
(
137+
(section
138+
(atx_heading) @section.iteration.start.endOf
139+
) @section.iteration.end.endOf
140+
(#trim-end! @section.iteration.end.endOf)
141+
)

0 commit comments

Comments
 (0)