-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`"join air"` `"join block air"` Fixes #50 ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [x] 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) - [x] I have not broken the cheatsheet --------- Co-authored-by: Pokey Rule <755842+pokey@users.noreply.github.com>
- Loading branch information
1 parent
70cbd86
commit 740e3ef
Showing
15 changed files
with
362 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
tags: [enhancement] | ||
pullRequest: 1901 | ||
--- | ||
|
||
- Added `join` action. This action will join multiple lines together. eg `"join air"` or `"join three lines air"`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { FlashStyle, Range, TextEditor } from "@cursorless/common"; | ||
import { flatten, zip } from "lodash"; | ||
import type { RangeUpdater } from "../core/updateSelections/RangeUpdater"; | ||
import { performEditsAndUpdateRanges } from "../core/updateSelections/updateSelections"; | ||
import { ide } from "../singletons/ide.singleton"; | ||
import { Edit } from "../typings/Types"; | ||
import { Target } from "../typings/target.types"; | ||
import { flashTargets, runOnTargetsForEachEditor } from "../util/targetUtils"; | ||
import type { ActionReturnValue } from "./actions.types"; | ||
import { range as iterRange, map, pairwise } from "itertools"; | ||
|
||
export default class JoinLines { | ||
constructor(private rangeUpdater: RangeUpdater) { | ||
this.run = this.run.bind(this); | ||
} | ||
|
||
async run(targets: Target[]): Promise<ActionReturnValue> { | ||
await flashTargets(ide(), targets, FlashStyle.pendingModification0); | ||
|
||
const thatSelections = flatten( | ||
await runOnTargetsForEachEditor(targets, async (editor, targets) => { | ||
const contentRanges = targets.map(({ contentRange }) => contentRange); | ||
const edits = getEdits(editor, contentRanges); | ||
|
||
const [updatedRanges] = await performEditsAndUpdateRanges( | ||
this.rangeUpdater, | ||
ide().getEditableTextEditor(editor), | ||
edits, | ||
[contentRanges], | ||
); | ||
|
||
return zip(targets, updatedRanges).map(([target, range]) => ({ | ||
editor: target!.editor, | ||
selection: range!.toSelection(target!.isReversed), | ||
})); | ||
}), | ||
); | ||
|
||
return { thatSelections }; | ||
} | ||
} | ||
|
||
function getEdits(editor: TextEditor, contentRanges: Range[]): Edit[] { | ||
const { document } = editor; | ||
const edits: Edit[] = []; | ||
|
||
for (const range of contentRanges) { | ||
const startLine = range.start.line; | ||
const endLine = range.isSingleLine ? startLine + 1 : range.end.line; | ||
|
||
const lineIter = map(iterRange(startLine, endLine + 1), (i) => | ||
document.lineAt(i), | ||
); | ||
for (const [line1, line2] of pairwise(lineIter)) { | ||
edits.push({ | ||
range: new Range( | ||
line1.range.end.line, | ||
line1.lastNonWhitespaceCharacterIndex, | ||
line2.range.start.line, | ||
line2.firstNonWhitespaceCharacterIndex, | ||
), | ||
text: line2.isEmptyOrWhitespace ? "" : " ", | ||
isReplace: true, | ||
}); | ||
} | ||
} | ||
|
||
return edits; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/actions/joinAir.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
languageId: plaintext | ||
command: | ||
version: 6 | ||
spokenForm: join air | ||
action: | ||
name: joinLines | ||
target: | ||
type: primitive | ||
mark: {type: decoratedSymbol, symbolColor: default, character: a} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
aaa | ||
bbb | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
marks: | ||
default.a: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 3} | ||
finalState: | ||
documentContents: aaa bbb | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
thatMark: | ||
- type: UntypedTarget | ||
contentRange: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 3} | ||
isReversed: false | ||
hasExplicitRange: true |
33 changes: 33 additions & 0 deletions
33
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/actions/joinAir2.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
languageId: plaintext | ||
command: | ||
version: 6 | ||
spokenForm: join air | ||
action: | ||
name: joinLines | ||
target: | ||
type: primitive | ||
mark: {type: decoratedSymbol, symbolColor: default, character: a} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
aaa | ||
bbb | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
marks: | ||
default.a: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 3} | ||
finalState: | ||
documentContents: aaa bbb | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
thatMark: | ||
- type: UntypedTarget | ||
contentRange: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 3} | ||
isReversed: false | ||
hasExplicitRange: true |
33 changes: 33 additions & 0 deletions
33
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/actions/joinAir3.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
languageId: plaintext | ||
command: | ||
version: 6 | ||
spokenForm: join air | ||
action: | ||
name: joinLines | ||
target: | ||
type: primitive | ||
mark: {type: decoratedSymbol, symbolColor: default, character: a} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
aaa | ||
bbb | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
marks: | ||
default.a: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 3} | ||
finalState: | ||
documentContents: aaa bbb | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
thatMark: | ||
- type: UntypedTarget | ||
contentRange: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 3} | ||
isReversed: false | ||
hasExplicitRange: true |
33 changes: 33 additions & 0 deletions
33
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/actions/joinAir4.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
languageId: plaintext | ||
command: | ||
version: 6 | ||
spokenForm: join air | ||
action: | ||
name: joinLines | ||
target: | ||
type: primitive | ||
mark: {type: decoratedSymbol, symbolColor: default, character: a} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
aaa | ||
bbb | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
marks: | ||
default.a: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 3} | ||
finalState: | ||
documentContents: aaa bbb | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
thatMark: | ||
- type: UntypedTarget | ||
contentRange: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 3} | ||
isReversed: false | ||
hasExplicitRange: true |
33 changes: 33 additions & 0 deletions
33
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/actions/joinBlock.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
languageId: plaintext | ||
command: | ||
version: 6 | ||
spokenForm: join block | ||
action: | ||
name: joinLines | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: paragraph} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
aaa | ||
bbb | ||
ccc | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: aaa bbb ccc | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
thatMark: | ||
- type: UntypedTarget | ||
contentRange: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 11} | ||
isReversed: false | ||
hasExplicitRange: true |
35 changes: 35 additions & 0 deletions
35
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/actions/joinFile.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
languageId: plaintext | ||
command: | ||
version: 6 | ||
spokenForm: join file | ||
action: | ||
name: joinLines | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: document} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |+ | ||
aaa | ||
bbb | ||
selections: | ||
- anchor: {line: 5, character: 0} | ||
active: {line: 5, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: aaa bbb | ||
selections: | ||
- anchor: {line: 0, character: 7} | ||
active: {line: 0, character: 7} | ||
thatMark: | ||
- type: UntypedTarget | ||
contentRange: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 7} | ||
isReversed: false | ||
hasExplicitRange: true |
33 changes: 33 additions & 0 deletions
33
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/actions/joinLineThis.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
languageId: plaintext | ||
command: | ||
version: 6 | ||
spokenForm: join this | ||
action: | ||
name: joinLines | ||
target: | ||
type: primitive | ||
mark: {type: cursor} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
aaa | ||
bbb | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
aaa | ||
bbb | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
thatMark: | ||
- type: UntypedTarget | ||
contentRange: | ||
start: {line: 0, character: 0} | ||
end: {line: 0, character: 3} | ||
isReversed: false | ||
hasExplicitRange: true |
Oops, something went wrong.