Skip to content

Commit 7af2a73

Browse files
AndreasArvidssonpokeypre-commit-ci[bot]
authored
Implemented head tail modifier that works on multiple scope types (#708)
* Implemented head tail modifier that works on multiple scope types * Fixed test that broke in merge * Cleanup * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * More cleanup * More cleanup * More cleanup * Fixed line endings * Updated tests * Updated tests * Head and tail modifiers swallow all following modifiers * Updated tests * Cleanup * Cleanup * Switch head tail stage to use token target instead of plane target * Cleanup head tail stage * Reinstate doc string Co-authored-by: Pokey Rule <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent dbd1626 commit 7af2a73

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

src/modifiers/head_tail.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from talon import Module
2+
3+
head_tail_modifiers = {
4+
"head": "extendThroughStartOf",
5+
"tail": "extendThroughEndOf",
6+
}
7+
8+
mod = Module()
9+
10+
mod.list(
11+
"cursorless_head_tail_modifier",
12+
desc="Cursorless head and tail modifiers",
13+
)
14+
15+
16+
@mod.capture(rule="{user.cursorless_head_tail_modifier} <user.cursorless_modifier>*")
17+
def cursorless_head_tail_modifier(m) -> dict[str, str]:
18+
"""Cursorless head and tail modifier"""
19+
result = {
20+
"type": m.cursorless_head_tail_modifier,
21+
}
22+
try:
23+
result["modifiers"] = m.cursorless_modifier_list
24+
except AttributeError:
25+
pass
26+
return result

src/modifiers/modifiers.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from talon import Module, app
22

33
from ..csv_overrides import init_csv_and_watch_changes
4+
from .head_tail import head_tail_modifiers
45
from .range_type import range_types
56

67
mod = Module()
@@ -11,8 +12,6 @@
1112
"inside": "interiorOnly",
1213
"bounds": "excludeInterior",
1314
"just": "toRawSelection",
14-
"head": "extendThroughStartOf",
15-
"tail": "extendThroughEndOf",
1615
"leading": "leading",
1716
"trailing": "trailing",
1817
}
@@ -31,11 +30,28 @@ def cursorless_simple_modifier(m) -> dict[str, str]:
3130
}
3231

3332

33+
modifiers = [
34+
"<user.cursorless_position>", # before, end of
35+
"<user.cursorless_simple_modifier>", # inside, bounds, just, leading, trailing
36+
"<user.cursorless_head_tail_modifier>", # head, tail
37+
"<user.cursorless_containing_scope>", # funk, state, class
38+
"<user.cursorless_subtoken_scope>", # first past second word
39+
"<user.cursorless_surrounding_pair>", # matching/pair [curly, round]
40+
]
41+
42+
43+
@mod.capture(rule="|".join(modifiers))
44+
def cursorless_modifier(m) -> str:
45+
"""Cursorless modifier"""
46+
return m[0]
47+
48+
3449
def on_ready():
3550
init_csv_and_watch_changes(
3651
"modifiers",
3752
{
3853
"simple_modifier": simple_modifiers,
54+
"head_tail_modifier": head_tail_modifiers,
3955
"range_type": range_types,
4056
},
4157
)

src/primitive_target.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@
88
IMPLICIT_TARGET = {"type": "primitive", "isImplicit": True}
99

1010

11-
modifiers = [
12-
"<user.cursorless_position>", # before, end of
13-
"<user.cursorless_simple_modifier>", # eg inside, bounds, just, head, tail, leading, trailing
14-
"<user.cursorless_containing_scope>", # funk, state, class
15-
"<user.cursorless_subtoken_scope>", # first past second word
16-
"<user.cursorless_surrounding_pair>", # matching/pair [curly, round]
17-
]
18-
19-
20-
@mod.capture(rule="|".join(modifiers))
21-
def cursorless_modifier(m) -> str:
22-
"""Cursorless modifier"""
23-
return m[0]
24-
25-
2611
@mod.capture(
2712
rule="<user.cursorless_modifier>+ [<user.cursorless_mark>] | <user.cursorless_mark>"
2813
)

0 commit comments

Comments
 (0)