-
Notifications
You must be signed in to change notification settings - Fork 10
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
Shave Only Delimits by a Space. #411
Comments
I added this functionality by turning your package into a helper file in my project. I went ahead and made a pull request on #412 that has my changes. I may have not copied all the changes since I had to do more for my project, but I'd be happy to revise or fix what I missed if I did. |
Can you provide a code sandbox of some sort to the issue you have? |
Yeah, I should be able to recreate an example of what I was dealing with in code sandbox. It might take a day or two unfortunately, but I'll post a link to it when I have it up for you to see. |
Sorry for the wait. I have the code sandbox environment mostly working. Code sandbox has some weird quirks I'm unfamiliar with with how it renders the DOM versus what I have experienced in my project's environment, but hopefully this is more clear versus my original description. I also updated my original description with a better explanation hopefully. I also realize in retrospect that the way I handled adding the delimiters into the array wouldn't be supported by IE since it uses positive lookbehinds and lookaheads, so if IE support is something that shave wants to maintain, then a different method would have to be done to capture delimiters for reconstructing the string afterwards. |
What Is the issue?
When shave interacts with a string of text, it delimits the text by spaces which means that if a different character such as a newline is the only character separating two words, it does not create two tokens. Instead it creates a single token with the newline character between the words.
This means that it may shave a word from the end of a line if the word after the newline character would be shaved but the word before the newline character would otherwise fit.
Provide issue context below using code examples, images, or links
const example = 'I am a cow.\nHear me moo!'
Currently shave would group
cow.\nHear
as a single token when it would make more sense to have it split the tokens ascow.
andHear
. This is especially a problem for a textarea where new lines are possible and the user may not realize that their input would be shaved in a way that is likely not expected.Edit: To be more clear, the issue is when
I am a cow.
would be the final line before shave removed the rest of the string. The string currently is tokenized like this['I', 'am', 'a', 'cow.\nHear', 'me' 'moo!']
. Since the final word on the line should becow.
it doesn't actually appear becauseHear
would be truncated thereforecow.\nHear
is all truncated causing the sentence to appear asI am a...
on the final line.The text was updated successfully, but these errors were encountered: