-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I'm not sure this is a direction we want to go or if this is a good implementation, but for editors where we don't have hats it would be nice if you could just speak the literal text instead. `"take hello world"` `"chuck state get value"` In this implementation I'm only looking in the viewport and I'm solving ambiguity by selecting the match closest to a cursor selection. ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet - [x] Add list for literal prefix/keyword. Empty by default. test that this behaves properly - [x] Tag to remove prefix and have literal as a replacement for hats. Check dfa compilation - [x] Tag to default to preferred scope instead of containing scope --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Phil Cohen <[email protected]>
- Loading branch information
1 parent
0e01381
commit 21715e4
Showing
24 changed files
with
516 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from talon import Context, Module | ||
|
||
from .mark_types import LiteralMark | ||
|
||
mod = Module() | ||
|
||
mod.list("private_cursorless_literal_mark", desc="Cursorless literal mark") | ||
|
||
# This is a private tag and should not be used by non Cursorless developers | ||
mod.tag( | ||
"private_cursorless_literal_mark_no_prefix", | ||
desc="Tag for enabling literal mark without prefix", | ||
) | ||
|
||
ctx_no_prefix = Context() | ||
ctx_no_prefix.matches = r""" | ||
tag: user.private_cursorless_literal_mark_no_prefix | ||
""" | ||
|
||
|
||
# NB: <phrase> is used over <user.text> for DFA performance reasons | ||
# (we intend to replace this with a dynamic list of document contents eventually) | ||
@mod.capture(rule="{user.private_cursorless_literal_mark} <phrase>") | ||
def cursorless_literal_mark(m) -> LiteralMark: | ||
return construct_mark(str(m.phrase)) | ||
|
||
|
||
@ctx_no_prefix.capture("user.cursorless_literal_mark", rule="<phrase>") | ||
def cursorless_literal_mark_no_prefix(m) -> LiteralMark: | ||
return construct_mark(str(m.phrase)) | ||
|
||
|
||
def construct_mark(text: str) -> LiteralMark: | ||
return { | ||
"type": "literal", | ||
"modifier": { | ||
"type": "preferredScope", | ||
"scopeType": { | ||
"type": "customRegex", | ||
"regex": construct_fuzzy_regex(text), | ||
"flags": "gui", | ||
}, | ||
}, | ||
} | ||
|
||
|
||
def construct_fuzzy_regex(text: str) -> str: | ||
parts = text.split(" ") | ||
# Between each word there can be any number of non-alpha symbols (including escape characters: \t\r\n). No separator at all is also valid -- for example, when searching for a camelCase identifier. | ||
return r"([^a-zA-Z]|\\[trn])*".join(parts) |
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
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
26 changes: 26 additions & 0 deletions
26
data/fixtures/recorded/modifiers/preferredScope/changeGoodPair.yml
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,26 @@ | ||
languageId: plaintext | ||
command: | ||
version: 7 | ||
spokenForm: change good pair | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: preferredScope | ||
scopeType: {type: surroundingPair, delimiter: any} | ||
usePrePhraseSnapshot: true | ||
spokenFormError: Modifier 'preferredScope' | ||
initialState: | ||
documentContents: | | ||
() | ||
selections: | ||
- anchor: {line: 1, character: 0} | ||
active: {line: 1, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: |+ | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
28 changes: 28 additions & 0 deletions
28
data/fixtures/recorded/modifiers/preferredScope/changeGoodPair2.yml
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,28 @@ | ||
languageId: plaintext | ||
command: | ||
version: 7 | ||
spokenForm: change good pair | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: preferredScope | ||
scopeType: {type: surroundingPair, delimiter: any} | ||
usePrePhraseSnapshot: true | ||
spokenFormError: Modifier 'preferredScope' | ||
initialState: | ||
documentContents: |- | ||
() () | ||
selections: | ||
- anchor: {line: 1, character: 9} | ||
active: {line: 1, character: 9} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
() | ||
selections: | ||
- anchor: {line: 0, character: 8} | ||
active: {line: 0, character: 8} |
26 changes: 26 additions & 0 deletions
26
data/fixtures/recorded/modifiers/preferredScope/changeGoodPair3.yml
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,26 @@ | ||
languageId: plaintext | ||
command: | ||
version: 7 | ||
spokenForm: change good pair | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: preferredScope | ||
scopeType: {type: surroundingPair, delimiter: any} | ||
usePrePhraseSnapshot: true | ||
spokenFormError: Modifier 'preferredScope' | ||
initialState: | ||
documentContents: | | ||
() () | ||
selections: | ||
- anchor: {line: 1, character: 0} | ||
active: {line: 1, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: |2 | ||
() | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
24 changes: 24 additions & 0 deletions
24
data/fixtures/recorded/modifiers/preferredScope/changeGoodPair4.yml
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,24 @@ | ||
languageId: plaintext | ||
command: | ||
version: 7 | ||
spokenForm: change good pair | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: preferredScope | ||
scopeType: {type: surroundingPair, delimiter: any} | ||
usePrePhraseSnapshot: true | ||
spokenFormError: Modifier 'preferredScope' | ||
initialState: | ||
documentContents: () () | ||
selections: | ||
- anchor: {line: 0, character: 3} | ||
active: {line: 0, character: 3} | ||
marks: {} | ||
finalState: | ||
documentContents: "() " | ||
selections: | ||
- anchor: {line: 0, character: 4} | ||
active: {line: 0, character: 4} |
26 changes: 26 additions & 0 deletions
26
data/fixtures/recorded/modifiers/preferredScope/clearLiteralHello.yml
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,26 @@ | ||
languageId: plaintext | ||
command: | ||
version: 7 | ||
spokenForm: clear literal hello | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: preferredScope | ||
scopeType: {type: customRegex, regex: hello, flags: gui} | ||
usePrePhraseSnapshot: true | ||
spokenFormError: Modifier 'preferredScope' | ||
initialState: | ||
documentContents: | | ||
hello | ||
selections: | ||
- anchor: {line: 1, character: 0} | ||
active: {line: 1, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: |+ | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
27 changes: 27 additions & 0 deletions
27
data/fixtures/recorded/modifiers/preferredScope/clearLiteralHello2.yml
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,27 @@ | ||
languageId: plaintext | ||
command: | ||
version: 7 | ||
spokenForm: clear literal hello | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: preferredScope | ||
scopeType: {type: customRegex, regex: hello, flags: gui} | ||
usePrePhraseSnapshot: true | ||
spokenFormError: Modifier 'preferredScope' | ||
initialState: | ||
documentContents: |- | ||
hello | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: |+ | ||
selections: | ||
- anchor: {line: 1, character: 0} | ||
active: {line: 1, character: 0} |
26 changes: 26 additions & 0 deletions
26
data/fixtures/recorded/modifiers/preferredScope/clearLiteralHelloThere.yml
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,26 @@ | ||
languageId: plaintext | ||
command: | ||
version: 7 | ||
spokenForm: clear literal hello there | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: preferredScope | ||
scopeType: {type: customRegex, regex: 'hello([^a-zA-Z]|\\[trn])*there', flags: gui} | ||
usePrePhraseSnapshot: true | ||
spokenFormError: Modifier 'preferredScope' | ||
initialState: | ||
documentContents: | | ||
hello there | ||
selections: | ||
- anchor: {line: 1, character: 0} | ||
active: {line: 1, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: |+ | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
26 changes: 26 additions & 0 deletions
26
data/fixtures/recorded/modifiers/preferredScope/clearLiteralHelloThere2.yml
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,26 @@ | ||
languageId: plaintext | ||
command: | ||
version: 7 | ||
spokenForm: clear literal hello there | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: preferredScope | ||
scopeType: {type: customRegex, regex: 'hello([^a-zA-Z]|\\[trn])*there', flags: gui} | ||
usePrePhraseSnapshot: true | ||
spokenFormError: Modifier 'preferredScope' | ||
initialState: | ||
documentContents: | | ||
hello.there | ||
selections: | ||
- anchor: {line: 1, character: 0} | ||
active: {line: 1, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: |+ | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
26 changes: 26 additions & 0 deletions
26
data/fixtures/recorded/modifiers/preferredScope/clearLiteralHelloThere3.yml
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,26 @@ | ||
languageId: plaintext | ||
command: | ||
version: 7 | ||
spokenForm: clear literal hello there | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: preferredScope | ||
scopeType: {type: customRegex, regex: 'hello([^a-zA-Z]|\\[trn])*there', flags: gui} | ||
usePrePhraseSnapshot: true | ||
spokenFormError: Modifier 'preferredScope' | ||
initialState: | ||
documentContents: | | ||
hello\nthere | ||
selections: | ||
- anchor: {line: 1, character: 0} | ||
active: {line: 1, character: 0} | ||
marks: {} | ||
finalState: | ||
documentContents: |+ | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} |
Oops, something went wrong.