Skip to content

Commit 41cf78d

Browse files
Migrate markdown scopes (#2043)
## Checklist - [-] 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 b70e87e commit 41cf78d

File tree

3 files changed

+21
-38
lines changed

3 files changed

+21
-38
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ const textFragmentExtractors: Record<
131131
htmlStringTextFragmentExtractor,
132132
),
133133
latex: fullDocumentTextFragmentExtractor,
134-
markdown: fullDocumentTextFragmentExtractor,
135134
ruby: constructDefaultTextFragmentExtractor(
136135
"ruby",
137136
rubyStringTextFragmentExtractor,

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

+2-37
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,19 @@
1-
import { Range, Selection, TextEditor } from "@cursorless/common";
1+
import { Range, SimpleScopeTypeType, TextEditor } from "@cursorless/common";
22
import type { SyntaxNode } from "web-tree-sitter";
3-
import { getMatchesInRange } from "../util/getMatchesInRange";
4-
import { SimpleScopeTypeType } from "@cursorless/common";
53
import {
64
NodeFinder,
75
NodeMatcherAlternative,
86
SelectionWithContext,
97
} from "../typings/Types";
8+
import { getMatchesInRange } from "../util/getMatchesInRange";
109
import { leadingSiblingNodeFinder, patternFinder } from "../util/nodeFinders";
1110
import { createPatternMatchers, matcher } from "../util/nodeMatchers";
1211
import {
1312
extendUntilNextMatchingSiblingOrLast,
14-
getNodeRange,
1513
selectWithLeadingDelimiter,
1614
} from "../util/nodeSelectors";
1715
import { shrinkRangeToFitContent } from "../util/selectionUtils";
1816

19-
/**
20-
* Given a node representing the text of a section heading (without leading
21-
* marker), will return the content range as the text without the leading
22-
* whitespace, and the outside range includes the leading marker, so that
23-
* "chuck name" deletes the heading
24-
* @param editor The editor containing the node
25-
* @param node The node to extract from; will be the content of the heading without the leading marker
26-
* @returns The selection with context
27-
*/
28-
function nameExtractor(
29-
editor: TextEditor,
30-
node: SyntaxNode,
31-
): SelectionWithContext {
32-
const range = getNodeRange(node);
33-
const contentRange = range.isEmpty
34-
? range
35-
: range.with(range.start.translate(0, 1));
36-
const removalRange = getNodeRange(node.parent!);
37-
38-
return {
39-
selection: new Selection(contentRange.start, contentRange.end),
40-
context: {
41-
removalRange,
42-
},
43-
};
44-
}
45-
4617
const HEADING_MARKER_TYPES = [
4718
"atx_h1_marker",
4819
"atx_h2_marker",
@@ -139,12 +110,6 @@ function itemExtractor(
139110
const nodeMatchers: Partial<
140111
Record<SimpleScopeTypeType, NodeMatcherAlternative>
141112
> = {
142-
list: ["list"],
143-
comment: "html_block",
144-
name: matcher(
145-
leadingSiblingNodeFinder(patternFinder("atx_heading[heading_content]")),
146-
nameExtractor,
147-
),
148113
collectionItem: matcher(patternFinder("list_item.paragraph!"), itemExtractor),
149114
section: sectionMatcher("atx_heading"),
150115
sectionLevelOne: sectionMatcher("atx_heading.atx_h1_marker"),

queries/markdown.scm

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(document) @textFragment
2+
3+
(html_block) @comment
4+
5+
;;!! * hello * stuff
6+
;;! ^^^^^^^^^^^^^^^
7+
(list) @list
8+
9+
;;!! # Title
10+
;;! ^^^^^
11+
;;!! xxxxxxx
12+
;;! -------
13+
(section
14+
(atx_heading
15+
(_)
16+
heading_content: (_) @name
17+
) @_.removal
18+
(#shrink-to-match! @name "^\\s*(?<keep>.*)$")
19+
) @_.domain

0 commit comments

Comments
 (0)