Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added modifiers row up down #44

Merged
merged 11 commits into from
Aug 5, 2021
4 changes: 2 additions & 2 deletions src/actions/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def cursorless_count(m) -> str:
try:
start = m.number_small
except:
except AttributeError:
start = 0
return {"start": start}

Expand All @@ -20,7 +20,7 @@ def cursorless_texts(m) -> str:
texts = list(
map(lambda text: actions.user.formatted_text(text, formatters), texts)
)
except:
except AttributeError:
pass
return texts

Expand Down
79 changes: 79 additions & 0 deletions src/marks/lines_number.py
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"]
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
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>"
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
)
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),
},
}
27 changes: 18 additions & 9 deletions src/mark.py → src/marks/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,22 @@ def cursorless_decorated_symbol(m) -> str:
# "last cursor": {"mark": {"type": "lastCursorPosition"}} # Not implemented
}

mod.list("cursorless_mark", desc="Cursorless marks")
ctx.lists["self.cursorless_mark"] = special_marks.keys()


@mod.capture(rule=("<user.cursorless_decorated_symbol> | " "{user.cursorless_mark}"))
mod.list("cursorless_special_mark", desc="Cursorless special marks")
ctx.lists["self.cursorless_special_mark"] = special_marks.keys()


@mod.capture(
rule=(
"<user.cursorless_decorated_symbol> | "
"{user.cursorless_special_mark} |"
# Because of problems with performance we have to have a simple version for now
# "<user.cursorless_line_number>" # row, up, down
"<user.cursorless_line_number_simple>" # up, down
)
)
def cursorless_mark(m) -> str:
try:
return m.cursorless_decorated_symbol
except AttributeError:
return special_marks[m.cursorless_mark]
try: return m.cursorless_decorated_symbol
except AttributeError: pass
try: return special_marks[m.cursorless_special_mark]
except AttributeError: pass
return m.cursorless_line_number_simple
4 changes: 2 additions & 2 deletions src/primitive_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
}

modifiers = [
"<user.cursorless_position>", # before, above, end of
"<user.cursorless_position>", # before, end of
"<user.cursorless_selection_type>", # token, line, file
"<user.cursorless_containing_scope>", # funk, state, class
"<user.cursorless_subtoken>", # first past second word
"<user.cursorless_head_tail>" # head, tail
"<user.cursorless_head_tail>", # head, tail
# "<user.cursorless_inside_outside>", # inner, outer
# "<user.cursorless_surrounding_pair>", # curly, round
# "<user.cursorless_matching_pair_symbol>", # matching
Expand Down