-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added modifiers row up down * Renamed capture * renamed file * Added a simpler version * Treat line numbers as proper marks * Updated comment * Update src/primitive_target.py Co-authored-by: Pokey Rule <pokey.rule@gmail.com> * Added comments about simplified version * Specified exceptions * Specified exceptions Co-authored-by: Pokey Rule <pokey.rule@gmail.com>
- Loading branch information
1 parent
845be3b
commit 00deee5
Showing
4 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from talon import Context, Module | ||
|
||
mod = Module() | ||
ctx = Context() | ||
|
||
ctx.matches = r""" | ||
tag: user.cursorless | ||
""" | ||
|
||
mod.list("cursorless_line_direction", desc="Supported directions for line modifier") | ||
|
||
directions = { | ||
"row": {"isRelative": False, "transformation": lambda number: number - 1}, | ||
"up": {"isRelative": True, "transformation": lambda number: -number}, | ||
"down": {"isRelative": True, "transformation": lambda number: number}, | ||
} | ||
|
||
ctx.lists["self.cursorless_line_direction"] = directions.keys() | ||
|
||
|
||
def parse_line(line: dict): | ||
direction = directions[line["direction"]] | ||
line_number = line["lineNumber"] | ||
return { | ||
"lineNumber": direction["transformation"](line_number), | ||
"isRelative": direction["isRelative"], | ||
} | ||
|
||
|
||
@mod.capture(rule="{user.cursorless_line_direction} <number>") | ||
def cursorless_line_number_anchor(m) -> str: | ||
return {"direction": m.cursorless_line_direction, "lineNumber": m.number} | ||
|
||
|
||
@mod.capture(rule="past [{user.cursorless_line_direction}] <number>") | ||
def cursorless_line_number_active(m) -> str: | ||
try: | ||
direction = m.cursorless_line_direction | ||
except AttributeError: | ||
direction = None | ||
return {"direction": direction, "lineNumber": m.number} | ||
|
||
|
||
# For now this capture is not used because it's too complex and increase compilation time too much | ||
@mod.capture( | ||
rule="<user.cursorless_line_number_anchor> [<user.cursorless_line_number_active>]" | ||
) | ||
def cursorless_line_number(m) -> str: | ||
anchor = m.cursorless_line_number_anchor | ||
try: | ||
active = m.cursorless_line_number_active | ||
# Infer missing direction from anchor | ||
if active["direction"] == None: | ||
active["direction"] = anchor["direction"] | ||
except AttributeError: | ||
active = anchor | ||
return { | ||
"selectionType": "line", | ||
"mark": { | ||
"type": "lineNumber", | ||
"anchor": parse_line(anchor), | ||
"active": parse_line(active), | ||
}, | ||
} | ||
|
||
# This is the simplified version that we are using for now that only implements a subset of the features | ||
@mod.capture( | ||
rule="(up | down) <number_small>" | ||
) | ||
def cursorless_line_number_simple(m) -> str: | ||
position = {"direction": m[0], "lineNumber": m.number_small} | ||
return { | ||
"selectionType": "line", | ||
"mark": { | ||
"type": "lineNumber", | ||
"anchor": parse_line(position), | ||
"active": parse_line(position), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters