AddWordToSelection adds the word the cursor is currently on to the selection
()
| 365 | // AddWordToSelection adds the word the cursor is currently on |
| 366 | // to the selection |
| 367 | func (c *Cursor) AddWordToSelection() { |
| 368 | if c.Loc.GreaterThan(c.OrigSelection[0]) && c.Loc.LessThan(c.OrigSelection[1]) { |
| 369 | c.CurSelection = c.OrigSelection |
| 370 | return |
| 371 | } |
| 372 | |
| 373 | if c.Loc.LessThan(c.OrigSelection[0]) { |
| 374 | backward := c.X |
| 375 | |
| 376 | for backward > 0 && util.IsWordChar(c.RuneUnder(backward-1)) { |
| 377 | backward-- |
| 378 | } |
| 379 | |
| 380 | c.SetSelectionStart(Loc{backward, c.Y}) |
| 381 | c.SetSelectionEnd(c.OrigSelection[1]) |
| 382 | } |
| 383 | |
| 384 | if c.Loc.GreaterThan(c.OrigSelection[1]) { |
| 385 | forward := c.X |
| 386 | |
| 387 | lineLen := util.CharacterCount(c.buf.LineBytes(c.Y)) - 1 |
| 388 | for forward < lineLen && util.IsWordChar(c.RuneUnder(forward+1)) { |
| 389 | forward++ |
| 390 | } |
| 391 | |
| 392 | c.SetSelectionEnd(Loc{forward, c.Y}.Move(1, c.buf)) |
| 393 | c.SetSelectionStart(c.OrigSelection[0]) |
| 394 | } |
| 395 | |
| 396 | c.Loc = c.CurSelection[1] |
| 397 | } |
| 398 | |
| 399 | // SelectTo selects from the current cursor location to the given |
| 400 | // location |
no test coverage detected