[PR #7770] Fix and test TextBuffer::MoveToPreviousWord() #26986

Open
opened 2026-01-31 09:19:20 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/7770

State: closed
Merged: Yes


This fixes a bug when moving backwards by word that resulted in #7742.

This also includes...

  • a minor refactor that leverages GetWordStart in MoveToPreviousWord
  • additional unit tests for movement by word
  • a feature test comprised of the referenced bug report

MoveToPreviousWord() would...

  • move backwards for each whitespace character
  • then, move backwards for each regular character

This would actually result in moving to the beginning of the current "word" (as defined by a11y).

We actually need to do this process twice:

  • the first time gets you to the beginning of the current word
  • attempt to move back by one character
  • the second time gets you to the beginning of the previous word

Rather than implementing 4 while loops, we leverage GetWordStart() to
attempt to move to the beginning of the previous word. We call it twice
(as described above). The logic is unchanged, but we instead reuse a
function that has already undergone more testing.

To make sure this works as expected, additional unit tests were
introduced covering "MoveByWord" in the TextBuffer.

Validation Steps Performed

Added test for repro steps.
Added unit tests for movement by word.

Closes #7742

**Original Pull Request:** https://github.com/microsoft/terminal/pull/7770 **State:** closed **Merged:** Yes --- This fixes a bug when moving backwards by word that resulted in #7742. This also includes... - a minor refactor that leverages `GetWordStart` in `MoveToPreviousWord` - additional unit tests for movement by word - a feature test comprised of the referenced bug report `MoveToPreviousWord()` would... - move backwards for each whitespace character - then, move backwards for each regular character This would actually result in moving to the beginning of the current "word" (as defined by a11y). We actually need to do this process twice: - the first time gets you to the beginning of the current word - attempt to move back by one character - the second time gets you to the beginning of the previous word Rather than implementing 4 while loops, we leverage `GetWordStart()` to attempt to move to the beginning of the previous word. We call it twice (as described above). The logic is unchanged, but we instead reuse a function that has already undergone more testing. To make sure this works as expected, additional unit tests were introduced covering "MoveByWord" in the TextBuffer. ## Validation Steps Performed Added test for repro steps. Added unit tests for movement by word. Closes #7742
claunia added the pull-request label 2026-01-31 09:19:20 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#26986