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

[Request] Add some kind of heuristic for shortening names displayed on the Winger button #27

Open
supersaiyansubtlety opened this issue Aug 24, 2023 · 4 comments

Comments

@supersaiyansubtlety
Copy link

The Winger button can only actually display the first few characters of a name; I'd love a way to automatically shorten them.

Ideas:

  • user-defined regex: if there's a match, display the match; allow group references for output
  • predefined heuristic(s); example: if there are capital letters, strip all lowercase letters (leave non-letters)

Since the heuristic has to match the user's naming conventions, I think regex is especially useful for its flexibility.

Since regex is complicated, I think some predefined heuristics could also be useful.

(none of the heuristics would be applied if the whole name fits)

@l10nelw
Copy link
Owner

l10nelw commented Sep 11, 2024

Hi @supersaiyansubtlety, user-defined regex for button badge text is in v2.8.0!

It's just that at the moment, plus sample regex added in the help page. Also an emoji handling setting.

Nothing complicated like heuristics, particularly name-fit checking - that's harder to do than it sounds.

Let me know what you think.

@supersaiyansubtlety
Copy link
Author

Awesome, thanks!

This pattern is working pretty well for me:
^.{1,3}$|(?<=(?:^| |_))[^\s_](?=.*(?: |_|$))

A couple things though:

  1. afaict if there's no match there's no label. There should probably be an option to default to the non-regex truncation behavior in this case
  2. it would be more powerful if there was an (optional) substitution field, to use instead of concatenating all the matches

For example my pattern above only gets one character for single-word labels that are longer than 3 characters.

With this (gross hack):
pattern: ^(.{1,3})$|^([^\s_])(?:(?:.*?(?: |_))([^\s_]))(?:(?:.*?(?: |_))([^\s_]))?.*|^(.{1,3}).*
substitution: $1$2$3$4$5

I could make it so that labels with only one word would instead get truncated to their first 3 letters

@l10nelw
Copy link
Owner

l10nelw commented Sep 12, 2024

^.{1,3}$|(?<=(?:^| |_))[^\s_](?=.*(?: |_|$))

Wow what does this do? :)

afaict if there's no match there's no label. There should probably be an option to default to the non-regex truncation behavior in this case

You're right, good catch. But for now wouldn't a conditional |.* at the end do the trick?

substitution

Yeah we probably want that, will look into it.

I could make it so that labels with only one word would instead get truncated to their first 3 letters

Sorry if I didn't understand but my first thought here is that truncating anything to the first few letters doesn't seem necessary since the badge by design does that anyway.

@supersaiyansubtlety
Copy link
Author

supersaiyansubtlety commented Sep 12, 2024

Wow what does this do? :)

The first part makes it so if there are 3 or fewer characters, they're all kept.
The second part matches the first letter of each word (including _ as a separator).

You're right, good catch. But for now wouldn't a conditional |.* at the end do the trick?

yeah that works

Sorry if I didn't understand but my first thought here is that truncating anything to the first few letters doesn't seem necessary since the badge by design does that anyway.

The point of that regex is to make exceptions for multiple words which is done in the middle part.
The last part could just be replaced with .* though to take advantage of builtin truncation:
^(.{1,3})$|^([^\s_])(?:(?:.*?(?: |_))([^\s_]))(?:(?:.*?(?: |_))([^\s_]))?.*|^.*
actually since the middle part can't match labels with <= 3 characters anyways, the first part isn't needed:
^([^\s_])(?:(?:.*?(?:\s|_))([^\s_]))(?:(?:.*?[\s|_])([^\s_]))?.+|(.+)

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