Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Dec 7, 2023
1 parent 09a7b9a commit c8ba960
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
10 changes: 10 additions & 0 deletions docs/user/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,16 @@ eg:
- `join air`: Join the line with the token containing the letter 'a' with its next line.
- `join block air`: Joines all lines in the paragraph with the token containing the letter 'a' together into a single line.
### Break
Break line in two.
- `"break <TARGET>"`
eg:
- `break air`: Break the line with the token containing the letter 'a'. 'a' is now the first token on the new line.
## Paired delimiters
| Default spoken form | Delimiter name | Symbol inserted before target | Symbol inserted after target | Is wrapper? | Is selectable? |
Expand Down
15 changes: 13 additions & 2 deletions packages/cursorless-engine/src/actions/BreakLine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FlashStyle, Range, TextEditor } from "@cursorless/common";
import { FlashStyle, Position, Range, TextEditor } from "@cursorless/common";
import { flatten, zip } from "lodash";
import type { RangeUpdater } from "../core/updateSelections/RangeUpdater";
import { performEditsAndUpdateRanges } from "../core/updateSelections/updateSelections";
Expand Down Expand Up @@ -50,10 +50,21 @@ function getEdits(editor: TextEditor, contentRanges: Range[]): Edit[] {
0,
line.firstNonWhitespaceCharacterIndex,
);
const characterTrailingWhitespace = line.text
.slice(0, position.character)
.search(/\s+$/);
const replacementRange =
characterTrailingWhitespace > -1
? new Range(
new Position(line.lineNumber, characterTrailingWhitespace),
position,
)
: position.toEmptyRange();

edits.push({
range: position.toEmptyRange(),
range: replacementRange,
text: "\n" + indentation,
isReplace: !replacementRange.isEmpty,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ initialState:
end: {line: 0, character: 7}
finalState:
documentContents: |-
aaa
aaa
bbb ccc
selections:
- anchor: {line: 0, character: 0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ finalState:
documentContents: |-
[
0,
1,
1,
// interesting
2
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
languageId: plaintext
command:
version: 6
spokenForm: break just this
action:
name: breakLine
target:
type: primitive
mark: {type: cursor}
modifiers:
- {type: toRawSelection}
usePrePhraseSnapshot: true
initialState:
documentContents: "ab "
selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
marks: {}
finalState:
documentContents: |-
a
b
selections:
- anchor: {line: 1, character: 0}
active: {line: 1, character: 0}
thatMark:
- type: UntypedTarget
contentRange:
start: {line: 1, character: 0}
end: {line: 1, character: 0}
isReversed: false
hasExplicitRange: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
languageId: plaintext
command:
version: 6
spokenForm: break just this
action:
name: breakLine
target:
type: primitive
mark: {type: cursor}
modifiers:
- {type: toRawSelection}
usePrePhraseSnapshot: true
initialState:
documentContents: " ab "
selections:
- anchor: {line: 0, character: 5}
active: {line: 0, character: 5}
marks: {}
finalState:
documentContents: |2-
a
b
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
thatMark:
- type: UntypedTarget
contentRange:
start: {line: 1, character: 4}
end: {line: 1, character: 4}
isReversed: false
hasExplicitRange: true

0 comments on commit c8ba960

Please sign in to comment.