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 glyph scope #2050

Merged
merged 22 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cursorless-talon/src/cheatsheet/sections/modifiers.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheatsheet seems to still have it as a modifier

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"previous_next_modifier",
"forward_backward_modifier",
"position",
"glyph_modifier",
]


Expand All @@ -28,6 +29,7 @@ def get_modifiers():
"next",
"backward",
"forward",
"glyph",
]
simple_modifiers = {
key: value
Expand Down Expand Up @@ -101,6 +103,16 @@ def get_modifiers():
},
],
},
{
"id": "glyph",
"type": "modifier",
"variations": [
{
"spokenForm": f"{complex_modifiers['glyph']} <glyph>",
"description": "First instance of <glyph>",
},
],
},
{
"id": "relativeScope",
"type": "modifier",
Expand Down
30 changes: 30 additions & 0 deletions cursorless-talon/src/modifiers/glyph_scope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from talon import Module

mod = Module()

mod.list(
"cursorless_glyph_scope_type",
desc="Cursorless glyph scope type",
)
mod.list(
"cursorless_glyph_scope_type_plural",
desc="Plural version of Cursorless glyph scope type",
)


@mod.capture(rule="{user.cursorless_glyph_scope_type} <user.any_alphanumeric_key>")
def cursorless_glyph_scope_type(m) -> dict[str, str]:
return {
"type": "glyph",
"character": m.any_alphanumeric_key,
}


@mod.capture(
rule="{user.cursorless_glyph_scope_type_plural} <user.any_alphanumeric_key>"
)
def cursorless_glyph_scope_type_plural(m) -> dict[str, str]:
return {
"type": "glyph",
"character": m.any_alphanumeric_key,
}
28 changes: 21 additions & 7 deletions cursorless-talon/src/modifiers/scopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,39 @@


@mod.capture(
rule="{user.cursorless_scope_type} | {user.cursorless_custom_regex_scope_type}"
rule="{user.cursorless_scope_type} | <user.cursorless_glyph_scope_type> | {user.cursorless_custom_regex_scope_type}"
)
def cursorless_scope_type(m) -> dict[str, str]:
"""Cursorless scope type singular"""
try:
return {"type": m.cursorless_scope_type}
except AttributeError:
return {"type": "customRegex", "regex": m.cursorless_custom_regex_scope_type}
pass

try:
return m.cursorless_glyph_scope_type
except AttributeError:
pass

return {"type": "customRegex", "regex": m.cursorless_custom_regex_scope_type}


@mod.capture(
rule="{user.cursorless_scope_type_plural} | {user.cursorless_custom_regex_scope_type_plural}"
rule="{user.cursorless_scope_type_plural} | <user.cursorless_glyph_scope_type_plural> | {user.cursorless_custom_regex_scope_type_plural}"
)
def cursorless_scope_type_plural(m) -> dict[str, str]:
"""Cursorless scope type plural"""
try:
return {"type": m.cursorless_scope_type_plural}
except AttributeError:
return {
"type": "customRegex",
"regex": m.cursorless_custom_regex_scope_type_plural,
}
pass

try:
return m.cursorless_glyph_scope_type_plural
except AttributeError:
pass

return {
"type": "customRegex",
"regex": m.cursorless_custom_regex_scope_type_plural,
}
3 changes: 3 additions & 0 deletions cursorless-talon/src/spoken_forms.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
},
"surrounding_pair_scope_type": {
"string": "string"
},
"glyph_scope_type": {
"glyph": "glyph"
}
},
"paired_delimiters.csv": {
Expand Down
2 changes: 1 addition & 1 deletion cursorless-talon/src/spoken_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def handle_new_values(csv_name: str, values: list[SpokenFormEntry]):
handle_csv("experimental/miscellaneous.csv"),
handle_csv(
"modifier_scope_types.csv",
pluralize_lists=["scope_type"],
pluralize_lists=["scope_type", "glyph_scope_type"],
extra_allowed_values=["private.fieldAccess"],
default_list_name="scope_type",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,17 @@ export interface OneOfScopeType {
scopeTypes: ScopeType[];
}

export interface GlyphScopeType {
type: "glyph";
character: string;
}

export type ScopeType =
| SimpleScopeType
| SurroundingPairScopeType
| CustomRegexScopeType
| OneOfScopeType;
| OneOfScopeType
| GlyphScopeType;

export interface ContainingSurroundingPairModifier
extends ContainingScopeModifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export class PrimitiveTargetSpokenFormGenerator {
handleScopeType(scopeType: ScopeType): SpokenFormComponent {
switch (scopeType.type) {
case "oneOf":
case "glyph":
throw new NoSpokenFormError(`Scope type '${scopeType.type}'`);
case "surroundingPair": {
const pair = this.spokenFormMap.pairedDelimiter[scopeType.delimiter];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { CustomRegexScopeType, Direction, ScopeType } from "@cursorless/common";
import {
CustomRegexScopeType,
Direction,
GlyphScopeType,
ScopeType,
} from "@cursorless/common";
import { imap } from "itertools";
import { escapeRegExp } from "lodash";
import { NestedScopeHandler, ScopeHandlerFactory } from ".";
import { generateMatchesInRange } from "../../../util/getMatchesInRange";
import { TokenTarget } from "../../targets";
Expand Down Expand Up @@ -61,3 +67,17 @@ export class CustomRegexScopeHandler extends RegexStageBase {
super(scopeHandlerFactory, scopeType, languageId);
}
}

export class GlyphScopeHandler extends RegexStageBase {
get regex() {
return new RegExp(escapeRegExp(this.scopeType.character), "gu");
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
}

constructor(
scopeHandlerFactory: ScopeHandlerFactory,
readonly scopeType: GlyphScopeType,
languageId: string,
) {
super(scopeHandlerFactory, scopeType, languageId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CharacterScopeHandler,
CustomRegexScopeHandler,
DocumentScopeHandler,
GlyphScopeHandler,
IdentifierScopeHandler,
LineScopeHandler,
NonWhitespaceSequenceScopeHandler,
Expand Down Expand Up @@ -72,6 +73,8 @@ export class ScopeHandlerFactoryImpl implements ScopeHandlerFactory {
return new UrlScopeHandler(this, scopeType, languageId);
case "customRegex":
return new CustomRegexScopeHandler(this, scopeType, languageId);
case "glyph":
return new GlyphScopeHandler(this, scopeType, languageId);
case "custom":
return scopeType.scopeHandler;
case "instance":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function isLanguageSpecific(scopeType: ScopeType): boolean {
case "notebookCell":
case "surroundingPair":
case "customRegex":
case "glyph":
return false;

case "oneOf":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
languageId: plaintext
command:
version: 6
spokenForm: clear every glyph air
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: everyScope
scopeType: {type: glyph, character: a}
usePrePhraseSnapshot: true
spokenFormError: Scope type 'glyph'
initialState:
documentContents: abc$!4123a
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: bc$!4123
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
- anchor: {line: 0, character: 8}
active: {line: 0, character: 8}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
languageId: plaintext
command:
version: 6
spokenForm: clear final glyph air
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: ordinalScope
scopeType: {type: glyph, character: a}
start: -1
length: 1
usePrePhraseSnapshot: true
spokenFormError: Scope type 'glyph'
initialState:
documentContents: abc$!4123a
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: abc$!4123
selections:
- anchor: {line: 0, character: 9}
active: {line: 0, character: 9}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
languageId: plaintext
command:
version: 6
spokenForm: clear glyph air
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: glyph, character: a}
usePrePhraseSnapshot: true
spokenFormError: Scope type 'glyph'
initialState:
documentContents: abc$!4123a
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: bc$!4123a
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: plaintext
command:
version: 6
spokenForm: clear next glyph dollar
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: relativeScope
scopeType: {type: glyph, character: $}
offset: 1
length: 1
direction: forward
usePrePhraseSnapshot: true
spokenFormError: Scope type 'glyph'
initialState:
documentContents: abc$!4123a
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: abc!4123a
selections:
- anchor: {line: 0, character: 3}
active: {line: 0, character: 3}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: plaintext
command:
version: 6
spokenForm: clear next glyph onyx
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: relativeScope
scopeType: {type: glyph, character: å}
offset: 1
length: 1
direction: forward
usePrePhraseSnapshot: true
spokenFormError: Scope type 'glyph'
initialState:
documentContents: abå
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
marks: {}
finalState:
documentContents: ab
selections:
- anchor: {line: 0, character: 2}
active: {line: 0, character: 2}