SelectWord selects the word the cursor is currently on
()
| 332 | |
| 333 | // SelectWord selects the word the cursor is currently on |
| 334 | func (c *Cursor) SelectWord() { |
| 335 | if len(c.buf.LineBytes(c.Y)) == 0 { |
| 336 | return |
| 337 | } |
| 338 | |
| 339 | if !util.IsWordChar(c.RuneUnder(c.X)) { |
| 340 | c.SetSelectionStart(c.Loc) |
| 341 | c.SetSelectionEnd(c.Loc.Move(1, c.buf)) |
| 342 | c.OrigSelection = c.CurSelection |
| 343 | return |
| 344 | } |
| 345 | |
| 346 | forward, backward := c.X, c.X |
| 347 | |
| 348 | for backward > 0 && util.IsWordChar(c.RuneUnder(backward-1)) { |
| 349 | backward-- |
| 350 | } |
| 351 | |
| 352 | c.SetSelectionStart(Loc{backward, c.Y}) |
| 353 | c.OrigSelection[0] = c.CurSelection[0] |
| 354 | |
| 355 | lineLen := util.CharacterCount(c.buf.LineBytes(c.Y)) - 1 |
| 356 | for forward < lineLen && util.IsWordChar(c.RuneUnder(forward+1)) { |
| 357 | forward++ |
| 358 | } |
| 359 | |
| 360 | c.SetSelectionEnd(Loc{forward, c.Y}.Move(1, c.buf)) |
| 361 | c.OrigSelection[1] = c.CurSelection[1] |
| 362 | c.Loc = c.CurSelection[1] |
| 363 | } |
| 364 | |
| 365 | // AddWordToSelection adds the word the cursor is currently on |
| 366 | // to the selection |
no test coverage detected