Skip to content

Commit

Permalink
Changed column modified to range vertical connector (cursorless-dev#116)
Browse files Browse the repository at this point in the history
* Changed column modified to range vertical connector

* Renamed is colum to range type

* Move range type to before first target

* Don't send none for non existing range type

* Updated range type to be before connective

Co-authored-by: Andreas Arvidsson <andreas.arvidsson@redpill-linpro.com>
  • Loading branch information
AndreasArvidsson and Andreas Arvidsson authored Dec 8, 2021
1 parent 383015b commit 96aef10
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/compound_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

mod = Module()


mod.list(
"cursorless_range_connective",
desc="A range joiner that indicates whether to include or exclude anchor and active",
Expand All @@ -16,8 +15,9 @@

@mod.capture(
rule=(
"[{user.cursorless_range_connective}] <user.cursorless_primitive_target> | "
"<user.cursorless_primitive_target> {user.cursorless_range_connective} <user.cursorless_primitive_target>"
"<user.cursorless_primitive_target> | "
"[<user.cursorless_range_type>] {user.cursorless_range_connective} <user.cursorless_primitive_target> | "
" <user.cursorless_primitive_target> [<user.cursorless_range_type>] {user.cursorless_range_connective} <user.cursorless_primitive_target>"
)
)
def cursorless_range(m) -> str:
Expand All @@ -32,14 +32,21 @@ def cursorless_range(m) -> str:
else:
start = primitive_targets[0]

return {
range = {
"type": "range",
"start": start,
"end": primitive_targets[-1],
"excludeStart": not is_anchor_included(range_connective),
"excludeEnd": not is_active_included(range_connective),
}

try:
range["rangeType"] = m.cursorless_range_type
except AttributeError:
pass

return range


def is_anchor_included(range_connective: str):
return range_connective not in ["rangeExclusive", "rangeExcludingStart"]
Expand All @@ -55,4 +62,4 @@ def is_active_included(range_connective: str):
def cursorless_target(m) -> dict:
if len(m.cursorless_range_list) == 1:
return m.cursorless_range
return {"type": "list", "elements": m.cursorless_range_list}
return {"type": "list", "elements": m.cursorless_range_list}
1 change: 0 additions & 1 deletion src/modifiers/containing_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def cursorless_containing_scope(m) -> str:
"file": "document",
"line": "line",
"token": "token",
"column": "column"
}

# NOTE: Please do not change these dicts. Use the CSVs for customization.
Expand Down
3 changes: 3 additions & 0 deletions src/modifiers/modifiers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from talon import app
from ..csv_overrides import init_csv_and_watch_changes
from .range_type import range_types
from .head_tail import head_tail

# NOTE: Please do not change these dicts. Use the CSVs for customization.
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md

delimiter_inclusions = {
"inside": "interiorOnly",
"bound": "excludeInterior",
Expand All @@ -16,6 +18,7 @@ def on_ready():
"modifiers",
{
"delimiter_inclusion": delimiter_inclusions,
"range_type": range_types,
"head_tail": head_tail,
"identity": identity,
},
Expand Down
33 changes: 33 additions & 0 deletions src/modifiers/range_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from talon import Module
from dataclasses import dataclass

mod = Module()

mod.list(
"cursorless_range_type",
desc="A range modifier that indicates the specific type of the range",
)


@dataclass
class RangeType:
defaultSpokenForm: str
cursorlessIdentifier: str
type: str


# NOTE: Please do not change these dicts. Use the CSVs for customization.
# See https://github.com/pokey/cursorless-talon/blob/main/docs/customization.md

range_type_list = [
RangeType("slice", "verticalRange", "vertical"),
]

range_type_map = {t.cursorlessIdentifier: t.type for t in range_type_list}
range_types = {t.defaultSpokenForm: t.cursorlessIdentifier for t in range_type_list}


@mod.capture(rule="{user.cursorless_range_type}")
def cursorless_range_type(m) -> str:
"""Range type modifier"""
return range_type_map[m.cursorless_range_type]
2 changes: 1 addition & 1 deletion src/modifiers/surrounding_pair.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from talon import Module, app, Context
from talon import Module, Context
from ..paired_delimiter import paired_delimiters_map

mod = Module()
Expand Down

0 comments on commit 96aef10

Please sign in to comment.