Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions packages/cursorless-engine/src/languages/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const itemLeadingDelimiterExtractor = selectWithLeadingDelimiter(
);

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

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

function itemExtractor(editor: TextEditor, node: SyntaxNode) {
const { context, selection } = itemLeadingDelimiterExtractor(editor, node);
function itemExtractor(
editor: TextEditor,
node: SyntaxNode,
): SelectionWithContext {
const { selection } = itemLeadingDelimiterExtractor(editor, node);
const line = editor.document.lineAt(selection.start);
const leadingRange = new Range(line.range.start, selection.start);
const indent = editor.document.getText(leadingRange);

return {
context,
context: {
containingListDelimiter: `\n${indent}`,
leadingDelimiterRange: leadingRange,
},
selection: excludeTrailingNewline(editor, selection).toSelection(
selection.isReversed,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
languageId: markdown
command:
version: 5
spokenForm: bring item drum after batt
action: {name: replaceWithTarget}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: collectionItem}
mark: {type: decoratedSymbol, symbolColor: default, character: d}
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: b}
modifiers:
- {type: position, position: after}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
- aaa
- bbb
- ccc
- ddd
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks:
default.d:
start: {line: 3, character: 4}
end: {line: 3, character: 7}
default.b:
start: {line: 1, character: 4}
end: {line: 1, character: 7}
finalState:
documentContents: |-
- aaa
- bbb
- ddd
- ccc
- ddd
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
languageId: markdown
command:
version: 5
spokenForm: chuck item
action: {name: remove}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: collectionItem}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
- aaa
- bbb
- ddd
selections:
- anchor: {line: 1, character: 5}
active: {line: 1, character: 5}
marks: {}
finalState:
documentContents: |-
- aaa

- ddd
selections:
- anchor: {line: 1, character: 0}
active: {line: 1, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
languageId: markdown
command:
version: 5
spokenForm: clear item
action: {name: clearAndSetSelection}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: collectionItem}
usePrePhraseSnapshot: true
initialState:
documentContents: |
- aaa
- bbb
- ccc
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks: {}
finalState:
documentContents: |
- aaa
-
- ccc
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
languageId: markdown
command:
version: 5
spokenForm: drink item
action: {name: editNewLineBefore}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: collectionItem}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
- aaa
- bbb
- ccc
- ddd
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks: {}
finalState:
documentContents: |-
- aaa
-
- bbb
- ccc
- ddd
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
languageId: markdown
command:
version: 5
spokenForm: pour item
action: {name: editNewLineAfter}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: collectionItem}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
- aaa
- bbb
- ccc
- ddd
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks: {}
finalState:
documentContents: |-
- aaa
- bbb
-
- ccc
- ddd
selections:
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: markdown
command:
version: 5
spokenForm: pour item
action: {name: editNewLineAfter}
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: collectionItem}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
* aaa bbb
* ccc ddd
selections:
- anchor: {line: 0, character: 2}
active: {line: 0, character: 2}
marks: {}
finalState:
documentContents: |-
* aaa bbb
*
* ccc ddd
selections:
- anchor: {line: 1, character: 2}
active: {line: 1, character: 2}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
languageId: markdown
command:
version: 5
spokenForm: round wrap item air
action:
name: wrapWithPairedDelimiter
args: [(, )]
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: collectionItem}
mark: {type: decoratedSymbol, symbolColor: default, character: a}
usePrePhraseSnapshot: true
initialState:
documentContents: |
- aaa
- bbb
selections:
- anchor: {line: 2, character: 0}
active: {line: 2, character: 0}
marks:
default.a:
start: {line: 0, character: 2}
end: {line: 0, character: 5}
finalState:
documentContents: |
- (aaa)
- bbb
selections:
- anchor: {line: 2, character: 0}
active: {line: 2, character: 0}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ initialState:
finalState:
documentContents: |-
- Testing

-
- Another test
selections:
- anchor: {line: 1, character: 0}
active: {line: 1, character: 0}
- anchor: {line: 1, character: 2}
active: {line: 1, character: 2}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: collectionItem}}]}]