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

Fix bug in deleteLastWord #305

Merged
merged 5 commits into from
Jul 6, 2023
Merged

Conversation

tbhno
Copy link
Contributor

@tbhno tbhno commented Jul 6, 2023

This fixes a bug I found when swiping left on the delete key to delete the last word: Sometimes, it deletes not only the last word, but also the space (in rare cases even more) before it.

This can be easily seen by starting out in an empty text field and typing a space and then a word, like:

word|

(vertical bar is cursor)

Here, hitting deleteLastWord deletes the last word plus the preceding space.

For a more extreme example, watch what happens when you type five spaces and then some words:

more words|

Here, hitting deleteLastWord deletes the last two words at once, leaving only the leading five spaces.

This unwanted behavior happens whenever the char-sequence lastWords in the function deleteLastWord, which contains the last 100 characters, begins with a space. Then the spaces up to the first non-whitespace character are added to the number of characters to be deleted.

I found out about this because after typing more than 100 characters into a text field, it happens quite often that the first of the last 100 characters is a space, so the space before the word is deleted along with it.

For example:

word word word word word word word word word word word word word word word word word word word word one two|

Expected result after hitting deleteLastWord:

word word word word word word word word word word word word word word word word word word word word one |

Unexpected result after hitting deleteLastWord again:

word word word word word word word word word word word word word word word word word word word word|

Apart from removing this inconsistency, I changed the function so that when there is no last word, meaning there are only spaces in a text field, deleteLastWord doesn't default to deleting just one character but instead deletes all of the spaces. This is not important and completely unrelated to the bug fix, just something I thought I would want the button to do.

@tbhno tbhno requested a review from dessalines as a code owner July 6, 2023 01:08
Copy link
Owner

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing CI lint for some reason.

@dessalines
Copy link
Owner

I'll test this shortly.

Copy link
Owner

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked great, thanks! I'll get this merged and released shortly.

@dessalines dessalines enabled auto-merge (squash) July 6, 2023 16:48
@dessalines dessalines merged commit ca68f86 into dessalines:main Jul 6, 2023
@tbhno tbhno deleted the deleteLastWord-bugfix branch July 6, 2023 17:04
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

Successfully merging this pull request may close these issues.

2 participants