deleteWordLeft deletes the word left to the cursor. Returns whether or not the cursor blink should be reset.
()
| 406 | // deleteWordLeft deletes the word left to the cursor. Returns whether or not |
| 407 | // the cursor blink should be reset. |
| 408 | func (m *TextInputModel) deleteWordLeft() bool { |
| 409 | if m.pos == 0 || len(m.value) == 0 { |
| 410 | return false |
| 411 | } |
| 412 | |
| 413 | if m.EchoMode != EchoNormal { |
| 414 | return m.deleteBeforeCursor() |
| 415 | } |
| 416 | |
| 417 | i := m.pos |
| 418 | blink := m.setCursor(m.pos - 1) |
| 419 | for unicode.IsSpace(m.value[m.pos]) { |
| 420 | // ignore series of whitespace before cursor |
| 421 | blink = m.setCursor(m.pos - 1) |
| 422 | } |
| 423 | |
| 424 | for m.pos > 0 { |
| 425 | if !unicode.IsSpace(m.value[m.pos]) { |
| 426 | blink = m.setCursor(m.pos - 1) |
| 427 | } else { |
| 428 | if m.pos > 0 { |
| 429 | // keep the previous space |
| 430 | blink = m.setCursor(m.pos + 1) |
| 431 | } |
| 432 | break |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if i > len(m.value) { |
| 437 | m.value = m.value[:m.pos] |
| 438 | } else { |
| 439 | m.value = append(m.value[:m.pos], m.value[i:]...) |
| 440 | } |
| 441 | |
| 442 | return blink |
| 443 | } |
| 444 | |
| 445 | // deleteWordRight deletes the word right to the cursor. Returns whether or not |
| 446 | // the cursor blink should be reset. If input is masked delete everything after |
no test coverage detected