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

Is there a way to specify \n as a boundary? #16

Open
JosephTLyons opened this issue Aug 7, 2023 · 2 comments
Open

Is there a way to specify \n as a boundary? #16

JosephTLyons opened this issue Aug 7, 2023 · 2 comments

Comments

@JosephTLyons
Copy link

JosephTLyons commented Aug 7, 2023

I'm trying to use Case::Title on some text that contains a newline (ex: The big\nblue house), but the newline isn't counted as a boundary, so I get The Big\nblue House. Is there a way to specify newlines as boundarys so I can get The Big\nBlue House? Thanks.

I tried doing something like:

let mut boundaries = Boundary::list_from("\n");
boundaries.push(Boundary::Space);

let converter = Converter::new()
    .to_case(Case::Title)
    .set_boundaries(&boundaries);

But I didn't have any luck with this.

JosephTLyons added a commit to zed-industries/zed that referenced this issue Sep 28, 2023
…cases (#3060)

If you highlight the following block of text (with a single selection):

```
The quick brown
fox jumps over
the lazy dog
```

and run `editor: convert to upper camel case`, you'll get:

```
TheQuickBrown
foxJumpsOver
theLazyDog
```

instead of:

```
TheQuickBrown
FoxJumpsOver
TheLazyDog
```

The same thing happens for `editor: convert to title case`. This happens
because [`to_case` crate](https://crates.io/crates/convert_case) doesn't
allow the user to define '\n' as a boundary. I wanted to fix this at the
lib level, so I filled [an
issue](rutrum/convert-case#16) but I never
heard back. What's strange is VS Code and Sublime I think both exhibit
the same output as we do currently, but I don't personally think this
feels right (happy to hear opposing opinions). I'm just doing the naive
thing to hack around this limitation of the `to_case` crate.

I did some testing and it seems I only need to adjust `editor: convert
to title case` and `editor: convert to upper camel case`. The way the
other transformations are implemented in `to_case` don't seem to have
this issue.

Release Notes:

- Fixed a bug where running certain text transfomration commands on a
single selection covering multiple lines would not transform all
selected lines as expected.
@rutrum
Copy link
Owner

rutrum commented Dec 29, 2023

This is not a feature at this time. You can only split a string based on a boundary condition, which is currently fixed to whatever is currently in Boundary, which doesn't include a generic "character" option. This should definitely be an option. I'd like to keep this issue open until it is fully investigated. For now, you would need to manually split the string before hand.

@JosephTLyons
Copy link
Author

Manually splitting is what I ended up doing. Appreciate the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants