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
1 change: 1 addition & 0 deletions cursorless-talon/src/spoken_forms.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"token": "token",
"identifier": "identifier",
"line": "line",
"full line": "fullLine",
"sentence": "sentence",
"block": "paragraph",
"file": "document",
Expand Down
10 changes: 10 additions & 0 deletions data/fixtures/scopes/plaintext/fullLine.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Hello world
---

[Content] =
[Removal] =
[Domain] = 0:0-0:17
>-----------------<
0| Hello world

[Insertion delimiter] = "\n"
96 changes: 96 additions & 0 deletions data/fixtures/scopes/plaintext/fullLine2.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

Hello
world

---

[#1 Content] =
[#1 Domain] = 0:0-0:0
><
0|

[#1 Removal] = 0:0-1:0
>
0|
1| Hello
<

[#1 Trailing delimiter] = 0:0-1:0
>
0|
1| Hello
<

[#1 Insertion delimiter] = "\n"


[#2 Content] =
[#2 Domain] = 1:0-1:5
>-----<
1| Hello

[#2 Removal] = 1:0-2:0
>-----
1| Hello
2| world
<

[#2 Leading delimiter] = 0:0-1:0
>
0|
1| Hello
<

[#2 Trailing delimiter] = 1:5-2:0
>
1| Hello
2| world
<

[#2 Insertion delimiter] = "\n"


[#3 Content] =
[#3 Domain] = 2:0-2:7
>-------<
2| world

[#3 Removal] = 2:0-3:0
>-------
2| world
3|
<

[#3 Leading delimiter] = 1:5-2:0
>
1| Hello
2| world
<

[#3 Trailing delimiter] = 2:7-3:0
>
2| world
3|
<

[#3 Insertion delimiter] = "\n"


[#4 Content] =
[#4 Domain] = 3:0-3:2
>--<
3|

[#4 Removal] = 2:7-3:2
>
2| world
3|
--<

[#4 Leading delimiter] = 2:7-3:0
>
2| world
3|
<

[#4 Insertion delimiter] = "\n"
6 changes: 5 additions & 1 deletion data/scopeSupportFacetInfos.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@

- `fieldAccess` A field access

### fullLine

- `fullLine` A single full line in the document. Includes leading and trailing whitespace.

### functionCall

- `functionCall` A function call
Expand Down Expand Up @@ -196,7 +200,7 @@

### line

- `line` A single line in the document
- `line` A single line in the document. Excludes leading and trailing whitespace.

### list

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ export const plaintextScopeSupportFacetInfos: Record<
scopeType: "identifier",
},
line: {
description: "A single line in the document",
description:
"A single line in the document. Excludes leading and trailing whitespace.",
scopeType: "line",
},
fullLine: {
description:
"A single full line in the document. Includes leading and trailing whitespace.",
scopeType: "fullLine",
},
sentence: {
description: "A single sentence in the document",
scopeType: "sentence",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export type PlaintextScopeSupportFacet =
| "token"
| "identifier"
| "line"
| "fullLine"
| "sentence"
| "paragraph"
| "boundedParagraph"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export const simpleScopeTypeTypes = [
"token",
"identifier",
"line",
"fullLine",
"sentence",
"paragraph",
"boundedParagraph",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type {
} from "@cursorless/common";
import { ide } from "../../singletons/ide.singleton";
import type { MarkStage } from "../PipelineStages.types";
import { createLineTarget } from "../modifiers/scopeHandlers";
import type { LineTarget } from "../targets";
import { createLineTarget } from "../targets";

export class LineNumberStage implements MarkStage {
constructor(private mark: LineNumberMark) {}
Expand All @@ -21,8 +21,8 @@ export class LineNumberStage implements MarkStage {
this.mark.lineNumberType,
this.mark.lineNumber,
);
const contentRange = editor.document.lineAt(lineNumber).range;
return [createLineTarget(editor, false, contentRange)];
const line = editor.document.lineAt(lineNumber);
return [createLineTarget(editor, false, line)];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ import type {
ScopeType,
TextEditor,
} from "@cursorless/common";
import { Range } from "@cursorless/common";
import { LineTarget } from "../../targets";
import { createLineTarget } from "../../targets";
import { BaseScopeHandler } from "./BaseScopeHandler";
import type { TargetScope } from "./scope.types";

interface LineScopeType {
type: "line" | "fullLine";
}

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

constructor(_scopeType: ScopeType, _languageId: string) {
constructor(
public readonly scopeType: LineScopeType,
_languageId: string,
) {
super();
}

Expand All @@ -26,48 +31,32 @@ export class LineScopeHandler extends BaseScopeHandler {
position: Position,
direction: Direction,
): Iterable<TargetScope> {
const useFullLine = this.scopeType.type === "fullLine";

if (direction === "forward") {
for (let i = position.line; i < editor.document.lineCount; i++) {
yield lineNumberToScope(editor, i);
yield lineNumberToScope(editor, useFullLine, i);
}
} else {
for (let i = position.line; i >= 0; i--) {
yield lineNumberToScope(editor, i);
yield lineNumberToScope(editor, useFullLine, i);
}
}
}
}

function lineNumberToScope(
editor: TextEditor,
useFullLine: boolean,
lineNumber: number,
): TargetScope {
const { range } = editor.document.lineAt(lineNumber);
const line = editor.document.lineAt(lineNumber);

return {
editor,
domain: range,
getTargets: (isReversed) => [createLineTarget(editor, isReversed, range)],
domain: line.range,
getTargets: (isReversed) => [
createLineTarget(editor, isReversed, line, useFullLine),
],
};
}

export function createLineTarget(
editor: TextEditor,
isReversed: boolean,
range: Range,
) {
return new LineTarget({
editor,
isReversed,
contentRange: fitRangeToLineContent(editor, range),
});
}

export function fitRangeToLineContent(editor: TextEditor, range: Range) {
const startLine = editor.document.lineAt(range.start);
const endLine = editor.document.lineAt(range.end);
return new Range(
startLine.rangeTrimmed?.start ?? startLine.range.start,
endLine.rangeTrimmed?.end ?? endLine.range.end,
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type {
Direction,
Position,
Range,
ScopeType,
TextDocument,
TextEditor,
TextLine,
} from "@cursorless/common";
import { Range } from "@cursorless/common";
import { ParagraphTarget } from "../../targets";
import { BaseScopeHandler } from "./BaseScopeHandler";
import { fitRangeToLineContent } from "./LineScopeHandler";
import type { TargetScope } from "./scope.types";

export class ParagraphScopeHandler extends BaseScopeHandler {
Expand Down Expand Up @@ -95,3 +94,12 @@ function createScope(editor: TextEditor, domain: Range): TargetScope {
],
};
}

function fitRangeToLineContent(editor: TextEditor, range: Range) {
const startLine = editor.document.lineAt(range.start);
const endLine = editor.document.lineAt(range.end);
return new Range(
startLine.rangeTrimmed?.start ?? startLine.range.start,
endLine.rangeTrimmed?.end ?? endLine.range.end,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export class ScopeHandlerFactoryImpl implements ScopeHandlerFactory {
case "identifier":
return new IdentifierScopeHandler(this, scopeType, languageId);
case "line":
return new LineScopeHandler(scopeType, languageId);
case "fullLine":
return new LineScopeHandler({ type: scopeType.type }, languageId);
case "sentence":
return new SentenceScopeHandler(this, scopeType, languageId);
case "paragraph":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TextEditor } from "@cursorless/common";
import type { TextEditor, TextLine } from "@cursorless/common";
import { Position, Range, toLineRange } from "@cursorless/common";
import type { TextualType } from "../../typings/target.types";
import { expandToFullLine } from "../../util/rangeUtils";
Expand Down Expand Up @@ -94,3 +94,19 @@ export function constructLineTarget(
): LineTarget | undefined {
return tryConstructTarget(LineTarget, editor, range, isReversed);
}

export function createLineTarget(
editor: TextEditor,
isReversed: boolean,
line: TextLine,
useFullRange = false,
) {
return new LineTarget({
editor,
isReversed,
contentRange:
useFullRange || line.rangeTrimmed == null
? line.range
: line.rangeTrimmed,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ function isLanguageSpecific(scopeType: ScopeType): boolean {
case "token":
case "identifier":
case "line":
case "fullLine":
case "sentence":
case "paragraph":
case "boundedParagraph":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = {
token: "token",
identifier: "identifier",
line: "line",
fullLine: "full line",
sentence: "sentence",
paragraph: "block",
boundedParagraph: "short block",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Scopes } from "./components/Scopes";

# Full line

<Scopes scopeTypeType="fullLine" />
Loading