Skip to content

Improve handling of extra characters on paired delimiters #552

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

Open
1 task
pokey opened this issue Feb 10, 2022 · 0 comments
Open
1 task

Improve handling of extra characters on paired delimiters #552

pokey opened this issue Feb 10, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@pokey
Copy link
Member

pokey commented Feb 10, 2022

The problem

Cursorless sometimes exhibits unexpected behaviour when handling paired delimiters. For example, in the following python code:

f"hello"

If the user says "twin repack harp", they are left with 'hello', rather than the expected f'hello'.

The solution

The primary problem here has to do with delimiters that can have optional leading or trailing characters. First, let's enumerate all known examples:

  • $( in bash
  • ${ in bash
  • ${ in typescript
  • f" in Python
  • </ in HTML and jsx
  • /> in HTML and jsx

To handle this case we'll make our delimiter representation a bit more structured. For both opening and closing delimiter, we'll support an object that has field for primaryCharacter, eg (, [ or ) and also fields for lists of optional leading / trailing characters, such as f, $, etc.

When searching for surrounding pairs, we'll include all forms of leading and closing, with or without trailing chars, in the regex / type matcher.

For all situations other than "repack", we'll just use the entire delimiter including any optional leading / trailing chars as the delimiter.

For "repack", the action itself (or potentially the target, if implemented on top of #210), will look at the text of the delimiter in the file, and check whether it includes optional leaders / trailers, and if so, see whether the new delimiter supports the same optional leading / trailing chars. If it does, it leaves the optional leader, otherwise removes. For example, saying "twin repack fine" for f"hello" will leave the f, but "square repack fine" would remove it

  • Check that this work fixes /> for self-closing tags in JSX, where / and > are parsed as two separate tokens. In particular, / needs to be part of closing delimiter
@pokey pokey added the bug Something isn't working label Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant