Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
david-tejada committed Jun 17, 2024
2 parents c6f41be + a70a081 commit 3764676
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ def rango_command_without_target(
actionType: str,
arg: Union[str, float, None] = None,
arg2: Union[str, None] = None,
arg3: Union[bool, None] = None,
):
"""Executes a Rango command without a target"""
action = {"type": actionType}
if arg:
action["arg"] = arg
if arg2:
action["arg2"] = arg2
if arg3:
action["arg3"] = arg3
return actions.user.rango_run_command(action)
12 changes: 11 additions & 1 deletion src/rango.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def rango_hint_double(m) -> str:
return m.letter + m.letter


@mod.capture(rule="<user.letter> | <user.letter> <user.letter> | <user.rango_hint_double>")
@mod.capture(
rule="<user.letter> | <user.letter> <user.letter> | <user.rango_hint_double>"
)
def rango_hint(m) -> str:
return "".join(m)

Expand Down Expand Up @@ -63,6 +65,14 @@ def rango_run_action_on_reference(command: str, reference: str):
"runActionOnReference", command, reference
)

def rango_run_action_on_text_matched_element(
command: str, text: str, prioritize_viewport: Union[bool, None] = False
):
"""Runs a Rango command on a hintable element found using fuzzy search"""
actions.user.rango_command_without_target(
"runActionOnTextMatchedElement", command, text, prioritize_viewport
)

def rango_get_bare_title() -> str:
"""Returns the title of the currently focused tab without including the decorations"""
return actions.user.rango_command_without_target("getBareTitle")
Expand Down
15 changes: 15 additions & 0 deletions src/rango.talon
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ dismiss: user.rango_command_without_target("unhoverAll")
show <user.rango_target>:
user.rango_command_with_target("showLink", rango_target)

# Hide hint
hide <user.rango_target>:
user.rango_command_with_target("hideHint", rango_target)

# Scroll
upper: user.rango_command_without_target("scrollUpPage")
upper <number>: user.rango_command_without_target("scrollUpPage", number)
Expand Down Expand Up @@ -230,6 +234,7 @@ rango open {user.rango_page}: user.rango_command_without_target("openPageInNewTa

# Hint/element references for scripting
mark <user.rango_target> as <user.word>: user.rango_command_with_target("saveReference", rango_target, word)
mark this as <user.word>: user.rango_command_without_target("saveReferenceForActiveElement", word)
mark show: user.rango_command_without_target("showReferences")
mark clear <user.word>: user.rango_command_without_target("removeReference", word)

Expand All @@ -238,5 +243,15 @@ click mark <user.word>: user.rango_run_action_on_reference("clickElement", word)
focus mark <user.word>: user.rango_run_action_on_reference("focusElement", word)
hover mark <user.word>: user.rango_run_action_on_reference("hoverElement", word)

# Run action by matching the text of an element
follow <user.text>:
user.rango_run_action_on_text_matched_element("clickElement", text, true)
button <user.text>:
user.rango_run_action_on_text_matched_element("clickElement", text, false)
focus text <user.text>:
user.rango_run_action_on_text_matched_element("focusElement", text, true)
hover text <user.text>:
user.rango_run_action_on_text_matched_element("hoverElement", text, true)

rango explicit: user.rango_force_explicit_clicking()
rango direct: user.rango_force_direct_clicking()
9 changes: 8 additions & 1 deletion src/talon_helpers.talon
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
code.language: talon
-
# Helpers to make scripting using references easier
# Helpers to make scripting easier

# Using references
click rango mark <user.word>: "user.rango_run_action_on_reference(\"clickElement\", \"{word}\")"
focus rango mark <user.word>: "user.rango_run_action_on_reference(\"focusElement\", \"{word}\")"
hover rango mark <user.word>: "user.rango_run_action_on_reference(\"hoverElement\", \"{word}\")"

# Using fuzzy search with the text of the element
click rango text <user.text>: "user.rango_run_action_on_text_matched_element(\"clickElement\", \"{text}\")"
focus rango text <user.text>: "user.rango_run_action_on_text_matched_element(\"focusElement\", \"{text}\")"
hover rango text <user.text>: "user.rango_run_action_on_text_matched_element(\"hoverElement\", \"{text}\")"

0 comments on commit 3764676

Please sign in to comment.