Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
(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:
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 functiondeleteLastWord
, 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:
Expected result after hitting
deleteLastWord
:Unexpected result after hitting
deleteLastWord
again: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.