Skip to content

Commit

Permalink
Added private setting to change line iteration scope to paragraph (#2022
Browse files Browse the repository at this point in the history
)

`"cursorless.private.lineParagraphIterationScope": true,`

## 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
  • Loading branch information
AndreasArvidsson authored Nov 12, 2023
1 parent 56b8431 commit d981813
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/common/src/ide/types/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export type CursorlessConfiguration = {
experimental: { snippetsDir: string | undefined; hatStability: HatStability };
decorationDebounceDelayMs: number;
debug: boolean;
private: {
lineParagraphIterationScope: boolean;
};
};

export type CursorlessConfigKey = keyof CursorlessConfiguration;
Expand All @@ -27,6 +30,9 @@ 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
@@ -1,17 +1,25 @@
import { Position, Range, TextEditor } from "@cursorless/common";
import { Direction, ScopeType } from "@cursorless/common";
import {
Direction,
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 = { type: "document" } as const;
public readonly iterationScopeType: ScopeType;
protected readonly isHierarchical = false;
public readonly includeAdjacentInEvery: boolean = true;

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

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

function getIterationScopeTypeType(): SimpleScopeTypeType {
const useParagraph = ide().configuration.getOwnConfiguration(
"private.lineParagraphIterationScope",
);
return useParagraph ? "paragraph" : "document";
}

0 comments on commit d981813

Please sign in to comment.