This is a reimplemented 914067d14a6a27b59bba1c53cc18cb67eb9811fc (hinted by @cfeck), plus a refactoring of TerminalDisplay::findWordStart()
findWordStart() had bounds check issues and an off-by-one for the case when the acquired region was more than two screens down.
TerminalDisplay::findWordEnd() is very similarly implemented, but I haven't found a case where it fails, so I haven't touched it.
Since 914067d14a6a27b59bba1c53cc18cb67eb9811fc caused a revert, I've tested the changes thoroughly (the cases are in the Test Plan below).
BUG: 399109