Skip to content

Commit 492a74b

Browse files
Clean up
1 parent 606213c commit 492a74b

File tree

9 files changed

+39
-75
lines changed

9 files changed

+39
-75
lines changed

cursorless-everywhere-talon/cursorless_everywhere_talon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .cursorless_everywhere_types import (
77
EditorEdit,
88
EditorState,
9-
FlashDescriptorOffsets,
9+
RangeOffsets,
1010
SelectionOffsets,
1111
)
1212

@@ -63,7 +63,7 @@ def cursorless_everywhere_edit_text(
6363
"""Edit focused element text"""
6464

6565
def cursorless_everywhere_flash_ranges(
66-
ranges: list[FlashDescriptorOffsets], # pyright: ignore [reportGeneralTypeIssues]
66+
ranges: list[RangeOffsets], # pyright: ignore [reportGeneralTypeIssues]
6767
):
6868
"""Flash ranges in focused element"""
6969
actions.skip()

cursorless-everywhere-talon/cursorless_everywhere_talon_browser.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .cursorless_everywhere_types import (
44
EditorEdit,
55
EditorState,
6-
FlashDescriptorOffsets,
6+
RangeOffsets,
77
SelectionOffsets,
88
)
99

@@ -63,18 +63,11 @@ def cursorless_everywhere_edit_text(
6363
actions.next(edit)
6464

6565
def cursorless_everywhere_flash_ranges(
66-
ranges: list[FlashDescriptorOffsets], # pyright: ignore [reportGeneralTypeIssues]
66+
ranges: list[RangeOffsets], # pyright: ignore [reportGeneralTypeIssues]
6767
):
6868
updated = [
69-
js_object_to_python_dict(d, ["style", "range"])
70-
for d in js_array_to_python_list(ranges)
71-
]
72-
updated = [
73-
{
74-
"style": d["style"],
75-
"range": js_object_to_python_dict(d["range"], ["type", "start", "end"]),
76-
}
77-
for d in updated
69+
js_object_to_python_dict(r, ["start", "end"])
70+
for r in js_array_to_python_list(ranges)
7871
]
7972
command = {
8073
"id": "flashRanges",

cursorless-everywhere-talon/cursorless_everywhere_types.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
1-
from typing import Literal, TypedDict
1+
from typing import TypedDict
22

33

44
class SelectionOffsets(TypedDict):
55
anchor: int
66
active: int
77

88

9-
class CharacterRangeOffsets(TypedDict):
10-
type: Literal["character"]
9+
class RangeOffsets(TypedDict):
1110
start: int
1211
end: int
1312

1413

15-
class LineRange(TypedDict):
16-
type: Literal["line"]
17-
start: int
18-
end: int
19-
20-
21-
GeneralizedRangeOffsets = CharacterRangeOffsets | LineRange
22-
23-
24-
class FlashDescriptorOffsets(TypedDict):
25-
style: str
26-
range: GeneralizedRangeOffsets
27-
28-
2914
class EditorState(TypedDict):
3015
text: str
3116
selections: list[SelectionOffsets]
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
import type { FlashDescriptor } from "@cursorless/common";
22
import type { Talon } from "../types/talon.types";
3-
import type { FlashDescriptorOffsets } from "../types/types";
4-
import { toGeneralizedRangeOffsets } from "./toGeneralizedRangeOffsets";
3+
import type { RangeOffsets } from "../types/types";
4+
import { toCharacterRangeOffsets } from "./toCharacterRangeOffsets";
55

66
export function flashRanges(
77
talon: Talon,
88
flashDescriptors: FlashDescriptor[],
99
): Promise<void> {
10-
const offsetDescriptors = flashDescriptors.map(
11-
(descriptor): FlashDescriptorOffsets => {
12-
return {
13-
style: descriptor.style,
14-
range: toGeneralizedRangeOffsets(descriptor.editor, descriptor.range),
15-
};
16-
},
10+
const ranges = flashDescriptors.map(
11+
(descriptor): RangeOffsets =>
12+
toCharacterRangeOffsets(descriptor.editor, descriptor.range),
1713
);
1814

19-
talon.actions.user.cursorless_everywhere_flash_ranges(offsetDescriptors);
15+
talon.actions.user.cursorless_everywhere_flash_ranges(ranges);
2016

2117
return Promise.resolve();
2218
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { GeneralizedRange, TextEditor } from "@cursorless/common";
2+
import type { RangeOffsets } from "../types/types";
3+
4+
export function toCharacterRangeOffsets(
5+
editor: TextEditor,
6+
range: GeneralizedRange,
7+
): RangeOffsets {
8+
if (range.type === "line") {
9+
const startLine = editor.document.lineAt(range.start).range;
10+
const endLine = editor.document.lineAt(range.end).range;
11+
return {
12+
start: editor.document.offsetAt(startLine.start),
13+
end: editor.document.offsetAt(endLine.end),
14+
};
15+
}
16+
return {
17+
start: editor.document.offsetAt(range.start),
18+
end: editor.document.offsetAt(range.end),
19+
};
20+
}

packages/cursorless-everywhere-talon-core/src/ide/toGeneralizedRangeOffsets.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/cursorless-everywhere-talon-core/src/types/talon.types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {
2+
RangeOffsets,
23
EditorEdit,
34
EditorState,
4-
FlashDescriptorOffsets,
55
SelectionOffsets,
66
} from "./types";
77

@@ -22,9 +22,7 @@ export interface TalonActions {
2222
cursorless_everywhere_get_editor_state(): EditorState;
2323
cursorless_everywhere_set_selections(selections: SelectionOffsets[]): void;
2424
cursorless_everywhere_edit_text(edit: EditorEdit): void;
25-
cursorless_everywhere_flash_ranges(
26-
flashDescriptors: FlashDescriptorOffsets[],
27-
): void;
25+
cursorless_everywhere_flash_ranges(ranges: RangeOffsets[]): void;
2826
};
2927
}
3028

packages/cursorless-everywhere-talon-core/src/types/types.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import type {
22
Command,
33
CommandResponse,
4-
FlashStyle,
54
IDE,
6-
LineRange,
75
NormalizedIDE,
86
TestHelpers,
97
} from "@cursorless/common";
@@ -16,19 +14,11 @@ export interface SelectionOffsets {
1614
active: number;
1715
}
1816

19-
export interface CharacterRangeOffsets {
20-
type: "character";
17+
export interface RangeOffsets {
2118
start: number;
2219
end: number;
2320
}
2421

25-
export type GeneralizedRangeOffsets = CharacterRangeOffsets | LineRange;
26-
27-
export interface FlashDescriptorOffsets {
28-
style: FlashStyle;
29-
range: GeneralizedRangeOffsets;
30-
}
31-
3222
export interface EditorState {
3323
text: string;
3424
languageId?: string;

packages/cursorless-everywhere-talon-e2e/src/talonMock.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type {
2+
RangeOffsets,
23
EditorEdit,
34
EditorState,
4-
FlashDescriptorOffsets,
55
SelectionOffsets,
66
Talon,
77
TalonActions,
@@ -54,9 +54,7 @@ const actions: TalonActions = {
5454
}
5555
_finalEditorState.text = edit.text;
5656
},
57-
cursorless_everywhere_flash_ranges(
58-
_flashDescriptors: FlashDescriptorOffsets[],
59-
): void {
57+
cursorless_everywhere_flash_ranges(_ranges: RangeOffsets[]): void {
6058
// Do nothing
6159
},
6260
},

0 commit comments

Comments
 (0)