Skip to content

Commit 15d7254

Browse files
Updated markdown item ranges (#1568)
Fixes #1200 Fixes #1199 Fixes #1107 ## 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 --------- Co-authored-by: Pokey Rule <[email protected]>
1 parent 662065c commit 15d7254

File tree

9 files changed

+235
-7
lines changed

9 files changed

+235
-7
lines changed

packages/cursorless-engine/src/languages/markdown.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const itemLeadingDelimiterExtractor = selectWithLeadingDelimiter(
107107
);
108108

109109
function excludeTrailingNewline(editor: TextEditor, range: Range) {
110-
const matches = getMatchesInRange(/\r?\n?$/g, editor, range);
110+
const matches = getMatchesInRange(/\r?\n\s*$/g, editor, range);
111111

112112
if (matches.length > 0) {
113113
return new Range(range.start, matches[0].start);
@@ -116,11 +116,20 @@ function excludeTrailingNewline(editor: TextEditor, range: Range) {
116116
return range;
117117
}
118118

119-
function itemExtractor(editor: TextEditor, node: SyntaxNode) {
120-
const { context, selection } = itemLeadingDelimiterExtractor(editor, node);
119+
function itemExtractor(
120+
editor: TextEditor,
121+
node: SyntaxNode,
122+
): SelectionWithContext {
123+
const { selection } = itemLeadingDelimiterExtractor(editor, node);
124+
const line = editor.document.lineAt(selection.start);
125+
const leadingRange = new Range(line.range.start, selection.start);
126+
const indent = editor.document.getText(leadingRange);
121127

122128
return {
123-
context,
129+
context: {
130+
containingListDelimiter: `\n${indent}`,
131+
leadingDelimiterRange: leadingRange,
132+
},
124133
selection: excludeTrailingNewline(editor, selection).toSelection(
125134
selection.isReversed,
126135
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
languageId: markdown
2+
command:
3+
version: 5
4+
spokenForm: bring item drum after batt
5+
action: {name: replaceWithTarget}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: collectionItem}
11+
mark: {type: decoratedSymbol, symbolColor: default, character: d}
12+
- type: primitive
13+
mark: {type: decoratedSymbol, symbolColor: default, character: b}
14+
modifiers:
15+
- {type: position, position: after}
16+
usePrePhraseSnapshot: true
17+
initialState:
18+
documentContents: |-
19+
- aaa
20+
- bbb
21+
- ccc
22+
- ddd
23+
selections:
24+
- anchor: {line: 1, character: 4}
25+
active: {line: 1, character: 4}
26+
marks:
27+
default.d:
28+
start: {line: 3, character: 4}
29+
end: {line: 3, character: 7}
30+
default.b:
31+
start: {line: 1, character: 4}
32+
end: {line: 1, character: 7}
33+
finalState:
34+
documentContents: |-
35+
- aaa
36+
- bbb
37+
- ddd
38+
- ccc
39+
- ddd
40+
selections:
41+
- anchor: {line: 1, character: 4}
42+
active: {line: 1, character: 4}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
languageId: markdown
2+
command:
3+
version: 5
4+
spokenForm: chuck item
5+
action: {name: remove}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: collectionItem}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: |-
14+
- aaa
15+
- bbb
16+
- ddd
17+
selections:
18+
- anchor: {line: 1, character: 5}
19+
active: {line: 1, character: 5}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
- aaa
24+
25+
- ddd
26+
selections:
27+
- anchor: {line: 1, character: 0}
28+
active: {line: 1, character: 0}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
languageId: markdown
2+
command:
3+
version: 5
4+
spokenForm: clear item
5+
action: {name: clearAndSetSelection}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: collectionItem}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: |
14+
- aaa
15+
- bbb
16+
- ccc
17+
selections:
18+
- anchor: {line: 1, character: 4}
19+
active: {line: 1, character: 4}
20+
marks: {}
21+
finalState:
22+
documentContents: |
23+
- aaa
24+
-
25+
- ccc
26+
selections:
27+
- anchor: {line: 1, character: 4}
28+
active: {line: 1, character: 4}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
languageId: markdown
2+
command:
3+
version: 5
4+
spokenForm: drink item
5+
action: {name: editNewLineBefore}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: collectionItem}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: |-
14+
- aaa
15+
- bbb
16+
- ccc
17+
- ddd
18+
selections:
19+
- anchor: {line: 1, character: 4}
20+
active: {line: 1, character: 4}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
- aaa
25+
-
26+
- bbb
27+
- ccc
28+
- ddd
29+
selections:
30+
- anchor: {line: 1, character: 4}
31+
active: {line: 1, character: 4}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
languageId: markdown
2+
command:
3+
version: 5
4+
spokenForm: pour item
5+
action: {name: editNewLineAfter}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: collectionItem}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: |-
14+
- aaa
15+
- bbb
16+
- ccc
17+
- ddd
18+
selections:
19+
- anchor: {line: 1, character: 4}
20+
active: {line: 1, character: 4}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
- aaa
25+
- bbb
26+
-
27+
- ccc
28+
- ddd
29+
selections:
30+
- anchor: {line: 2, character: 4}
31+
active: {line: 2, character: 4}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: markdown
2+
command:
3+
version: 5
4+
spokenForm: pour item
5+
action: {name: editNewLineAfter}
6+
targets:
7+
- type: primitive
8+
modifiers:
9+
- type: containingScope
10+
scopeType: {type: collectionItem}
11+
usePrePhraseSnapshot: true
12+
initialState:
13+
documentContents: |-
14+
* aaa bbb
15+
* ccc ddd
16+
selections:
17+
- anchor: {line: 0, character: 2}
18+
active: {line: 0, character: 2}
19+
marks: {}
20+
finalState:
21+
documentContents: |-
22+
* aaa bbb
23+
*
24+
* ccc ddd
25+
selections:
26+
- anchor: {line: 1, character: 2}
27+
active: {line: 1, character: 2}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
languageId: markdown
2+
command:
3+
version: 5
4+
spokenForm: round wrap item air
5+
action:
6+
name: wrapWithPairedDelimiter
7+
args: [(, )]
8+
targets:
9+
- type: primitive
10+
modifiers:
11+
- type: containingScope
12+
scopeType: {type: collectionItem}
13+
mark: {type: decoratedSymbol, symbolColor: default, character: a}
14+
usePrePhraseSnapshot: true
15+
initialState:
16+
documentContents: |
17+
- aaa
18+
- bbb
19+
selections:
20+
- anchor: {line: 2, character: 0}
21+
active: {line: 2, character: 0}
22+
marks:
23+
default.a:
24+
start: {line: 0, character: 2}
25+
end: {line: 0, character: 5}
26+
finalState:
27+
documentContents: |
28+
- (aaa)
29+
- bbb
30+
selections:
31+
- anchor: {line: 2, character: 0}
32+
active: {line: 2, character: 0}

packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/targets/scopeType/pourEntry.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ initialState:
2020
finalState:
2121
documentContents: |-
2222
- Testing
23-
23+
-
2424
- Another test
2525
selections:
26-
- anchor: {line: 1, character: 0}
27-
active: {line: 1, character: 0}
26+
- anchor: {line: 1, character: 2}
27+
active: {line: 1, character: 2}
2828
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: collectionItem}}]}]

0 commit comments

Comments
 (0)