-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Token scope prefers $ over other symbols (#2048)
Fixes #1321 ## 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
- Loading branch information
1 parent
41cf78d
commit 3fe5d81
Showing
5 changed files
with
149 additions
and
45 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
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
28 changes: 28 additions & 0 deletions
28
...ges/cursorless-engine/src/processTargets/modifiers/scopeHandlers/isPreferredOverHelper.ts
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 @@ | ||
import { testRegex } from "../../../util/regex"; | ||
import type { TargetScope } from "./scope.types"; | ||
|
||
export function isPreferredOverHelper( | ||
scopeA: TargetScope, | ||
scopeB: TargetScope, | ||
matchers: RegExp[], | ||
): boolean | undefined { | ||
const textA = scopeA.editor.document.getText(scopeA.domain); | ||
const textB = scopeB.editor.document.getText(scopeB.domain); | ||
|
||
for (const matcher of matchers) { | ||
// NB: Don't directly use `test` here because global regexes are stateful | ||
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#finding_successive_matches | ||
const aMatchesRegex = testRegex(matcher, textA); | ||
const bMatchesRegex = testRegex(matcher, textB); | ||
|
||
if (aMatchesRegex && !bMatchesRegex) { | ||
return true; | ||
} | ||
|
||
if (bMatchesRegex && !aMatchesRegex) { | ||
return false; | ||
} | ||
} | ||
|
||
return undefined; | ||
} |
49 changes: 49 additions & 0 deletions
49
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/scopes/character/changeChar.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,49 @@ | ||
languageId: plaintext | ||
command: | ||
version: 6 | ||
spokenForm: change char | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: character} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
$. | ||
.$ | ||
$a | ||
a$ | ||
$$ | ||
selections: | ||
- anchor: {line: 4, character: 1} | ||
active: {line: 4, character: 1} | ||
- anchor: {line: 3, character: 1} | ||
active: {line: 3, character: 1} | ||
- anchor: {line: 2, character: 1} | ||
active: {line: 2, character: 1} | ||
- anchor: {line: 1, character: 1} | ||
active: {line: 1, character: 1} | ||
- anchor: {line: 0, character: 1} | ||
active: {line: 0, character: 1} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
. | ||
. | ||
$ | ||
$ | ||
$ | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
- anchor: {line: 1, character: 1} | ||
active: {line: 1, character: 1} | ||
- anchor: {line: 2, character: 1} | ||
active: {line: 2, character: 1} | ||
- anchor: {line: 3, character: 0} | ||
active: {line: 3, character: 0} | ||
- anchor: {line: 4, character: 1} | ||
active: {line: 4, character: 1} |
49 changes: 49 additions & 0 deletions
49
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/scopes/token/changeToken.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,49 @@ | ||
languageId: plaintext | ||
command: | ||
version: 6 | ||
spokenForm: change token | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: token} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
$. | ||
.$ | ||
$a | ||
a$ | ||
$$ | ||
selections: | ||
- anchor: {line: 4, character: 1} | ||
active: {line: 4, character: 1} | ||
- anchor: {line: 3, character: 1} | ||
active: {line: 3, character: 1} | ||
- anchor: {line: 2, character: 1} | ||
active: {line: 2, character: 1} | ||
- anchor: {line: 1, character: 1} | ||
active: {line: 1, character: 1} | ||
- anchor: {line: 0, character: 1} | ||
active: {line: 0, character: 1} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
. | ||
. | ||
$ | ||
$ | ||
$ | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
- anchor: {line: 1, character: 1} | ||
active: {line: 1, character: 1} | ||
- anchor: {line: 2, character: 1} | ||
active: {line: 2, character: 1} | ||
- anchor: {line: 3, character: 0} | ||
active: {line: 3, character: 0} | ||
- anchor: {line: 4, character: 1} | ||
active: {line: 4, character: 1} |