Skip to content

Commit

Permalink
Make paragraph line iteration scope (#2060)
Browse files Browse the repository at this point in the history
## 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 <755842+pokey@users.noreply.github.com>
  • Loading branch information
AndreasArvidsson and pokey authored Dec 5, 2023
1 parent 990c98b commit a4ab8da
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
6 changes: 0 additions & 6 deletions packages/common/src/ide/types/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export type CursorlessConfiguration = {
experimental: { snippetsDir: string | undefined; hatStability: HatStability };
decorationDebounceDelayMs: number;
debug: boolean;
private: {
lineParagraphIterationScope: boolean;
};
};

export type CursorlessConfigKey = keyof CursorlessConfiguration;
Expand All @@ -30,9 +27,6 @@ export const CONFIGURATION_DEFAULTS: CursorlessConfiguration = {
hatStability: HatStability.balanced,
},
debug: false,
private: {
lineParagraphIterationScope: false,
},
};

export interface Configuration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ import {
Position,
Range,
ScopeType,
SimpleScopeTypeType,
TextEditor,
} from "@cursorless/common";
import { ide } from "../../../singletons/ide.singleton";
import { LineTarget } from "../../targets";
import { BaseScopeHandler } from "./BaseScopeHandler";
import type { TargetScope } from "./scope.types";

export class LineScopeHandler extends BaseScopeHandler {
public readonly scopeType = { type: "line" } as const;
public readonly iterationScopeType: ScopeType;
public readonly iterationScopeType: ScopeType = {
type: "paragraph",
} as const;
protected readonly isHierarchical = false;
public readonly includeAdjacentInEvery: boolean = true;

constructor(_scopeType: ScopeType, _languageId: string) {
super();
this.iterationScopeType = { type: getIterationScopeTypeType() };
}

*generateScopeCandidates(
Expand Down Expand Up @@ -75,10 +74,3 @@ export function fitRangeToLineContent(editor: TextEditor, range: Range) {
endLine.lastNonWhitespaceCharacterIndex,
);
}

function getIterationScopeTypeType(): SimpleScopeTypeType {
const useParagraph = ide().configuration.getOwnConfiguration(
"private.lineParagraphIterationScope",
);
return useParagraph ? "paragraph" : "document";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
languageId: plaintext
command:
version: 6
spokenForm: change every line
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: everyScope
scopeType: {type: line}
usePrePhraseSnapshot: true
initialState:
documentContents: |
a
b c
d e
f g
selections:
- anchor: {line: 3, character: 0}
active: {line: 3, character: 0}
marks: {}
finalState:
documentContents: |+
a
selections:
- anchor: {line: 3, character: 0}
active: {line: 3, character: 0}
- anchor: {line: 4, character: 0}
active: {line: 4, character: 0}
- anchor: {line: 5, character: 0}
active: {line: 5, character: 0}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
languageId: plaintext
command:
spokenForm: change every line
spokenForm: change every line file
version: 3
targets:
- type: primitive
modifiers:
- type: everyScope
scopeType: {type: line}
- type: containingScope
scopeType: {type: document}
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
languageId: plaintext
command:
spokenForm: take every line
spokenForm: take every line file
version: 2
action: {name: setSelection}
targets:
- type: primitive
modifiers:
- type: everyScope
scopeType: {type: line}
- type: containingScope
scopeType: {type: document}
usePrePhraseSnapshot: true
initialState:
documentContents: |
Expand Down

0 comments on commit a4ab8da

Please sign in to comment.